GHSA-w5fx-fh39-j5rw: Codex has sandbox bypass due to bug in path configuration logic
N/A
Basic Information
Technical Details
Package Name | Ecosystem | Vulnerable Versions | First Patched Version |
---|---|---|---|
@openai/codex | npm | >= 0.2.0, <= 0.38.0 | 0.39.0 |
Vulnerability Intelligence
Miggo AI
Root Cause Analysis
The vulnerability exists because the Codex CLI was using a single cwd
(current working directory) for two different purposes: setting the working directory for a command generated by an AI model, and defining the security boundaries of the sandbox in which that command runs. An attacker could craft a model response that specifies a cwd
outside of the intended project directory (e.g., /
or /tmp
).
The vulnerable functions, primarily spawn_command_under_seatbelt
for macOS and spawn_command_under_linux_sandbox
for Linux, would then use this malicious cwd
to configure the sandbox policy. Specifically, functions like create_seatbelt_command_args
would call sandbox_policy.get_writable_roots_with_cwd(cwd)
, effectively making the malicious path a writable root for the sandbox. This allowed the sandboxed process to write files and execute commands anywhere the user running the Codex CLI had permissions, bypassing the intended sandbox restrictions.
The patch addresses this by introducing a separation between the command's working directory (command_cwd
) and the directory used to enforce the sandbox policy (sandbox_policy_cwd
). The sandbox_policy_cwd
is now correctly and safely derived from the user's session directory, ensuring that the sandbox boundaries are always enforced correctly, regardless of the cwd
specified by the model.
Vulnerable functions
run_command_under_sandbox
codex-rs/cli/src/debug_sandbox.rs
process_exec_tool_call
codex-rs/core/src/exec.rs
spawn_command_under_linux_sandbox
codex-rs/core/src/landlock.rs
spawn_command_under_seatbelt
codex-rs/core/src/seatbelt.rs
create_seatbelt_command_args
codex-rs/core/src/seatbelt.rs