Repository navigation
fix(intercept): match text deny rules on Bash words as the shell decodes them - #955
Merged
Merged
Conversation
BaaRai
force-pushed
the
fix/rm-rule-backslash
branch
from
December 3, 2026 23:25
d48d6e5 to
49ad921
Compare
Regex and string intercept rules were matched on the raw tool input, but Bash removes quotes and backslashes and decodes $'...' before it runs a command: r\m -rf, r''m -rf, rm -r''f, rm -R -$'f' and a backslash-newline inside a word all ran rm -rf while the built-in recursive-force-delete rule did not match, and so did rm -rf on the line after another command, because the JSON escape of the newline glued an "n" to the command name. A deny or ask rule on a Bash call now also meets the command decoded with the argv word decoder, the simple commands joined by "; ". Allow rules are still matched on the text as written. The word decoder now decodes ANSI-C strings instead of treating them as opaque, which also lets argv deny and ask rules meet $'nmap' and bash -c $'nmap x'.
BaaRai
force-pushed
the
fix/rm-rule-backslash
branch
from
December 3, 2026 23:43
49ad921 to
d92a9e5
Compare
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
Regex and string intercept rules on a Bash call matched the raw
tool_input, but Bash removes quotes and backslashes and decodes$'...'before running a command.r\m -rf ./x,r''m -rf,"r"m -rf,/bin/r\m -rf,rm -r''f,rm -R -$'f'or a backslash-newline inside a word ranrm -rfwithout matching the built-in recursive-force-delete rule. A command on the line after another also escaped armrule: JSON writes the newline as\n, and itsnglued to the next word.Changes
;, each word with quotes, backslash escapes, line continuations and$'...'removed; a word that holds an expansion is kept as written.$'r\x6d'), so argv deny and ask rules meet$'nmap'andbash -c $'nmap x'.Tests
intercept/argv_compound_test.go,intercept/argv_test.go,guard/guard_test.go,server/intercept_argv_test.go: every spelling above matches the recursive-delete rule; allow-rule and non-Bash cases are unchanged, and the new cases fail on main.hardening/rulecheck_test.go: the JSON-escaped whitespace case (pip\tinstall) moves from a documented open bypass to a caught package install; the other documented open cases are unchanged.go test -race ./intercept ./guardpasses.Behaviour change
A deny or ask rule can now fire on a command that decodes to a denied word even when the text as typed did not contain it. That is the intent; allow rules do not change.