Repository navigation
fix(sandbox): check where a symlinked path resolves before allowing it - #1388
Merged
Merged
Conversation
The sandbox and protected-path checks only looked at the path as written, so a link inside the sandbox could read or write any file outside it: a link to ~/.ssh/id_ed25519 read back as a plain project file, and a linked directory let writes land anywhere. The check now also runs on the path's resolved target, and a denial names that target, so approving it grants the directory the file really lives in. Every sandbox and carve-out root is matched both as written and resolved, which keeps symlinked roots such as /tmp on macOS working.
A hard link to a file outside the sandbox needs no symlink, so the resolved-path check cannot see through it, and ln -f can replace a project file. The baseline now allows ln -s with plain operands, which still covers linking AGENTS.md to CLAUDE.md and skill directories; any other ln asks first.
edenreich
added a commit
that referenced
this pull request
Sep 28, 2026
## Summary The every-mode bash allow-list never looked at the paths a command names: - `head ~/.aws/credentials` read any file without approval. - `sort -o`, `tree -o` and `git diff --output=` could overwrite any file. - `make` and `task` ran whatever the repository's Makefile or Taskfile said. This follows #1388, which made the sandbox check follow symlinks. Allow-listed commands now go through that same check. ## Changes - An allow-listed command runs without approval only when every path it names passes `ValidatePathInSandbox` (`ValidatePathInSandboxWrite` for `mkdir` and `ln`). The check covers: - arguments, `--flag=value` and `-Xvalue` values, and input redirections (`< file`) - `~`, and `$VAR` expanded from the environment bash inherits - every glob match, following bash's hidden-file rule - A path that can't be known in advance asks, like any off-list command: `${VAR:-x}`, `$1`, `{a,b}`, a dot-leading glob, or `~user`. `echo` and `printf` are not checked, since they never open their arguments. - `sort -o`, `tree -o`, `git --output` (and its getopt abbreviations) and `uniq`'s output operand count as file writes, which the guard never auto-approves. - `make` and `task` leave the baseline. `INFER_TOOLS_BASH_ALLOW_APPEND`, or a mode's allow-list, adds them back where the repository is trusted. - `BashCommandRejectionHint` is now a nil-safe `Config` method, so a headless rejection names the offending path. The system prompt tells the model that allow-listed commands only skip approval inside the sandbox. - Docs (`tools-reference.md`, `configuration-reference.md`) and AGENTS.md describe the path rule. **Behaviour change:** headless runs without an approver that call `make …` or `task …`, or allow-listed commands on paths outside the sandbox, are now rejected with a hint. In chat, and with an approval broker, they ask. ## Testing - `TestIsBashCommandAllowed_SandboxPaths` has 48 cases: paths inside and outside, symlinks, globs, variables, braces, redirections, flag values, write options, and `make`/`task`. With the path check disabled, the 22 path cases fail. - The existing variable tests now expect `ls $HOME` to ask, since it expands outside the sandbox. `git log $REF` and `tail $LOGFILE` still run. - `go test ./...` and `task precommit:run` pass.
Contributor
|
🎉 This PR is included in version 0.217.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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
The sandbox and protected-path checks only looked at the path as written. A symlink inside the sandbox could therefore reach any file outside it, and neither check noticed:
~/.ssh/id_ed25519returned the key, with no approval, because Read is auto-approved.lnwas also auto-approved in every mode, so the agent could create such a link itself without asking.Changes
ValidatePathInSandboxnow checks the path as written and its resolved target. A denial names the target, so approving the sandbox prompt grants the directory the file really lives in.isWithinDir. Symlinked roots such as/tmpon macOS keep working, and the containment checks that each helper duplicated are gone.ValidatePathInSandboxWritechecks the resolved target against the read-only Go library directories.ln -s <operands>. A hard link has no symlink to resolve, and-fcan replace a project file, so every otherlnasks.ln -s AGENTS.md CLAUDE.mdand linking skill directories still run unattended.Testing
TestValidatePathInSandbox_Symlinkscovers a link to a file inside, a link to a file outside, a new file through a linked directory, a link to a protected file, and a symlinked sandbox root. It also checks that granting the reported directory lets the call through.TestIsBashCommandAllowed_MkdirLnnow covers hard links and forced links.infer headless --format ag-ui --require-approvalin auto mode, readinglink.txt→ an outside file. The CLI emits aSandboxAccessapproval. Approving it reads the file, denying it fails the read, and with no approval broker the read fails without asking.go test ./...andtask precommit:runpass.