Repository navigation
feat(tools): restrict bash file-write redirects unless whitelisted by pattern - #613
Merged
Merged
Conversation
… pattern A whitelisted command could write to an arbitrary file because the matcher prefix-matched the whole string including a trailing "> file" (e.g. echo secret > /etc/passwd, git log > /etc/passwd). Pipes and command substitution were already handled by the shell-aware matcher added in #581. A segment that still carries a non-benign file-write redirection (>, >>, &>file, >&file) now bypasses the plain command list and is allowed only by a whitelist pattern matching the entire command, so a prefix pattern like ^git log cannot unlock a redirected variant while an anchored ^...$ pattern can opt one in. Benign redirects (2>&1, >/dev/null) are still stripped and allowed; command substitution is still rejected. Denials now return actionable feedback naming the operator and pointing at tools.bash.whitelist.patterns. Pipe behavior from #581 is unchanged (each segment must be independently whitelisted), which already blocks the issue's "ls | xargs rm" example. Closes #560.
3 tasks
inference-gateway-releaser Bot
pushed a commit
that referenced
this pull request
Jun 6, 2026
## [0.120.0](v0.119.0...v0.120.0) (2026-06-06) ### 🚀 Features * add gh api graphql and gh project subcommands to default bash whitelist ([#612](#612)) ([b0f8bf3](b0f8bf3)), closes [#606](#606) * **tools:** restrict bash file-write redirects unless whitelisted by pattern ([#613](#613)) ([13b058a](13b058a)), closes [#581](#581) [#605](#605) [#581](#581) [#560](#560) ### ♻️ Code Refactoring * **ci:** remove NPM_TOKEN - use trusted publisher ([843457c](843457c)) ### 🧹 Maintenance * **deps:** bump infer CLI v0.117.1 -> v0.119.0, infer-action v0.11.2 -> v0.11.4 ([#611](#611)) ([30a536b](30a536b)) * regenerate config ([93e3de0](93e3de0))
Contributor
|
🎉 This PR is included in version 0.120.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Closed
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 #560.
A whitelisted Bash command could write to an arbitrary file, because the matcher prefix-matched the whole command string including a trailing
> file. Withecho(or any prefix-matched command) or a non-anchored pattern (^git log) whitelisted, these were silently auto-approved:echo secret > /etc/passwdgit log > /etc/passwdPipes (
|) and command substitution were already handled by the shell-aware matcher added in #581 / #605 — the issue's headlinels | xargs rmis already denied (xargs rmisn't whitelisted). The remaining, genuine gap was file-write redirects, which this PR closes.What changed
A segment that still carries a non-benign file-write redirection (
>,>>,&>file,>&file) now:\A(?:…)\z), so a prefix pattern like^git logcannot unlock a redirected variant, while an anchored^…$pattern can opt one in.Benign redirects (
2>&1,>/dev/null) are still stripped and allowed; command substitution is still rejected. Denied commands now return actionable feedback naming the operator and pointing attools.bash.whitelist.patterns.Per discussion, pipe behavior from #581 is intentionally unchanged (each segment must be independently whitelisted), and restricted-operator commands still flow through the normal approval prompt rather than being hard-denied.
Acceptance criteria (#560)
|,>,>>handled —>/>>restricted (new);|segment-split (existing, now covered by tests)docs/tools-reference.md,docs/configuration-reference.md)Tests
config/bash_whitelist_test.go: redirect restriction, pattern-unlocks-redirect (incl. prefix-pattern must-not-unlock), pipe policy (ls | xargs rmdenied,ls | headallowed),containsFileRedirect,matchesEntirePattern, rejection-hint.internal/agent/tools/bash_test.go: redirectValidatecase + error-message assertion.task test(full suite),task lint(golangci-lint 0 issues + markdownlint),task buildall pass.Docs / cross-repo
In-repo
docs/updated. A matching[DOCS]ticket forinference-gateway/docsmay be warranted if the docs site mirrors these pages - happy to draft it.