Skip to content

fix(sandbox): check where a symlinked path resolves before allowing it - #1388

Merged
edenreich merged 2 commits into
mainfrom
fix/sandbox-symlinks-and-approval
Sep 28, 2026
Merged

edenreich merged 2 commits into
mainfrom
fix/sandbox-symlinks-and-approval

Conversation

@edenreich

@edenreich edenreich commented Sep 28, 2026 •

Copy link
Copy Markdown
Contributor

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:

  • Reading a link to ~/.ssh/id_ed25519 returned the key, with no approval, because Read is auto-approved.
  • Writing through a linked directory landed wherever the link pointed. The approval prompt showed the harmless-looking link path.

ln was also auto-approved in every mode, so the agent could create such a link itself without asking.

Changes

  • ValidatePathInSandbox now 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.
  • Every sandbox and carve-out root is matched both as written and resolved, through the shared isWithinDir. Symlinked roots such as /tmp on macOS keep working, and the containment checks that each helper duplicated are gone.
  • ValidatePathInSandboxWrite checks the resolved target against the read-only Go library directories.
  • The every-mode bash baseline now auto-approves only ln -s <operands>. A hard link has no symlink to resolve, and -f can replace a project file, so every other ln asks. ln -s AGENTS.md CLAUDE.md and linking skill directories still run unattended.

Testing

  • New TestValidatePathInSandbox_Symlinks covers 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_MkdirLn now covers hard links and forced links.
  • End to end with the mock gateway: infer headless --format ag-ui --require-approval in auto mode, reading link.txt → an outside file. The CLI emits a SandboxAccess approval. Approving it reads the file, denying it fails the read, and with no approval broker the read fails without asking.
  • go test ./... and task precommit:run pass.

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
edenreich requested a review from a team as a code owner September 28, 2026 19:47
@edenreich
edenreich merged commit 510d7af into main Sep 28, 2026
1 check passed
@edenreich
edenreich deleted the fix/sandbox-symlinks-and-approval branch September 28, 2026 19:50
@edenreich edenreich changed the title fix(sandbox): check where a symlinked path resolves before allowing it fix(sandbox): enforce the sandbox through symlinks and auto-approved bash commands Sep 28, 2026
@edenreich edenreich changed the title fix(sandbox): enforce the sandbox through symlinks and auto-approved bash commands fix(sandbox): check where a symlinked path resolves before allowing it Sep 28, 2026
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.
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.217.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant