Fix Windows sandbox fs-helper proxy refresh

This commit is contained in:
David Wiesen
2026-06-29 21:23:11 -07:00
parent c660e2b644
commit 2387ffe523
4 changed files with 50 additions and 16 deletions
+15 -1
View File
@@ -29,7 +29,21 @@ use std::io;
use std::path::Path;
#[cfg(target_os = "windows")]
const WINDOWS_SANDBOX_WRAPPER_SETUP_ENV_ALLOWLIST: &[&str] = &["USERNAME", "USERPROFILE"];
const WINDOWS_SANDBOX_WRAPPER_SETUP_ENV_ALLOWLIST: &[&str] = &[
"USERNAME",
"USERPROFILE",
"HTTP_PROXY",
"HTTPS_PROXY",
"ALL_PROXY",
"WS_PROXY",
"WSS_PROXY",
"http_proxy",
"https_proxy",
"all_proxy",
"ws_proxy",
"wss_proxy",
"CODEX_NETWORK_ALLOW_LOCAL_BINDING",
];
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum SandboxType {
+15
View File
@@ -438,6 +438,9 @@ fn transform_for_direct_spawn_windows_preserves_only_wrapper_setup_identity() {
[
("USERNAME", "alice"),
("USERPROFILE", r"C:\Users\alice"),
("HTTP_PROXY", "http://127.0.0.1:7890"),
("all_proxy", "socks5://127.0.0.1:1080"),
("CODEX_NETWORK_ALLOW_LOCAL_BINDING", "1"),
("OPENAI_API_KEY", "secret"),
]
.map(|(key, value)| {
@@ -454,6 +457,18 @@ fn transform_for_direct_spawn_windows_preserves_only_wrapper_setup_identity() {
("Path".to_string(), r"C:\Windows\System32".to_string()),
("USERNAME".to_string(), "alice".to_string()),
("USERPROFILE".to_string(), r"C:\Users\alice".to_string()),
(
"HTTP_PROXY".to_string(),
"http://127.0.0.1:7890".to_string()
),
(
"all_proxy".to_string(),
"socks5://127.0.0.1:1080".to_string()
),
(
"CODEX_NETWORK_ALLOW_LOCAL_BINDING".to_string(),
"1".to_string(),
),
])
);
}
@@ -22,18 +22,21 @@ pub(crate) const RESOURCES_DIRNAME: &str = "codex-resources";
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub(crate) enum HelperExecutable {
CommandRunner,
Setup,
}
impl HelperExecutable {
fn file_name(self) -> &'static str {
match self {
Self::CommandRunner => "codex-command-runner.exe",
Self::Setup => "codex-windows-sandbox-setup.exe",
}
}
fn label(self) -> &'static str {
match self {
Self::CommandRunner => "command-runner",
Self::Setup => "setup-helper",
}
}
}
@@ -563,4 +566,11 @@ mod tests {
assert_eq!(file_name, "codex-command-runner-test-suffix.exe");
}
#[test]
fn setup_materialized_file_name_adds_suffix_before_extension() {
let file_name = materialized_file_name(HelperExecutable::Setup, "test-suffix");
assert_eq!(file_name, "codex-windows-sandbox-setup-test-suffix.exe");
}
}
+10 -15
View File
@@ -12,8 +12,9 @@ use std::process::Stdio;
use crate::allow::AllowDenyPaths;
use crate::allow::compute_allow_paths_for_permissions;
use crate::helper_materialization::bundled_executable_path_for_exe;
use crate::helper_materialization::HelperExecutable;
use crate::helper_materialization::helper_bin_dir;
use crate::helper_materialization::resolve_helper_for_launch;
use crate::identity::sandbox_setup_is_complete;
use crate::logging::current_log_file_path;
use crate::logging::log_note;
@@ -46,7 +47,6 @@ pub const ONLINE_USERNAME: &str = "CodexSandboxOnline";
const ERROR_CANCELLED: u32 = 1223;
const SECURITY_BUILTIN_DOMAIN_RID: u32 = 0x0000_0020;
const DOMAIN_ALIAS_RID_ADMINS: u32 = 0x0000_0220;
const SETUP_EXE_FILENAME: &str = "codex-windows-sandbox-setup.exe";
const USERPROFILE_ROOT_EXCLUSIONS: &[&str] = &[
".ssh",
".tsh",
@@ -212,7 +212,7 @@ fn run_setup_refresh_inner(
};
let json = serde_json::to_vec(&payload)?;
let b64 = BASE64_STANDARD.encode(json);
let exe = find_setup_exe();
let exe = find_setup_exe(request.codex_home);
let sbx_dir = sandbox_dir(request.codex_home);
let log_path = current_log_file_path(&sbx_dir);
let cleared_report = match clear_setup_error_report(request.codex_home) {
@@ -683,17 +683,12 @@ fn quote_arg(arg: &str) -> String {
out
}
fn find_setup_exe() -> PathBuf {
if let Ok(exe) = std::env::current_exe()
&& let Some(setup_exe) = find_setup_exe_for_current_exe(&exe)
{
return setup_exe;
}
PathBuf::from(SETUP_EXE_FILENAME)
}
fn find_setup_exe_for_current_exe(exe: &Path) -> Option<PathBuf> {
bundled_executable_path_for_exe(exe, SETUP_EXE_FILENAME)
fn find_setup_exe(codex_home: &Path) -> PathBuf {
resolve_helper_for_launch(
HelperExecutable::Setup,
codex_home,
Some(&sandbox_dir(codex_home)),
)
}
fn report_helper_failure(
@@ -737,7 +732,7 @@ fn run_setup_exe(
use windows_sys::Win32::UI::Shell::SEE_MASK_NOCLOSEPROCESS;
use windows_sys::Win32::UI::Shell::SHELLEXECUTEINFOW;
use windows_sys::Win32::UI::Shell::ShellExecuteExW;
let exe = find_setup_exe();
let exe = find_setup_exe(codex_home);
let payload_json = serde_json::to_string(payload).map_err(|err| {
failure(
SetupErrorCode::OrchestratorPayloadSerializeFailed,