Repository navigation
fix(plugins): bash-guard — block compound commands where any segment matches a deny rule (#36637) - #36645
Closed
Pro777 wants to merge 2 commits into
Closed
fix(plugins): bash-guard — block compound commands where any segment matches a deny rule (#36637)#36645Pro777 wants to merge 2 commits into
Pro777 wants to merge 2 commits into
Conversation
…ss (#36637) Chained bash commands like `git status && rm -rf /` bypass the permissions.deny allowlist because Claude Code's built-in checker evaluates the full string against prefix rules and matches only the first segment. bash-guard is a PreToolUse hook plugin that: - Splits the command on &&, ||, ;, | (honouring quoting) - Checks each segment independently against Bash(...) deny patterns from ~/.claude/settings.json and project-local settings - Blocks the entire command if any segment is denied - Also strips VAR=value env-prefix bypasses before matching All 34 unit tests pass. Fixes #36637.
This was referenced Mar 23, 2026
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
Fixes #36637 — chained bash commands silently bypass the tool permission allowlist.
The bug
Claude Code's built-in permission checker evaluates a
Bashtool call as a single string against thepermissions.allow/permissions.denyrules. For a compound command like:the checker finds that the string starts with
git status(matching an allow-rule prefix) and grants the whole command — without ever evaluatingrm -rf /important/diragainst the deny rules. The same bypass works with;,||, and|.This was confirmed by inspecting the minified CLI bundle (
cli.js). TheVL1matcher function explicitly skips compound commands when evaluating allow-rules (skipCompoundCheck: false), meaning the per-segment deny walk inva9is only reached via the sandbox/auto-allow code path and not during interactive permission prompts.The fix
This PR adds a new plugin,
plugins/bash-guard/, that registers aPreToolUsehook forBashtool calls. The hook:&&,||,;, and|— honouring single quotes, double quotes, and backtick quoting so operators inside strings are not treated as separators.Bash(...)deny patterns from~/.claude/settings.jsonand the project-local.claude/settings.json/.claude/settings.local.json.The hook also strips leading
VAR=valueenv-var assignments before matching to close theX=1 rm -rf /env-prefix bypass.Before / after
With
"Bash(rm -rf /*)"inpermissions.deny:rm -rf /tmpgit status && rm -rf /tmpecho x; rm -rf ~/Documentsfalse || rm -rf /home/usercat /etc/passwd | dd if=/dev/zero of=/dev/sdagit fetch && git statusTest plan
python3 -m pytest plugins/bash-guard/tests/ -v