Allow disabled proxy with any Windows sandbox

This commit is contained in:
David Wiesen
2026-07-07 13:07:30 -07:00
parent c32b50beb7
commit c20a892b53
8 changed files with 96 additions and 8 deletions
@@ -268,7 +268,10 @@ impl CommandExecRequestProcessor {
self.config.effective_workspace_roots(),
)
};
let started_network_proxy = match network_proxy_spec.as_ref() {
let started_network_proxy = match network_proxy_spec
.as_ref()
.filter(|spec| !cfg!(target_os = "windows") || spec.enabled())
{
Some(spec) => match spec
.start_proxy(
&network_proxy_permission_profile,
@@ -69,7 +69,11 @@ impl WindowsSandboxRequestProcessor {
};
codex_core::config::validate_windows_sandbox_network_proxy_compatibility(
target_windows_sandbox_level,
config.permissions.network.is_some(),
config
.permissions
.network
.as_ref()
.is_some_and(codex_core::config::NetworkProxySpec::enabled),
)
.map_err(|err| invalid_request(err.to_string()))?;
+41
View File
@@ -253,6 +253,47 @@ async fn network_proxy_without_elevated_only_sandbox_requirement_is_rejected() -
));
Ok(())
}
#[cfg(target_os = "windows")]
#[tokio::test]
async fn disabled_managed_network_allows_unelevated_windows_sandbox() -> std::io::Result<()> {
let codex_home = TempDir::new()?;
std::fs::write(
codex_home.path().join(CONFIG_TOML_FILE),
r#"
[windows]
sandbox = "unelevated"
"#,
)?;
let config = ConfigBuilder::without_managed_config_for_tests()
.codex_home(codex_home.path().to_path_buf())
.fallback_cwd(Some(codex_home.path().to_path_buf()))
.cloud_config_bundle(
CloudConfigBundleFixture::loader_with_enterprise_requirement(
r#"
[experimental_network]
enabled = false
"#,
),
)
.build()
.await?;
assert_eq!(
WindowsSandboxLevel::from_config(&config),
WindowsSandboxLevel::RestrictedToken
);
assert!(
!config
.permissions
.network
.as_ref()
.expect("managed network requirements should remain available")
.enabled()
);
Ok(())
}
use core_test_support::PathBufExt;
use core_test_support::PathExt;
use core_test_support::TempDirExt;
+6 -4
View File
@@ -3788,13 +3788,14 @@ impl Config {
network_requirements,
&network_permission_profile,
)?;
let network_proxy_enabled = network.as_ref().is_some_and(NetworkProxySpec::enabled);
validate_windows_network_proxy_requirements(
config_layer_stack.requirements_toml(),
network.is_some(),
network_proxy_enabled,
)?;
validate_windows_sandbox_network_proxy_compatibility(
windows_sandbox_level,
network.is_some(),
network_proxy_enabled,
)?;
let mut helper_readable_roots = get_readable_roots_required_for_codex_runtime(
&codex_home,
@@ -4195,13 +4196,14 @@ impl Config {
self.config_layer_stack.requirements().network.clone(),
permission_profile,
)?;
let network_proxy_enabled = network.as_ref().is_some_and(NetworkProxySpec::enabled);
validate_windows_network_proxy_requirements(
self.config_layer_stack.requirements_toml(),
network.is_some(),
network_proxy_enabled,
)?;
validate_windows_sandbox_network_proxy_compatibility(
WindowsSandboxLevel::from_config(self),
network.is_some(),
network_proxy_enabled,
)?;
Ok(network)
}
@@ -73,7 +73,7 @@ impl ConfigReloader for StaticNetworkProxyReloader {
}
impl NetworkProxySpec {
pub(crate) fn enabled(&self) -> bool {
pub fn enabled(&self) -> bool {
self.config.network.enabled
}
+4
View File
@@ -1127,6 +1127,10 @@ impl Session {
spec
}
};
if cfg!(target_os = "windows") && !spec.enabled() {
self.services.network_proxy.store(None);
return;
}
if let Some(started_proxy) = self.services.network_proxy.load_full() {
if let Err(err) = spec.apply_to_started_proxy(started_proxy.as_ref()).await {
warn!("failed to refresh managed network proxy for sandbox change: {err}");
+6 -1
View File
@@ -971,7 +971,12 @@ impl Session {
)
});
let (network_proxy, session_network_proxy) =
if let Some(spec) = config.permissions.network.as_ref() {
if let Some(spec) = config
.permissions
.network
.as_ref()
.filter(|spec| !cfg!(target_os = "windows") || spec.enabled())
{
let current_exec_policy = exec_policy.current();
let (network_proxy, session_network_proxy) = Self::start_managed_network_proxy(
spec,
+29
View File
@@ -913,6 +913,7 @@ async fn new_turn_refreshes_managed_network_proxy_for_sandbox_change() -> anyhow
let initial_permission_profile = PermissionProfile::workspace_write();
let mut network_config = NetworkProxyConfig::default();
network_config.network.enabled = true;
network_config
.network
.set_allowed_domains(vec!["evil.com".to_string()]);
@@ -1177,6 +1178,34 @@ async fn workspace_write_turns_continue_to_expose_managed_network_proxy() -> any
Ok(())
}
#[cfg(target_os = "windows")]
#[tokio::test]
async fn workspace_write_turns_do_not_expose_disabled_managed_network_proxy() -> anyhow::Result<()>
{
let permission_profile = PermissionProfile::workspace_write();
let network_spec = crate::config::NetworkProxySpec::from_config_and_constraints(
NetworkProxyConfig::default(),
Some(NetworkConstraints {
enabled: Some(false),
..Default::default()
}),
&permission_profile,
)?;
let session = make_session_with_config(move |config| {
config
.permissions
.set_permission_profile(permission_profile)
.expect("test setup should allow permission profile");
config.permissions.network = Some(network_spec);
})
.await?;
let turn_context = session.new_default_turn().await;
assert!(turn_context.network.is_none());
Ok(())
}
#[tokio::test]
async fn user_shell_commands_do_not_inherit_managed_network_proxy() -> anyhow::Result<()> {
let permission_profile = PermissionProfile::workspace_write();