Skip to content

feat(tools): restrict bash file-write redirects unless whitelisted by pattern - #613

Merged
edenreich merged 2 commits into
mainfrom
feat/bash-restrict-file-redirects-560
Jun 6, 2026
Merged

edenreich merged 2 commits into
mainfrom
feat/bash-restrict-file-redirects-560

Conversation

@edenreich

@edenreich edenreich commented Jun 6, 2026 •

Copy link
Copy Markdown
Contributor

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. With echo (or any prefix-matched command) or a non-anchored pattern (^git log) whitelisted, these were silently auto-approved:

  • echo secret > /etc/passwd
  • git log > /etc/passwd

Pipes (|) and command substitution were already handled by the shell-aware matcher added in #581 / #605 — the issue's headline ls | xargs rm is already denied (xargs rm isn'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:

  • bypasses the plain command list, and
  • is allowed only by a whitelist pattern that matches the entire command (\A(?:…)\z), 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. Denied commands now return actionable feedback naming the operator and pointing at tools.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)
  • whitelist patterns take precedence (anchored full-command match)
  • documented (docs/tools-reference.md, docs/configuration-reference.md)
  • tested

Tests

  • config/bash_whitelist_test.go: redirect restriction, pattern-unlocks-redirect (incl. prefix-pattern must-not-unlock), pipe policy (ls | xargs rm denied, ls | head allowed), containsFileRedirect, matchesEntirePattern, rejection-hint.
  • internal/agent/tools/bash_test.go: redirect Validate case + error-message assertion.
  • task test (full suite), task lint (golangci-lint 0 issues + markdownlint), task build all pass.

Docs / cross-repo

In-repo docs/ updated. A matching [DOCS] ticket for inference-gateway/docs may be warranted if the docs site mirrors these pages - happy to draft it.

… 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.
@edenreich
edenreich requested a review from a team as a code owner June 6, 2026 17:50
@edenreich
edenreich merged commit 13b058a into main Jun 6, 2026
@edenreich
edenreich deleted the feat/bash-restrict-file-redirects-560 branch June 6, 2026 17:57
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))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.120.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.

[FEATURE] Bash pipes or output redirections should be restricted by default

1 participant