Do not skip trust prompt on Windows if sandbox is enabled. (#6167)
If the experimental windows sandbox is enabled, the trust prompt should show on Windows.
This commit is contained in:
1
codex-rs/Cargo.lock
generated
1
codex-rs/Cargo.lock
generated
@@ -1469,6 +1469,7 @@ dependencies = [
|
|||||||
"regex-lite",
|
"regex-lite",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
|
"serial_test",
|
||||||
"shlex",
|
"shlex",
|
||||||
"strum 0.27.2",
|
"strum 0.27.2",
|
||||||
"strum_macros 0.27.2",
|
"strum_macros 0.27.2",
|
||||||
|
|||||||
@@ -85,6 +85,7 @@ pub mod util;
|
|||||||
pub use apply_patch::CODEX_APPLY_PATCH_ARG1;
|
pub use apply_patch::CODEX_APPLY_PATCH_ARG1;
|
||||||
pub use command_safety::is_safe_command;
|
pub use command_safety::is_safe_command;
|
||||||
pub use safety::get_platform_sandbox;
|
pub use safety::get_platform_sandbox;
|
||||||
|
pub use safety::set_windows_sandbox_enabled;
|
||||||
// Re-export the protocol types from the standalone `codex-protocol` crate so existing
|
// Re-export the protocol types from the standalone `codex-protocol` crate so existing
|
||||||
// `codex_core::protocol::...` references continue to work across the workspace.
|
// `codex_core::protocol::...` references continue to work across the workspace.
|
||||||
pub use codex_protocol::protocol;
|
pub use codex_protocol::protocol;
|
||||||
|
|||||||
@@ -106,3 +106,4 @@ insta = { workspace = true }
|
|||||||
pretty_assertions = { workspace = true }
|
pretty_assertions = { workspace = true }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
vt100 = { workspace = true }
|
vt100 = { workspace = true }
|
||||||
|
serial_test = { workspace = true }
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ use codex_core::auth::enforce_login_restrictions;
|
|||||||
use codex_core::config::Config;
|
use codex_core::config::Config;
|
||||||
use codex_core::config::ConfigOverrides;
|
use codex_core::config::ConfigOverrides;
|
||||||
use codex_core::find_conversation_path_by_id_str;
|
use codex_core::find_conversation_path_by_id_str;
|
||||||
|
use codex_core::get_platform_sandbox;
|
||||||
use codex_core::protocol::AskForApproval;
|
use codex_core::protocol::AskForApproval;
|
||||||
use codex_ollama::DEFAULT_OSS_MODEL;
|
use codex_ollama::DEFAULT_OSS_MODEL;
|
||||||
use codex_protocol::config_types::SandboxMode;
|
use codex_protocol::config_types::SandboxMode;
|
||||||
@@ -512,8 +513,8 @@ async fn load_config_or_exit(
|
|||||||
/// or if the current cwd project is already trusted. If not, we need to
|
/// or if the current cwd project is already trusted. If not, we need to
|
||||||
/// show the trust screen.
|
/// show the trust screen.
|
||||||
fn should_show_trust_screen(config: &Config) -> bool {
|
fn should_show_trust_screen(config: &Config) -> bool {
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") && get_platform_sandbox().is_none() {
|
||||||
// Native Windows cannot enforce sandboxed write access without WSL; skip the trust prompt entirely.
|
// If the experimental sandbox is not enabled, Native Windows cannot enforce sandboxed write access without WSL; skip the trust prompt entirely.
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if config.did_user_set_custom_approval_policy_or_sandbox_mode {
|
if config.did_user_set_custom_approval_policy_or_sandbox_mode {
|
||||||
@@ -557,10 +558,13 @@ mod tests {
|
|||||||
use codex_core::config::ConfigOverrides;
|
use codex_core::config::ConfigOverrides;
|
||||||
use codex_core::config::ConfigToml;
|
use codex_core::config::ConfigToml;
|
||||||
use codex_core::config::ProjectConfig;
|
use codex_core::config::ProjectConfig;
|
||||||
|
use codex_core::set_windows_sandbox_enabled;
|
||||||
|
use serial_test::serial;
|
||||||
use tempfile::TempDir;
|
use tempfile::TempDir;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn windows_skips_trust_prompt() -> std::io::Result<()> {
|
#[serial]
|
||||||
|
fn windows_skips_trust_prompt_without_sandbox() -> std::io::Result<()> {
|
||||||
let temp_dir = TempDir::new()?;
|
let temp_dir = TempDir::new()?;
|
||||||
let mut config = Config::load_from_base_config_with_overrides(
|
let mut config = Config::load_from_base_config_with_overrides(
|
||||||
ConfigToml::default(),
|
ConfigToml::default(),
|
||||||
@@ -569,6 +573,7 @@ mod tests {
|
|||||||
)?;
|
)?;
|
||||||
config.did_user_set_custom_approval_policy_or_sandbox_mode = false;
|
config.did_user_set_custom_approval_policy_or_sandbox_mode = false;
|
||||||
config.active_project = ProjectConfig { trust_level: None };
|
config.active_project = ProjectConfig { trust_level: None };
|
||||||
|
set_windows_sandbox_enabled(false);
|
||||||
|
|
||||||
let should_show = should_show_trust_screen(&config);
|
let should_show = should_show_trust_screen(&config);
|
||||||
if cfg!(target_os = "windows") {
|
if cfg!(target_os = "windows") {
|
||||||
@@ -584,4 +589,31 @@ mod tests {
|
|||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
#[test]
|
||||||
|
#[serial]
|
||||||
|
fn windows_shows_trust_prompt_with_sandbox() -> std::io::Result<()> {
|
||||||
|
let temp_dir = TempDir::new()?;
|
||||||
|
let mut config = Config::load_from_base_config_with_overrides(
|
||||||
|
ConfigToml::default(),
|
||||||
|
ConfigOverrides::default(),
|
||||||
|
temp_dir.path().to_path_buf(),
|
||||||
|
)?;
|
||||||
|
config.did_user_set_custom_approval_policy_or_sandbox_mode = false;
|
||||||
|
config.active_project = ProjectConfig { trust_level: None };
|
||||||
|
set_windows_sandbox_enabled(true);
|
||||||
|
|
||||||
|
let should_show = should_show_trust_screen(&config);
|
||||||
|
if cfg!(target_os = "windows") {
|
||||||
|
assert!(
|
||||||
|
should_show,
|
||||||
|
"Windows trust prompt should be shown on native Windows with sandbox enabled"
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
assert!(
|
||||||
|
should_show,
|
||||||
|
"Non-Windows should still show trust prompt when project is untrusted"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user