From f7e0996894a30f439c428934b08b888307f9ee3e Mon Sep 17 00:00:00 2001 From: wrestle-R Date: Wed, 25 Nov 2026 01:43:59 +0530 Subject: [PATCH 1/2] keep codex launches isolated and pin update assets Strip inherited provider and runtime overrides before setting private Codex homes. Validate the release artifact location before download and retain the update reservation until restart. --- cli/crates/cli/src/login.rs | 10 +--- cli/crates/core/src/extension_accounts.rs | 9 ++-- cli/crates/core/src/process.rs | 62 +++++++++++++++++++++++ cli/crates/core/src/profiles.rs | 23 +++------ cli/crates/core/src/usage.rs | 6 +-- extension/src/bridge.ts | 11 ++-- extension/src/extension.ts | 5 +- extension/src/startup.ts | 8 +-- extension/src/worker.ts | 5 +- extension/tests/bridge.test.mjs | 22 +++++++- extension/tests/fixtures/fake-engine.mjs | 3 ++ tauri/src-tauri/src/lib.rs | 5 +- tauri/src-tauri/src/updater.rs | 38 ++++++++++---- tauri/src-tauri/src/updater_policy.rs | 45 ++++++++++++++++ 14 files changed, 189 insertions(+), 63 deletions(-) create mode 100644 tauri/src-tauri/src/updater_policy.rs diff --git a/cli/crates/cli/src/login.rs b/cli/crates/cli/src/login.rs index c303237..f03f3cb 100644 --- a/cli/crates/cli/src/login.rs +++ b/cli/crates/cli/src/login.rs @@ -31,16 +31,8 @@ pub fn sign_in( fn run(pending: &PendingDeviceLogin, no_browser: bool, stop: &Arc) -> Result<()> { let engine = resolve_codex_command()?; let mut command = Command::new(engine); - for (key, _) in std::env::vars_os() { - let name = key.to_string_lossy(); - if name.starts_with("CODEX_") || name.starts_with("OPENAI_") || name == "NODE_OPTIONS" { - command.env_remove(key); - } - } - let mut child = command + let mut child = multi_codex_core::process::isolated_codex_home(&mut command, &pending.codex_home) .args(["login", "--device-auth"]) - .env("CODEX_HOME", &pending.codex_home) - .env("CODEX_SQLITE_HOME", &pending.codex_home) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()) diff --git a/cli/crates/core/src/extension_accounts.rs b/cli/crates/core/src/extension_accounts.rs index a2bb667..325eef3 100644 --- a/cli/crates/core/src/extension_accounts.rs +++ b/cli/crates/core/src/extension_accounts.rs @@ -12,11 +12,12 @@ impl AuthRecognizer for BundledRecognizer { tempfile::tempdir().map_err(|_| "Could not prepare credential validation")?; profiles::write_private_file(&directory.path().join("auth.json"), auth.as_bytes())?; profiles::write_codex_config(directory.path())?; - let output = crate::process::background(&mut std::process::Command::new(&self.0)) + let mut command = std::process::Command::new(&self.0); + let output = crate::process::background(crate::process::isolated_codex_home( + &mut command, + directory.path(), + )) .args(["login", "status"]) - .env("CODEX_HOME", directory.path()) - .env_remove("OPENAI_API_KEY") - .env_remove("CODEX_API_KEY") .output() .map_err(|_| "The Codex extension's bundled engine could not validate the account")?; if output.status.success() { diff --git a/cli/crates/core/src/process.rs b/cli/crates/core/src/process.rs index 66ad133..49d3e85 100644 --- a/cli/crates/core/src/process.rs +++ b/cli/crates/core/src/process.rs @@ -1,9 +1,35 @@ //! Bound external desktop helpers so a disconnected compositor cannot hang a launch. +use std::ffi::OsStr; use std::io::Read; +use std::path::Path; use std::process::{Command, Output, Stdio}; use std::thread; use std::time::{Duration, Instant}; +pub(crate) fn is_codex_override(key: &OsStr) -> bool { + let name = key.to_string_lossy().to_ascii_uppercase(); + name.starts_with("CODEX_") + || name.starts_with("OPENAI_") + || matches!(name.as_str(), "NODE_OPTIONS" | "ELECTRON_RUN_AS_NODE") +} + +/// Run Codex with the account's own credentials, provider and storage paths. +pub fn isolated_codex_home<'a>(command: &'a mut Command, home: &Path) -> &'a mut Command { + let overrides: Vec<_> = std::env::vars_os() + .map(|(key, _)| key) + .chain(command.get_envs().map(|(key, _)| key.to_owned())) + .filter(|key| is_codex_override(key)) + .collect(); + for key in overrides { + command.env_remove(key); + } + command + .env_remove("NODE_OPTIONS") + .env_remove("ELECTRON_RUN_AS_NODE") + .env("CODEX_HOME", home) + .env("CODEX_SQLITE_HOME", home) +} + pub fn background(command: &mut Command) -> &mut Command { #[cfg(windows)] { @@ -13,6 +39,42 @@ pub fn background(command: &mut Command) -> &mut Command { command } +#[cfg(test)] +mod isolation_tests { + use super::*; + + #[test] + fn private_codex_command_uses_only_its_account_environment() { + let home = Path::new("synthetic-account"); + let mut command = Command::new("codex-fixture"); + for key in [ + "OPENAI_API_KEY", + "OPENAI_BASE_URL", + "CODEX_API_KEY", + "codex_provider_fixture", + "NODE_OPTIONS", + "ELECTRON_RUN_AS_NODE", + ] { + command.env(key, "inert-fixture"); + } + command.env("CODEX_HOME", "other-account"); + command.env("CODEX_SQLITE_HOME", "other-database"); + command.env("LANG", "C"); + let configured: std::collections::BTreeMap<_, _> = isolated_codex_home(&mut command, home) + .get_envs() + .filter_map(|(key, value)| value.map(|value| (key, value))) + .collect(); + assert_eq!( + configured, + std::collections::BTreeMap::from([ + (OsStr::new("CODEX_HOME"), home.as_os_str()), + (OsStr::new("CODEX_SQLITE_HOME"), home.as_os_str()), + (OsStr::new("LANG"), OsStr::new("C")), + ]) + ); + } +} + #[cfg(all(test, windows))] mod windows_tests { use super::*; diff --git a/cli/crates/core/src/profiles.rs b/cli/crates/core/src/profiles.rs index 8e55713..3b45843 100644 --- a/cli/crates/core/src/profiles.rs +++ b/cli/crates/core/src/profiles.rs @@ -216,9 +216,8 @@ impl AuthRecognizer for CodexCliRecognizer { let codex = resolve_codex_command()?; let output = crate::process::output( - Command::new(codex) - .args(["login", "status"]) - .env("CODEX_HOME", temp.path()), + crate::process::isolated_codex_home(&mut Command::new(codex), temp.path()) + .args(["login", "status"]), Duration::from_secs(20), ) .map_err(|_| "Codex CLI could not validate the account within 20 seconds".to_string())?; @@ -2181,7 +2180,7 @@ fn cli_arguments(codex: &Path, home: &Path, workspace: &Path) -> Vec { ]); removed.extend(env::vars_os().filter_map(|(key, _)| { let name = key.to_string_lossy(); - (name.starts_with("CODEX_") || name.starts_with("OPENAI_") || name.starts_with("VSCODE_")) + (crate::process::is_codex_override(&key) || name.starts_with("VSCODE_")) .then(|| name.into_owned()) })); let mut args = vec!["/usr/bin/env".into()]; @@ -2563,19 +2562,16 @@ fn build_vscode_command_with( #[cfg(target_os = "macos")] let code = native_code.as_deref().unwrap_or(code); let mut command = Command::new(code); - command + crate::process::isolated_codex_home(&mut command, codex_home) .arg("--new-window") .arg("--user-data-dir") .arg(vscode_home) .arg("--extensions-dir") .arg(extensions_dir) .arg(workspace) - .env("CODEX_HOME", codex_home) - .env("CODEX_SQLITE_HOME", codex_home) .env_remove("VSCODE_IPC_HOOK_CLI") .env_remove("VSCODE_PID") - .env_remove("VSCODE_CWD") - .env_remove("ELECTRON_RUN_AS_NODE"); + .env_remove("VSCODE_CWD"); #[cfg(target_os = "macos")] command .env_remove("VSCODE_ESM_ENTRYPOINT") @@ -2594,16 +2590,11 @@ fn build_standalone_command( // data explicitly. Never forward this request to an unscoped global app. for (key, _) in env::vars_os() { let name = key.to_string_lossy(); - if name.starts_with("CODEX_") || name.starts_with("OPENAI_") || name.starts_with("VSCODE_") - { + if name.starts_with("VSCODE_") { command.env_remove(key); } } - command - .env_remove("NODE_OPTIONS") - .env_remove("ELECTRON_RUN_AS_NODE") - .env("CODEX_HOME", codex_home) - .env("CODEX_SQLITE_HOME", codex_home) + crate::process::isolated_codex_home(&mut command, codex_home) .env("CODEX_ELECTRON_USER_DATA_PATH", desktop_home) .arg(format!("--user-data-dir={}", desktop_home.display())) .current_dir(workspace) diff --git a/cli/crates/core/src/usage.rs b/cli/crates/core/src/usage.rs index 8c304e6..d9f9c8c 100644 --- a/cli/crates/core/src/usage.rs +++ b/cli/crates/core/src/usage.rs @@ -56,11 +56,9 @@ fn read_with_command( checked_at: DateTime, ) -> Result { let mut child = crate::process::spawn( - Command::new(codex) + // Keep token refreshes in the profile's durable home. + crate::process::isolated_codex_home(&mut Command::new(codex), codex_home) .args(["app-server", "--stdio"]) - // Use the profile's durable home so a token refreshed by Codex is not discarded with a - // temporary directory. Each Multi Codex profile already has its own isolated CODEX_HOME. - .env("CODEX_HOME", codex_home) .stdin(Stdio::piped()) .stdout(Stdio::piped()) .stderr(Stdio::piped()), diff --git a/extension/src/bridge.ts b/extension/src/bridge.ts index 3e99e84..74055f9 100644 --- a/extension/src/bridge.ts +++ b/extension/src/bridge.ts @@ -49,9 +49,8 @@ export class CodexBridge { constructor(readonly config: BridgeConfig, readonly frontend: JsonLines, args: string[], private existing?: ExistingBackend) { if (config.sharedChats && existing) throw new Error('Shared chats require a managed private backend; live attachment cannot enforce writer handoff.'); this.engineArgs = args; - const env: NodeJS.ProcessEnv = config.sharedChats ? privateBackendEnvironment(config.sessionHome) : { ...process.env, CODEX_HOME: config.sessionHome, - CODEX_SQLITE_HOME: config.sharedChats ? config.sessionHome : config.historyHome ?? config.sessionHome }; - delete env.OPENAI_API_KEY; delete env.CODEX_API_KEY; delete env.ELECTRON_RUN_AS_NODE; + const historyHome = config.sharedChats ? config.sessionHome : config.historyHome; + const env = privateBackendEnvironment(config.sessionHome, process.env, historyHome); this.backend = existing?.child ?? spawnExecutable(config.engine, args, { env, cwd: config.workspace, stdio: ['pipe', 'pipe', 'pipe'] }); // Codex diagnostics can contain workspace and account data. Never mirror them into VS Code logs. if (!existing) this.backend.stderr.resume(); @@ -350,9 +349,9 @@ export class CodexBridge { const nextHome = join(this.config.sessionHome, '..', randomUUID()); await prepareSessionHome(join(this.config.dataRoot, 'profiles', profileId, 'codex-home'), nextHome, { sharedChats: true }); this.config.sessionHome = nextHome; - const env = privateBackendEnvironment(nextHome); - delete env.OPENAI_API_KEY; delete env.CODEX_API_KEY; delete env.ELECTRON_RUN_AS_NODE; - this.backend = spawnExecutable(this.config.engine, this.engineArgs, { env, cwd: this.config.workspace }); + this.backend = spawnExecutable(this.config.engine, this.engineArgs, { + env: privateBackendEnvironment(nextHome), cwd: this.config.workspace, + }); this.backend.stderr.resume(); this.backendLines = new JsonLines(this.backend.stdout, this.backend.stdin); this.backendRpc = new RpcPeer(this.backendLines); diff --git a/extension/src/extension.ts b/extension/src/extension.ts index 8e4cffb..3da2b74 100644 --- a/extension/src/extension.ts +++ b/extension/src/extension.ts @@ -12,6 +12,7 @@ import { AccountClient, type Account } from './accounts'; import { BridgeClient } from './client'; import { JsonLines, RpcPeer } from './protocol'; import { withAccountBackend } from './worker'; +import { privateBackendEnvironment } from './startup'; import { CodexBridge } from './bridge'; import { findCodexBackend, tapBackend } from './stdio-tap'; import { bundledEnginePath } from './platform'; @@ -292,9 +293,7 @@ export async function activate(context: vscode.ExtensionContext) { } const directory = join(runtimeRoot, 'logins', randomUUID()); await mkdir(directory, { recursive: true, mode: 0o700 }); await writeFile(join(directory, 'config.toml'), 'cli_auth_credentials_store = "file"\n[analytics]\nenabled = false\n', { mode: 0o600 }); - const loginEnvironment: NodeJS.ProcessEnv = { ...process.env, CODEX_HOME: directory, CODEX_SQLITE_HOME: directory }; - delete loginEnvironment.OPENAI_API_KEY; delete loginEnvironment.CODEX_API_KEY; delete loginEnvironment.ELECTRON_RUN_AS_NODE; - const child = spawnExecutable(engine, ['app-server'], { env: loginEnvironment }); + const child = spawnExecutable(engine, ['app-server'], { env: privateBackendEnvironment(directory) }); child.stderr.resume(); const lines = new JsonLines(child.stdout, child.stdin); const rpc = new RpcPeer(lines, 'login:'); try { await rpc.request('initialize', { clientInfo: { name: 'multi_codex_login', version: extensionVersion } }); lines.send({ method: 'initialized' }); diff --git a/extension/src/startup.ts b/extension/src/startup.ts index 0dc6669..2ed71fe 100644 --- a/extension/src/startup.ts +++ b/extension/src/startup.ts @@ -1,10 +1,10 @@ import { chmod, copyFile, mkdir, readFile, symlink, writeFile } from 'node:fs/promises'; import { isAbsolute, join } from 'node:path'; -export function privateBackendEnvironment(home: string, inherited = process.env): NodeJS.ProcessEnv { - const env = Object.fromEntries(Object.entries(inherited).filter(([key]) => !/^(?:OPENAI_|CODEX_)/i.test(key))); - delete env.ELECTRON_RUN_AS_NODE; delete env.NODE_OPTIONS; - return { ...env, CODEX_HOME: home, CODEX_SQLITE_HOME: home }; +export function privateBackendEnvironment(home: string, inherited = process.env, historyHome = home): NodeJS.ProcessEnv { + const env = Object.fromEntries(Object.entries(inherited).filter(([key]) => + !/^(?:OPENAI_|CODEX_)|^(?:ELECTRON_RUN_AS_NODE|NODE_OPTIONS)$/i.test(key))); + return { ...env, CODEX_HOME: home, CODEX_SQLITE_HOME: historyHome }; } /** The launch home can be a desktop account; it is separate from shared account storage. */ diff --git a/extension/src/worker.ts b/extension/src/worker.ts index 406b918..91be9d9 100644 --- a/extension/src/worker.ts +++ b/extension/src/worker.ts @@ -1,11 +1,10 @@ import { extensionVersion } from './version'; import { spawnExecutable, terminateExecutable } from './native'; import { JsonLines, RpcPeer } from './protocol'; +import { privateBackendEnvironment } from './startup'; export async function withAccountBackend(engine: string, home: string, action: (rpc: RpcPeer) => Promise): Promise { - const env: NodeJS.ProcessEnv = { ...process.env, CODEX_HOME: home, CODEX_SQLITE_HOME: home }; - delete env.OPENAI_API_KEY; delete env.CODEX_API_KEY; delete env.ELECTRON_RUN_AS_NODE; - const child = spawnExecutable(engine, ['app-server'], { env }); + const child = spawnExecutable(engine, ['app-server'], { env: privateBackendEnvironment(home) }); child.stderr.resume(); const lines = new JsonLines(child.stdout, child.stdin); const rpc = new RpcPeer(lines, 'worker:'); child.on('error', () => rpc.close()); child.on('exit', () => rpc.close()); try { diff --git a/extension/tests/bridge.test.mjs b/extension/tests/bridge.test.mjs index 732829a..24c16e6 100644 --- a/extension/tests/bridge.test.mjs +++ b/extension/tests/bridge.test.mjs @@ -6,12 +6,12 @@ import { tmpdir } from 'node:os'; import { join, resolve } from 'node:path'; import { createRequire } from 'node:module'; const { controlEndpoint, spawnExecutable, CodexBridge, JsonLines, RpcPeer, BridgeClient } = createRequire(import.meta.url)('../dist/core.cjs'); -async function setup(t) { +async function setup(t, historyHome) { const root = await mkdtemp(join(tmpdir(), 'mc-bridge-test-')); const engine = resolve('tests/fixtures/fake-engine.mjs'); const helper = resolve('tests/fixtures/fake-accounts.mjs'); await chmod(engine, 0o755); await chmod(helper, 0o755); await mkdir(join(root, 'home')); const input = new PassThrough(); const output = new PassThrough(); - const bridge = new CodexBridge({ engine, helper, dataRoot: root, globalHome: root, sessionHome: join(root, 'home'), socket: controlEndpoint(root.replace(/[^a-zA-Z0-9]/g, '')), token: 'private-test-token', workspace: root }, new JsonLines(input, output), ['app-server']); + const bridge = new CodexBridge({ engine, helper, dataRoot: root, globalHome: root, sessionHome: join(root, 'home'), historyHome, socket: controlEndpoint(root.replace(/[^a-zA-Z0-9]/g, '')), token: 'private-test-token', workspace: root }, new JsonLines(input, output), ['app-server']); const peer = new RpcPeer(new JsonLines(output, input), 'frontend:'); await bridge.listen(); await peer.request('initialize'); input.write(JSON.stringify({ method: 'initialized' }) + '\n'); const client = await BridgeClient.connect(bridge.config.socket, bridge.config.token); @@ -19,6 +19,24 @@ async function setup(t) { return { bridge, client, peer }; } const delay = ms => new Promise(resolve => setTimeout(resolve, ms)); +test('isolated backend removes inherited provider overrides and keeps its configured history', async t => { + const keys = ['OPENAI_BASE_URL', 'CODEX_PROVIDER_FIXTURE', 'NODE_OPTIONS']; + const previous = keys.map(key => process.env[key]); + const marker = '--no-warnings'; + for (const key of keys) process.env[key] = marker; + const historyHome = resolve('tests/fixtures'); + const { bridge, peer } = await (async () => { + try { return await setup(t, historyHome); } + finally { + for (const [index, key] of keys.entries()) { + if (previous[index] === undefined) delete process.env[key]; + else process.env[key] = previous[index]; + } + } + })(); + assert.deepEqual(await peer.request('fixture/environment', { marker }), { inheritedOverride: false }); + assert.deepEqual(await peer.request('fixture/homes'), { home: bridge.config.sessionHome, history: historyHome }); +}); test('shared account handoff stops the old backend and keeps account files and histories private', async t => { const root = await mkdtemp(join(tmpdir(), 'mc-shared-handoff-')); const { syntheticAuth } = await import('./fixtures/local-service.mjs'); diff --git a/extension/tests/fixtures/fake-engine.mjs b/extension/tests/fixtures/fake-engine.mjs index b24fc55..ef91a0b 100755 --- a/extension/tests/fixtures/fake-engine.mjs +++ b/extension/tests/fixtures/fake-engine.mjs @@ -26,6 +26,9 @@ for await (const line of createInterface({ input: process.stdin })) { result = { held: !!held }; } else if (message.method === 'fixture/homes') { result = { home: process.env.CODEX_HOME, history: process.env.CODEX_SQLITE_HOME }; + } else if (message.method === 'fixture/environment') { + result = { inheritedOverride: ['OPENAI_BASE_URL', 'CODEX_PROVIDER_FIXTURE', 'NODE_OPTIONS'] + .some(key => process.env[key] === message.params?.marker) }; } else if (message.method === 'account/login/start') { if (p.type === 'apiKey' && authMethod === 'chatgpt') { send({ id: message.id, error: { code: -1, message: 'External auth is active' } }); continue; } if (mode === 'reject-all' || (mode === 'reject' && p.chatgptAccountId === 'synthetic-account-b')) { send({ id: message.id, error: { code: -1, message: 'Synthetic authentication failure' } }); continue; } diff --git a/tauri/src-tauri/src/lib.rs b/tauri/src-tauri/src/lib.rs index 168781c..657a9fb 100644 --- a/tauri/src-tauri/src/lib.rs +++ b/tauri/src-tauri/src/lib.rs @@ -166,6 +166,7 @@ use multi_codex_core::linux_desktops; mod desktop_integration; mod release_notes; mod updater; +mod updater_policy; pub use extension_accounts::{run_account_helper, run_bridge_launcher}; @@ -534,10 +535,8 @@ fn begin_device_login( } }; let mut child = process::spawn( - Command::new(codex) + process::isolated_codex_home(&mut Command::new(codex), &pending.codex_home) .args(["login", "--device-auth"]) - .env("CODEX_HOME", &pending.codex_home) - .env("CODEX_SQLITE_HOME", &pending.codex_home) .stdin(Stdio::null()) .stdout(Stdio::piped()) .stderr(Stdio::piped()), diff --git a/tauri/src-tauri/src/updater.rs b/tauri/src-tauri/src/updater.rs index 79c258c..8e2e929 100644 --- a/tauri/src-tauri/src/updater.rs +++ b/tauri/src-tauri/src/updater.rs @@ -86,10 +86,21 @@ fn updater_builder(app: &AppHandle) -> Result Result, String> { - updater.check().await.map_err(|error| { + let update = updater.check().await.map_err(|error| { eprintln!("Update availability check failed: {error}"); "Cannot reach the update service right now. Reconnect and try again.".to_string() - }) + })?; + if let Some(candidate) = &update { + if !crate::updater_policy::matches_release_asset( + std::env::consts::OS, + std::env::consts::ARCH, + &candidate.version, + candidate.download_url.as_str(), + ) { + return Err("The update service returned a package outside the expected release.".into()); + } + } + Ok(update) } #[tauri::command] @@ -110,6 +121,14 @@ pub async fn check_app_update(app: AppHandle) -> Result, String> static UPDATING: AtomicBool = AtomicBool::new(false); struct UpdateGuard; +impl UpdateGuard { + fn acquire() -> Result { + UPDATING + .compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire) + .map_err(|_| "An update is already in progress.")?; + Ok(Self) + } +} impl Drop for UpdateGuard { fn drop(&mut self) { UPDATING.store(false, Ordering::Release); @@ -145,10 +164,7 @@ fn emit( #[tauri::command] pub async fn update_app(app: AppHandle) -> Result { - UPDATING - .compare_exchange(false, true, Ordering::AcqRel, Ordering::Acquire) - .map_err(|_| "An update is already in progress.")?; - let _guard = UpdateGuard; + let guard = UpdateGuard::acquire()?; #[cfg(target_os = "linux")] if std::env::var_os("APPIMAGE").is_none() { return Err("In-app updates require the AppImage on Linux. Update .deb and .rpm installations through their package manager.".into()); @@ -193,6 +209,8 @@ pub async fn update_app(app: AppHandle) -> Result { emit(&app, "restarting", 0, None, Some(version)); // Allow the webview to paint the restart state. Profile apps remain running. tauri::async_runtime::spawn(async move { + // Keep the install reserved until the process restarts. + let _guard = guard; // A blocking timer here runs off the async executor's worker threads. let _ = tauri::async_runtime::spawn_blocking(|| std::thread::sleep(Duration::from_millis(700))) @@ -210,11 +228,13 @@ mod channel_tests { fn channel_cannot_change_during_installation_and_recovers_afterwards() { let root = tempfile::tempdir().unwrap(); write_channel(root.path(), UpdateChannel::Stable).unwrap(); - assert!(!UPDATING.swap(true, Ordering::AcqRel)); - let guard = UpdateGuard; + let guard = UpdateGuard::acquire().unwrap(); + // The restart task owns the reservation after installation succeeds. + let restart_task = move || drop(guard); + assert!(UpdateGuard::acquire().is_err()); assert!(save_channel_preference(root.path(), UpdateChannel::All).is_err()); assert_eq!(read_channel(root.path()).unwrap(), UpdateChannel::Stable); - drop(guard); + restart_task(); save_channel_preference(root.path(), UpdateChannel::All).unwrap(); assert_eq!(read_channel(root.path()).unwrap(), UpdateChannel::All); } diff --git a/tauri/src-tauri/src/updater_policy.rs b/tauri/src-tauri/src/updater_policy.rs new file mode 100644 index 0000000..b1f2091 --- /dev/null +++ b/tauri/src-tauri/src/updater_policy.rs @@ -0,0 +1,45 @@ +/// Keep the native downloader on the exact artifact emitted by updater-manifest.mjs. +/// The Tauri updater independently verifies the payload with the bundled public key. +pub(crate) fn matches_release_asset(os: &str, arch: &str, version: &str, url: &str) -> bool { + let suffix = match (os, arch) { + ("linux", "x86_64") => "amd64.AppImage", + ("macos", "aarch64") => "aarch64.app.tar.gz", + ("windows", "x86_64") => "x64-setup.exe", + _ => return false, + }; + url == format!( + "https://github.com/wrestle-R/multi-codex/releases/download/v{version}/Multi.Codex_{version}_{suffix}" + ) +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn only_the_expected_release_and_platform_artifact_is_accepted() { + let base = "https://github.com/wrestle-R/multi-codex/releases/download"; + for (os, arch, suffix) in [ + ("linux", "x86_64", "amd64.AppImage"), + ("macos", "aarch64", "aarch64.app.tar.gz"), + ("windows", "x86_64", "x64-setup.exe"), + ] { + let package = format!("{base}/v1.2.3/Multi.Codex_1.2.3_{suffix}"); + assert!(matches_release_asset(os, arch, "1.2.3", &package)); + assert!(!matches_release_asset(os, arch, "1.2.4", &package)); + assert!(!matches_release_asset(os, "other", "1.2.3", &package)); + assert!(!matches_release_asset( + os, + arch, + "1.2.3", + &format!("{package}?download=1") + )); + assert!(!matches_release_asset( + os, + arch, + "1.2.3", + &package.replace("github.com", "example.invalid"), + )); + } + } +} From c7ba6e5dcd5222e4409ca009fe08f4a0d6b0ab10 Mon Sep 17 00:00:00 2001 From: wrestle-R Date: Wed, 25 Nov 2026 01:48:46 +0530 Subject: [PATCH 2/2] fixed rust formatting for ci --- cli/crates/core/src/extension_accounts.rs | 6 +++--- tauri/src-tauri/src/updater.rs | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cli/crates/core/src/extension_accounts.rs b/cli/crates/core/src/extension_accounts.rs index 325eef3..e55ae17 100644 --- a/cli/crates/core/src/extension_accounts.rs +++ b/cli/crates/core/src/extension_accounts.rs @@ -17,9 +17,9 @@ impl AuthRecognizer for BundledRecognizer { &mut command, directory.path(), )) - .args(["login", "status"]) - .output() - .map_err(|_| "The Codex extension's bundled engine could not validate the account")?; + .args(["login", "status"]) + .output() + .map_err(|_| "The Codex extension's bundled engine could not validate the account")?; if output.status.success() { Ok(()) } else { diff --git a/tauri/src-tauri/src/updater.rs b/tauri/src-tauri/src/updater.rs index 8e2e929..29a85ee 100644 --- a/tauri/src-tauri/src/updater.rs +++ b/tauri/src-tauri/src/updater.rs @@ -97,7 +97,9 @@ async fn check( &candidate.version, candidate.download_url.as_str(), ) { - return Err("The update service returned a package outside the expected release.".into()); + return Err( + "The update service returned a package outside the expected release.".into(), + ); } } Ok(update)