Repository navigation
fix(bash): keep auto-approved commands inside the sandbox - #1389
Merged
Merged
Conversation
The every-mode allow-list never looked at the paths a command names, so
head, tail, wc and friends could read any file on disk without approval,
sort -o, tree -o and git --output could overwrite one, and make and task
ran whatever the repository's Makefile or Taskfile said.
- An allow-listed command now runs unattended only when every path it
names passes the file tools' sandbox check. Arguments, flag values,
input redirections, ~, $VAR (from the environment bash inherits) and
glob matches are checked. Anything the check cannot predict, such as
${VAR:-x}, {a,b} or a dot-leading glob, asks like any off-list command.
- sort -o, tree -o, git --output 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.
The rejection hint is now a Config method, so it can name the offending
path.
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 every-mode bash allow-list never looked at the paths a command names:
head ~/.aws/credentialsread any file without approval.sort -o,tree -oandgit diff --output=could overwrite any file.makeandtaskran 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
ValidatePathInSandbox(ValidatePathInSandboxWriteformkdirandln). The check covers:--flag=valueand-Xvaluevalues, and input redirections (< file)~, and$VARexpanded from the environment bash inherits${VAR:-x},$1,{a,b}, a dot-leading glob, or~user.echoandprintfare not checked, since they never open their arguments.sort -o,tree -o,git --output(and its getopt abbreviations) anduniq's output operand count as file writes, which the guard never auto-approves.makeandtaskleave the baseline.INFER_TOOLS_BASH_ALLOW_APPEND, or a mode's allow-list, adds them back where the repository is trusted.BashCommandRejectionHintis now a nil-safeConfigmethod, so a headless rejection names the offending path. The system prompt tells the model that allow-listed commands only skip approval inside the sandbox.tools-reference.md,configuration-reference.md) and AGENTS.md describe the path rule.Behaviour change: headless runs without an approver that call
make …ortask …, 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_SandboxPathshas 48 cases: paths inside and outside, symlinks, globs, variables, braces, redirections, flag values, write options, andmake/task. With the path check disabled, the 22 path cases fail.ls $HOMEto ask, since it expands outside the sandbox.git log $REFandtail $LOGFILEstill run.go test ./...andtask precommit:runpass.