Skip to content

Commit fdd56da

Browse files
authored
fix(cli): authenticate the mobile options server (#16099)
* fix(cli): authenticate the mobile options server The dev/build commands expose the CLI options (including forwarded env vars) to the Xcode and Android Studio build scripts over a local WebSocket server. Require a per-session random token, reject requests with an Origin header, stop sending secret-looking env vars, store the address file owner-only in the generated project instead of the shared temp dir, remove it on exit, and return clear errors from the IDE scripts. * cleanup
1 parent 9bad06b commit fdd56da

11 files changed

Lines changed: 367 additions & 72 deletions

File tree

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
---
2+
"tauri-cli": patch:sec
3+
"@tauri-apps/cli": patch:sec
4+
---
5+
6+
Secure the local server that `tauri android|ios dev|build` uses to pass options to the Android Studio and Xcode build scripts: requests now need a random per-session token, WebSocket connections from web pages (with an `Origin` header) are rejected, and variables whose name contains `TOKEN`, `PASSWORD`, `SECRET` or `CREDENTIAL` are no longer sent. The connection details are now written with owner-only permissions to `gen/<android|apple>/.tauri/cli-options-server.json` (instead of the shared temp directory) and removed when the command exits. The IDE build scripts now report a clear error when the Tauri CLI command is not running.

‎Cargo.lock‎

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎crates/tauri-cli/Cargo.toml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ jsonrpsee = { version = "0.26", features = ["server"] }
4343
jsonrpsee-core = "0.26"
4444
jsonrpsee-client-transport = { version = "0.26", features = ["ws"] }
4545
jsonrpsee-ws-client = { version = "0.26", default-features = false }
46+
tower = { version = "0.5", default-features = false }
4647
sublime_fuzzy = "0.7"
4748
clap_complete = "4"
4849
clap = { version = "4", features = ["derive", "env"] }

‎crates/tauri-cli/src/helpers/config.rs‎

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@ pub struct ConfigMetadata {
2626
/// The current target.
2727
target: Target,
2828

29-
original_identifier: Option<String>,
3029
/// The actual configuration, merged with any extension.
3130
inner: Config,
3231
/// The config extensions (platform-specific config files or the config CLI argument).
@@ -44,12 +43,6 @@ impl std::ops::Deref for ConfigMetadata {
4443
}
4544

4645
impl ConfigMetadata {
47-
/// The original bundle identifier from the config file.
48-
/// This does not take any extensions into account.
49-
pub fn original_identifier(&self) -> Option<&str> {
50-
self.original_identifier.as_deref()
51-
}
52-
5346
/// Checks which config is overwriting the bundle identifier.
5447
pub fn find_bundle_identifier_overwriter(&self) -> Option<OsString> {
5548
for (ext, config) in &self.extensions {
@@ -159,11 +152,6 @@ fn load_config(
159152
let config_file_name = config_path.file_name().unwrap();
160153
let mut extensions = HashMap::new();
161154

162-
let original_identifier = config
163-
.as_object()
164-
.and_then(|config| config.get("identifier")?.as_str())
165-
.map(ToString::to_string);
166-
167155
if let Some((platform_config, config_path)) =
168156
tauri_utils::config::parse::read_platform(target, tauri_dir)
169157
.context("failed to parse platform config")?
@@ -229,7 +217,6 @@ fn load_config(
229217

230218
Ok(ConfigMetadata {
231219
target,
232-
original_identifier,
233220
inner: config,
234221
extensions,
235222
})

‎crates/tauri-cli/src/mobile/android/android_studio_script.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub fn command(options: Options) -> Result<()> {
4747
};
4848

4949
let mut tauri_config = get_tauri_config(tauri_utils::platform::Target::Android, &[], dirs.tauri)?;
50-
let cli_options = read_options(&tauri_config);
50+
let cli_options = read_options(MobileTarget::Android, dirs.tauri)?;
5151

5252
if !cli_options.config.is_empty() {
5353
// reload config with merges from the android dev|build script

‎crates/tauri-cli/src/mobile/android/build.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ fn run_build(
277277
config: build_options.config,
278278
target_device: options.target_device.clone(),
279279
};
280-
let handle = write_options(tauri_config, cli_options)?;
280+
let handle = write_options(MobileTarget::Android, tauri_dir, cli_options)?;
281281

282282
inject_resources(config, tauri_config)?;
283283

‎crates/tauri-cli/src/mobile/android/dev.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ fn run_dev(
335335
}),
336336
};
337337

338-
let _handle = write_options(tauri_config, cli_options)?;
338+
let _handle = write_options(MobileTarget::Android, dirs.tauri, cli_options)?;
339339

340340
inject_resources(config, tauri_config)?;
341341

‎crates/tauri-cli/src/mobile/ios/build.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ fn run_build(
404404
config: build_options.config.clone(),
405405
target_device: options.target_device.clone(),
406406
};
407-
let handle = write_options(&tauri_config, cli_options)?;
407+
let handle = write_options(MobileTarget::Ios, dirs.tauri, cli_options)?;
408408

409409
if options.open {
410410
return Ok(handle);

‎crates/tauri-cli/src/mobile/ios/dev.rs‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ fn run_dev(
341341
no_watch: options.no_watch,
342342
additional_watch_folders: options.additional_watch_folders,
343343
},
344-
|options, tauri_config| {
344+
|options, _tauri_config| {
345345
let cli_options = CliOptions {
346346
dev: true,
347347
features: options.features.clone(),
@@ -351,7 +351,7 @@ fn run_dev(
351351
config: dev_options.config.clone(),
352352
target_device: None,
353353
};
354-
let _handle = write_options(tauri_config, cli_options)?;
354+
let _handle = write_options(MobileTarget::Ios, dirs.tauri, cli_options)?;
355355

356356
let open_xcode = || {
357357
if !set_host {

‎crates/tauri-cli/src/mobile/ios/xcode_script.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub fn command(options: Options) -> Result<()> {
9595
let macos = macos_from_platform(&options.platform);
9696

9797
let mut tauri_config = get_tauri_config(tauri_utils::platform::Target::Ios, &[], dirs.tauri)?;
98-
let cli_options = read_options(&tauri_config);
98+
let cli_options = read_options(MobileTarget::Ios, dirs.tauri)?;
9999
if !cli_options.config.is_empty() {
100100
// reload config with merges from the ios dev|build script
101101
reload_tauri_config(

0 commit comments

Comments
 (0)