Skip to content

Commit eed0172

Browse files
committed
feat(core): add shell > sidecar allowlist and process feature flag [TRI-037] (#18)
1 parent 6fbd6db commit eed0172

8 files changed

Lines changed: 55 additions & 18 deletions

File tree

.changes/command-feature-flag.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tauri": patch
3+
---
4+
5+
The `api::process::Command` APIs are now hidden behind the `command` feature flag.

.changes/sidecar-allowlist.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-utils": patch
3+
"tauri": patch
4+
---
5+
6+
The `shell` allowlist now includes a `sidecar` flag, which enables the use of the `shell` API to execute sidecars.

core/tauri-utils/src/config.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -840,6 +840,11 @@ pub struct ShellAllowlistConfig {
840840
/// Enable binary execution.
841841
#[serde(default)]
842842
pub execute: bool,
843+
/// Enable sidecar execution, allowing the JavaScript layer to spawn a sidecar program,
844+
/// an executable that is shipped with the application.
845+
/// For more information see https://tauri.studio/en/docs/usage/guides/bundler/sidecar.
846+
#[serde(default)]
847+
pub sidecar: bool,
843848
/// Open URL with the user's default application.
844849
#[serde(default)]
845850
pub open: bool,
@@ -850,6 +855,7 @@ impl Allowlist for ShellAllowlistConfig {
850855
let allowlist = Self {
851856
all: false,
852857
execute: true,
858+
sidecar: true,
853859
open: true,
854860
};
855861
let mut features = allowlist.to_features();
@@ -863,6 +869,7 @@ impl Allowlist for ShellAllowlistConfig {
863869
} else {
864870
let mut features = Vec::new();
865871
check_feature!(self, features, execute, "shell-execute");
872+
check_feature!(self, features, sidecar, "shell-sidecar");
866873
check_feature!(self, features, open, "shell-open");
867874
features
868875
}

core/tauri/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,8 +164,10 @@ process-relaunch = []
164164
protocol-all = ["protocol-asset"]
165165
protocol-asset = []
166166
reqwest-client = ["reqwest", "bytes"]
167-
shell-all = ["shell-execute", "shell-open"]
168-
shell-execute = ["shared_child", "os_pipe"]
167+
command = ["shared_child", "os_pipe"]
168+
shell-all = ["shell-execute", "shell-sidecar", "shell-open"]
169+
shell-execute = ["command"]
170+
shell-sidecar = ["command"]
169171
shell-open = ["open"]
170172
system-tray = ["tauri-runtime/system-tray", "tauri-runtime-wry/system-tray"]
171173
updater = ["minisign-verify", "base64", "dialog-ask"]

core/tauri/build.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,9 @@ fn main() {
5151

5252
// shell
5353
shell_all: { any(api_all, feature = "shell-all") },
54-
shell_open: { any(shell_all, feature = "shell-open") },
5554
shell_execute: { any(shell_all, feature = "shell-execute") },
55+
shell_sidecar: { any(shell_all, feature = "shell-sidecar") },
56+
shell_open: { any(shell_all, feature = "shell-open") },
5657

5758
// dialog
5859
dialog_all: { any(api_all, feature = "dialog-all") },

core/tauri/src/api/process.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,11 @@ use std::{
1212
process::{exit, Command as StdCommand},
1313
};
1414

15-
#[cfg(shell_execute)]
15+
#[cfg(feature = "command")]
16+
#[cfg_attr(doc_cfg, doc(cfg(feature = "command")))]
1617
mod command;
17-
#[cfg(shell_execute)]
18+
#[cfg(feature = "command")]
19+
#[cfg_attr(doc_cfg, doc(cfg(feature = "command")))]
1820
pub use command::*;
1921

2022
/// Gets the current binary.

core/tauri/src/endpoints/shell.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -81,13 +81,23 @@ impl Cmd {
8181
on_event_fn,
8282
options,
8383
} => {
84-
#[cfg(shell_execute)]
84+
let mut command = if options.sidecar {
85+
#[cfg(not(shell_sidecar))]
86+
return Err(crate::Error::ApiNotAllowlisted(
87+
"shell > sidecar".to_string(),
88+
));
89+
#[cfg(shell_sidecar)]
90+
crate::api::process::Command::new_sidecar(program)?
91+
} else {
92+
#[cfg(not(shell_execute))]
93+
return Err(crate::Error::ApiNotAllowlisted(
94+
"shell > execute".to_string(),
95+
));
96+
#[cfg(shell_execute)]
97+
crate::api::process::Command::new(program)
98+
};
99+
#[cfg(any(shell_execute, shell_sidecar))]
85100
{
86-
let mut command = if options.sidecar {
87-
crate::api::process::Command::new_sidecar(program)?
88-
} else {
89-
crate::api::process::Command::new(program)
90-
};
91101
command = command.args(args);
92102
if let Some(cwd) = options.cwd {
93103
command = command.current_dir(cwd);
@@ -116,10 +126,6 @@ impl Cmd {
116126

117127
Ok(pid.into())
118128
}
119-
#[cfg(not(shell_execute))]
120-
Err(crate::Error::ApiNotAllowlisted(
121-
"shell > execute".to_string(),
122-
))
123129
}
124130
Self::KillChild { pid } => {
125131
#[cfg(shell_execute)]

tooling/cli.rs/schema.json

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,8 @@
103103
"shell": {
104104
"all": false,
105105
"execute": false,
106-
"open": false
106+
"open": false,
107+
"sidecar": false
107108
},
108109
"window": {
109110
"all": false,
@@ -338,7 +339,8 @@
338339
"default": {
339340
"all": false,
340341
"execute": false,
341-
"open": false
342+
"open": false,
343+
"sidecar": false
342344
},
343345
"allOf": [
344346
{
@@ -1265,6 +1267,11 @@
12651267
"description": "Open URL with the user's default application.",
12661268
"default": false,
12671269
"type": "boolean"
1270+
},
1271+
"sidecar": {
1272+
"description": "Enable sidecar execution, allowing the JavaScript layer to spawn a sidecar program, an executable that is shipped with the application. For more information see https://tauri.studio/en/docs/usage/guides/bundler/sidecar.",
1273+
"default": false,
1274+
"type": "boolean"
12681275
}
12691276
},
12701277
"additionalProperties": false
@@ -1356,7 +1363,8 @@
13561363
"shell": {
13571364
"all": false,
13581365
"execute": false,
1359-
"open": false
1366+
"open": false,
1367+
"sidecar": false
13601368
},
13611369
"window": {
13621370
"all": false,

0 commit comments

Comments
 (0)