Repository navigation
Intercept: argv prefix rules (match_type=argv) - #210
Merged
Merged
Conversation
This was referenced Nov 13, 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.
What
A new interception rule type,
match_type = argv, for the Bash tool. Itspatternis a JSON array of tokens, for example["git","push"], andmatch_targetistool_input. The rule matches when the parsed Bash command has exactly that prefix (the program and its subcommands).This is PR 1 of 2. The always-allow button in the pending approval detail will be a separate PR once this one is merged.
Why
stringandregexrules match raw command text, so an allow rule written as a regex wildcard is easy to get wrong and hard to audit.nmap.*also allowsnmap x; rm -rf /. An argv prefix rule says exactly which program and subcommand it allows, and it can never match a compound command.Which shell runs the command (blocking question)
The Bash tool runs the command with
bash -c(not a login shell, not without a shell):github.com/Autumn-27/norma v0.4.3replaced bygithub.com/BaaRai/Norma v0.4.8. In v0.4.8,shellCmd()(tool/task.go:684-689) returns"bash", []string{"-c"}on every OS except Windows (powershell -NoProfile -NonInteractive -Command).tool/bash.go:159-160(runBashSync) andtool/task.go:331(the managed and background path).server/assembly.go:314,328only changes the tool's description.The parser therefore uses the Bash grammar:
syntax.Variant(syntax.LangBash), inintercept/argv.goParseSimpleCommand.Design
intercept/argv.go,ParseSimpleCommand, usingmvdan.cc/sh/v3/syntax):*syntax.CallExpr.&, including coproc and disown);FOO=bar nmap);command,builtin,env,exec,eval, matched by base name, so/usr/bin/envis caught too.&&,||,;, subshells, blocks, negation and compound commands.$'..'or$"..". Quotes are removed ('git' "push"isgit push).BashArity.prefix. The longest entry wins, and the fallback istokens[0]. Entries:cat,cd,ls,rm,grep, and similar single-word programs;git,npm,docker,kubectl,terraform;npm run,docker compose,kubectl rollout,git config,gcloud,gh,aws.git -C /repo pushgives["git","-C"]) or a non-literal token is refused: no match, and no prefix is invented.["nmap"]does not matchnmapx, and does not match/usr/bin/nmap.match_targetmust betool_input.-.; & | > < ```` $ ( )`) or any whitespace.rule_id,decision_source=rule) are unchanged.db/schema.sqlupdates the inline CHECK constraint for new databases. For existing databases it runsALTER TABLE intercept_rules DROP CONSTRAINT IF EXISTS intercept_rules_match_type_checkand then adds the constraint again withargv, in the same style asmcp_servers_transport_check.match_targettotool_input. The rule list shows an argv rule asgit push *, and the form warns that flags are not constrained.New dependency
mvdan.cc/sh/v3v3.14.1 (BSD-3-Clause, pure Go), added withgo getandgo mod tidy.Limitations
["git","push"]also coversgit push --force, andgit push --receive-pack=..../usr/bin/nmapneeds its own rule.Choices
execandevalwere added to the wrapper rejection alongsidecommand,builtinandenv.$'..'/$".."in the prefix also mean no match.Tests run locally (Kali, go1.26.10, throwaway Postgres 16 on 127.0.0.1)
gofmt -lon the changed Go files: clean.go build ./...: exit 0.go vet ./...: exit 0.go test -count=1 -p 1 ./...: exit 0.go test -race -count=1 -p 1on intercept, guard, db and server (fresh databases): intercept, guard and db pass. server: exit 1, from the known intermittent race only:agent.AugmentTools(a planner goroutine left over fromTestWorkerControlRoutes) againstwireAgentAugment(TestReviveClearsBudgetEndReason). It is not related to this change; server tests pass without -race.git push,npm run,docker compose, thetokens[0]fallback, flags after the program;nmapx;Not verified