Enforce managed deny-read rules in the Windows sandbox (#38660)

## Why

Windows sandbox requests must preserve managed filesystem deny rules across every execution path and setup refresh. Unsupported policies should fail closed instead of allowing a command to run without the requested protection.

## What changed

- Resolve Windows filesystem overrides while constructing each sandbox execution request so both `shell_command` and `exec_command` enforce exact-path and glob deny-read entries.
- Carry resolved deny-read paths into Windows sandbox setup refreshes, including workspace-relative entries.
- Reject unelevated restricted-token requests that cannot enforce deny-read rules.
- Reject recursive globs rooted at a filesystem root unless `glob_scan_max_depth` bounds their expansion.

## Testing

Added coverage for deny-read enforcement through both command runtimes, setup refresh resolution, restricted-token failure, and bounded root-level glob scans.

GitOrigin-RevId: 33dfa4d1a45b14850cbf58f9173717e3e707d9bf
This commit is contained in:
johnl-oai authored and copyberry committed 2026-08-14 22:28:33 +00:00
1 parent 5186e2ccc3
commit 848cbad7f4
8 files changed
+486 -47

No files matched your search

+39 -4
View File
@@ -19,14 +19,19 @@ use codex_network_proxy::ManagedNetworkSandboxContext;
use codex_network_proxy::NetworkProxy;
use codex_network_proxy::RemoteNetworkProxyLaunchConfig;
use codex_protocol::config_types::WindowsSandboxLevel;
use codex_protocol::error::CodexErr;
use codex_protocol::exec_output::ExecToolCallOutput;
use codex_protocol::models::PermissionProfile;
pub use codex_protocol::models::SandboxPermissions;
use codex_sandboxing::SandboxExecRequest;
use codex_sandboxing::SandboxType;
use codex_sandboxing::WindowsSandboxFilesystemOverrides;
use codex_sandboxing::resolve_windows_elevated_filesystem_overrides;
use codex_sandboxing::resolve_windows_restricted_token_filesystem_overrides;
use codex_sandboxing::windows_sandbox_uses_elevated_backend;
use codex_utils_absolute_path::AbsolutePathBuf;
use codex_utils_path_uri::PathUri;
use codex_utils_string::truncate_middle_with_token_budget;
use std::collections::HashMap;
#[derive(Debug)]
@@ -112,7 +117,7 @@ impl ExecRequest {
request: SandboxExecRequest,
options: ExecOptions,
windows_sandbox_workspace_roots: Vec<AbsolutePathBuf>,
) -> Self {
) -> Result<Self, CodexErr> {
let SandboxExecRequest {
command,
cwd,
@@ -131,6 +136,36 @@ impl ExecRequest {
expiration,
capture_policy,
} = options;
let windows_sandbox_filesystem_overrides = if sandbox == SandboxType::WindowsRestrictedToken
{
let sandbox_policy_cwd = windows_sandbox_policy_cwd
.to_abs_path()
.map_err(|err| CodexErr::InvalidRequest(format!("invalid sandbox cwd: {err}")))?;
let use_windows_elevated_backend =
windows_sandbox_uses_elevated_backend(windows_sandbox_level);
if use_windows_elevated_backend {
resolve_windows_elevated_filesystem_overrides(
sandbox,
&permission_profile,
&sandbox_policy_cwd,
use_windows_elevated_backend,
)
} else {
resolve_windows_restricted_token_filesystem_overrides(
sandbox,
&permission_profile,
&sandbox_policy_cwd,
windows_sandbox_level,
)
}
.map_err(|error| {
CodexErr::UnsupportedOperation(
truncate_middle_with_token_budget(&error, /*max_tokens*/ 900).0,
)
})?
} else {
None
};
let network_sandbox_policy = permission_profile.network_sandbox_policy();
if !network_sandbox_policy.is_enabled() {
env.insert(
@@ -142,7 +177,7 @@ impl ExecRequest {
if sandbox == SandboxType::MacosSeatbelt {
env.insert(CODEX_SANDBOX_ENV_VAR.to_string(), "seatbelt".to_string());
}
Self {
Ok(Self {
command,
cwd,
env,
@@ -157,13 +192,13 @@ impl ExecRequest {
windows_sandbox_level,
windows_sandbox_private_desktop,
permission_profile,
windows_sandbox_filesystem_overrides: None,
windows_sandbox_filesystem_overrides,
arg0,
exec_server_sandbox: None,
exec_server_enforce_managed_network: false,
exec_server_managed_network: None,
exec_server_network_proxy: None,
}
})
}
}