Repository navigation
fix(tools): confine shell reads to workspace + session temp (#447) - #456
Merged
Merged
Conversation
exec_command and the bash tool ran inside the OS sandbox for writes, but the sandbox's read side was left open: the Seatbelt profile allowed file-read* everywhere and bubblewrap exposed the host filesystem read-only. A shell command could cat ~/.ssh and ~/.aws that read_file/write_file refused, which is the #447 escape. Close the read side with the same boundary the file tools enforce. On macOS the profile now allows reads only for the workspace, the session temp dir, and the OS-owned paths a process needs to start; on Linux the home trees (/home, /root) are masked with a tmpfs alongside /run and /tmp. Denials keep the existing SandboxDenied escalation path. Adds read-denial regression tests for both shell spawn paths (exec_command and run_shell_command) plus a workspace+session-temp positive control; updates the permission contract, README, and SECURITY.md.
mohitranka
force-pushed
the
fix/447-exec-command-sandbox-confinement
branch
from
August 27, 2026 21:53
706f085 to
fee31bc
Compare
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…confinement fix(tools): confine shell reads to workspace + session temp (#447)
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…confinement fix(tools): confine shell reads to workspace + session temp (#447)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #447 —
exec_command(and thebashtool'srun_shell_commandpath) bypassed the workspace sandbox boundary on the read side.read_file/write_fileconfine paths to the workspace + session temp viaToolContext::resolve_path, with no approval path. Shell commands were already confined for writes by the OS sandbox (sandbox-execon macOS,bwrapon Linux) applied at spawn, but the sandbox's read side was left open: the Seatbelt profile contained a blanket(allow file-read*), and bubblewrap exposed the host filesystem read-only (--ro-bind / /). A shell command could thereforecat ~/.ssh/...and~/.aws/...thatread_filerefused — the exact escape in #447.What changed
(allow file-read*). Reads are now allowed only for:/System,/usr,/bin,/sbin,/Library/Apple,/Library/Keychains(system roots only — user keychains under$HOMEstay denied),/Library/Preferences,/private/etc+/etc,/opt/homebrew(root-owned ARM toolchain), timezone/DarwinDirectory user-lookup data, standard/devnodes, and/(getcwd);file-map-executableon the loader paths andfile-read-metadatatraversal for/var.$HOME, per-user temp under/private/var/folders, volumes,/Network) is denied by the profile default. Denied reads surface asOperation not permitted→ existingToolError::SandboxDenied.--ro-bind / /stays, but/homeand/rootare now masked with a private tmpfs alongside/runand/tmp, so~/.ssh/~/.awsdo not exist inside the sandbox (reported as ENOENT →SandboxDenied). Masks are emitted before the workspace bind, so workspaces living under/homeor/rootare re-exposed like workspaces under/tmp.SandboxDeniedsemantics and governance escalation (user approves → unconfined replay); no new failure mode introduced.~/.docker-under-$HOMEsocket gap is now closed, residual socket gap limited to unmasked trees (e.g./var,/opt) — still tracked in Harden sandbox with Landlock RESOLVE_UNIX once kernels ship ABI 9 #392.Tests
sandbox_enforcement.rs:reads_outside_the_workspace_are_refused(wrapper level, secret file outside the workspace must be unreadable),system_paths_needed_to_start_a_process_stay_readable(positive control),exec_command_cannot_read_outside_the_workspace(tool level, escalatesSandboxDenied, secret must not leak into tool output),exec_command_reads_workspace_and_session_temp(positive control),bash_tool_cannot_read_outside_the_workspace(second spawn path). Existing write-denial tests unchanged.permission_contract.rs: the "read outside the workspace" contract row flippedAllowed → Denied; network row wording updated.sandbox.rsunit tests: blanket(allow file-read*)absence + workspace/system-path read allowlist asserted; bwrap test now asserts/homeand/rootmasks precede the workspace bind.forge-core/forge-tuimirroring the old denial text updated.Validation (run on macOS; kernel-level tests are sandbox-gated and skip where a second sandbox cannot be entered — they run on CI's Linux+bubblewrap job)
cargo fmt --all -- --check— cleancargo clippy --workspace --all-targets --locked -- -D warnings— cleancargo test --workspace --all-targets --locked --no-fail-fast— all green (incl. forge-tools 327 lib + 37 enforcement + 15 contract, forge-core 1040, forge-tui)cargo build --release --locked --package forge-cli+./target/release/forge --version— okPlatform limitations of the confinement
/usr,/opt/homebrew) is a curated list; a system path forge does not know about fails closed and escalates to the user. User keychains and$HOMEare denied./homeand/rootare hidden, but other user-writable trees not masked (e.g./mnt,/var/backups) remain readable read-only inside the sandbox, and a read-only mount does not stopconnect()to a socket under an unmasked tree (residual gap Harden sandbox with Landlock RESOLVE_UNIX once kernels ship ABI 9 #392).unconfined_shellreplays after explicit user approval remain permitted by design.