mirror of
https://github.com/pchuan98/codex.git
synced 2026-07-01 00:31:56 +08:00
## Why `codex sandbox` can start a network proxy from a configured permission profile. Previously, sandbox-level containment was tied to managed network requirements rather than whether a proxy was actually active. This meant config-driven proxy policies were not consistently enforced as the sandbox's only network path. ## What changed - Enable proxy-only network containment whenever `codex sandbox` starts a network proxy. - Apply the same active-proxy check to the macOS and Linux sandbox paths. - Add a Linux regression test that verifies a sandboxed command cannot establish a direct connection while the configured proxy is active. ## Test plan - `just test -p codex-cli debug_sandbox::tests` - `sandbox_with_network_proxy_blocks_direct_loopback_access` runs on Linux to cover the config-driven proxy path end to end.
96 lines
2.5 KiB
Rust
96 lines
2.5 KiB
Rust
use super::*;
|
|
use pretty_assertions::assert_eq;
|
|
|
|
#[test]
|
|
fn legacy_landlock_flag_is_included_when_requested() {
|
|
let command = vec!["/bin/true".to_string()];
|
|
let command_cwd = Path::new("/tmp/link");
|
|
let cwd = Path::new("/tmp");
|
|
|
|
let default_bwrap = create_linux_sandbox_command_args(
|
|
command.clone(),
|
|
command_cwd,
|
|
cwd,
|
|
/*use_legacy_landlock*/ false,
|
|
/*allow_network_for_proxy*/ false,
|
|
);
|
|
assert_eq!(
|
|
default_bwrap.contains(&"--use-legacy-landlock".to_string()),
|
|
false
|
|
);
|
|
|
|
let legacy_landlock = create_linux_sandbox_command_args(
|
|
command,
|
|
command_cwd,
|
|
cwd,
|
|
/*use_legacy_landlock*/ true,
|
|
/*allow_network_for_proxy*/ false,
|
|
);
|
|
assert_eq!(
|
|
legacy_landlock.contains(&"--use-legacy-landlock".to_string()),
|
|
true
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn proxy_flag_takes_precedence_over_legacy_landlock() {
|
|
let command = vec!["/bin/true".to_string()];
|
|
let command_cwd = Path::new("/tmp/link");
|
|
let cwd = Path::new("/tmp");
|
|
let permission_profile = PermissionProfile::read_only();
|
|
|
|
let args = create_linux_sandbox_command_args_for_permission_profile(
|
|
command,
|
|
command_cwd,
|
|
&permission_profile,
|
|
cwd,
|
|
/*use_legacy_landlock*/ true,
|
|
/*allow_network_for_proxy*/ true,
|
|
);
|
|
assert_eq!(
|
|
args.contains(&"--allow-network-for-proxy".to_string()),
|
|
true
|
|
);
|
|
assert_eq!(args.contains(&"--use-legacy-landlock".to_string()), false);
|
|
}
|
|
|
|
#[test]
|
|
fn permission_profile_flag_is_included() {
|
|
let command = vec!["/bin/true".to_string()];
|
|
let command_cwd = Path::new("/tmp/link");
|
|
let cwd = Path::new("/tmp");
|
|
let permission_profile = PermissionProfile::read_only();
|
|
|
|
let args = create_linux_sandbox_command_args_for_permission_profile(
|
|
command,
|
|
command_cwd,
|
|
&permission_profile,
|
|
cwd,
|
|
/*use_legacy_landlock*/ true,
|
|
/*allow_network_for_proxy*/ false,
|
|
);
|
|
|
|
assert_eq!(
|
|
args.windows(2)
|
|
.any(|window| { window[0] == "--permission-profile" && !window[1].is_empty() }),
|
|
true
|
|
);
|
|
assert_eq!(
|
|
args.windows(2)
|
|
.any(|window| window[0] == "--command-cwd" && window[1] == "/tmp/link"),
|
|
true
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn proxy_network_requires_managed_requirements() {
|
|
assert_eq!(
|
|
allow_network_for_proxy(/*enforce_managed_network*/ false),
|
|
false
|
|
);
|
|
assert_eq!(
|
|
allow_network_for_proxy(/*enforce_managed_network*/ true),
|
|
true
|
|
);
|
|
}
|