Fix Windows fs-helper sandbox bypass#27950
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 32fab729cf
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| tokio = { workspace = true, features = ["rt-multi-thread"] } | ||
|
|
||
| [target.'cfg(windows)'.dependencies] | ||
| codex-windows-sandbox = { workspace = true } |
There was a problem hiding this comment.
Refresh Bazel lock for the dependency change
This Cargo.toml change adds a Windows-only dependency but MODULE.bazel.lock is unchanged, so Bazel crate resolution can drift and just bazel-lock-check/Bazel builds can fail for the Windows dependency set; refresh and include the Bazel lock with the dependency edit. guidance
Useful? React with 👍 / 👎.
32fab72 to
3e7a309
Compare
3e7a309 to
c11e2f3
Compare
Why
The exec-server filesystem helper path is a direct-spawn path: it asks
SandboxManagerfor aSandboxExecRequest, then launches the returned argv itself. That is safe on macOS/Linux because the transformed argv is a self-contained sandbox wrapper (sandbox-exec/codex-linux-sandbox). On Windows, the transform result carriedWindowsRestrictedTokensandbox metadata, but the filesystem helper runner still spawned the helper argv directly.As a result, Windows filesystem built-ins that route through the fs-helper could run with the parent Codex process permissions instead of the configured Windows sandbox. In practice, that means a helper-backed operation could write where the active permission profile says it should not.
What Changed
--run-as-windows-sandbox, so direct-spawn callers can receive a self-contained Windows sandbox argv.SandboxManager::transform_for_direct_spawn, which preserves the existing transform behavior for normal command execution but wraps Windows restricted-token requests for direct-spawn callers..sandbox-binbefore it is launched by the sandboxed user.codex sandbox windowsand the hidden wrapper share the same forwarding code.FileSystemSandboxContextso symbolic:workspace_rootspolicies are resolved correctly for the wrapped helper.USERNAME/USERPROFILEvalues while preserving the serialized inner command env.Verification
just test -p codex-sandboxing transform_for_direct_spawn_windowsjust test -p codex-windows-sandbox windows_wrapper_args_round_tripjust test -p codex-exec-server fs_sandbox::testsjust test -p codex-core apply_patch--run-as-windows-sandbox -- ... --codex-run-as-apply-patchpatched an allowed file and failed to write a denied file.codex exec-server --listen stdio:fs/writeFilewrote inside the allowed root, failed withAccess is denied. (os error 5)outside it, and used the materialized helper at.sandbox-bin/codex.exe.