Skip to content

fix(intercept): match text deny rules on Bash words as the shell decodes them - #955

Merged
BaaRai merged 1 commit into
mainfrom
fix/rm-rule-backslash
Dec 4, 2026
Merged

BaaRai merged 1 commit into
mainfrom
fix/rm-rule-backslash

Conversation

@BaaRai

@BaaRai BaaRai commented Dec 3, 2026 •

Copy link
Copy Markdown
Owner

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 ran rm -rf without matching the built-in recursive-force-delete rule. A command on the line after another also escaped a rm rule: JSON writes the newline as \n, and its n glued to the next word.

Changes

  • A deny or ask text rule on a Bash call now also meets the command decoded the way the shell runs it: the simple commands joined by ; , each word with quotes, backslash escapes, line continuations and $'...' removed; a word that holds an expansion is kept as written.
  • Allow rules still match only the text as written, so decoding never widens what is allowed; other tools are unchanged.
  • The shell-word decoder now also decodes ANSI-C strings ($'r\x6d'), so argv deny and ask rules meet $'nmap' and bash -c $'nmap x'.
  • This covers every built-in regex rule and the operator's deny and ask rules.

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 ./guard passes.

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.

@BaaRai
BaaRai force-pushed the fix/rm-rule-backslash branch from d48d6e5 to 49ad921 Compare December 3, 2026 23:25
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
BaaRai force-pushed the fix/rm-rule-backslash branch from 49ad921 to d92a9e5 Compare December 3, 2026 23:43
@BaaRai
BaaRai merged commit 3286e20 into main Dec 4, 2026
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant