Repository navigation
Intercept: always allow a pending Bash prefix (argv rule, code-owned denylist) - #211
Merged
Merged
Conversation
…owned denylist)
POST /api/intercept/pending/{id}/always-allow derives an argv allow rule from the stored pending row (never from the body), at priority -1000, reusing an identical enabled rule, and leaves the request pending. A code-owned denylist of interpreters, launchers, package managers, orchestration and destructive programs refuses such rules at creation, in the manual rule form, and neutralises argv allow rules at matching; argv deny and ask rules still match.
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
An "always allow" button on a pending Bash approval. It creates an argv allow rule (
match_type=argv, PR #210) for the prefix of the pending command, for examplegit push *. A code-owned denylist refuses programs for which such a rule would allow arbitrary code.Why
Approving the same harmless command family over and over (for example
gh pr list) is noise. The argv parser from #210 gives a prefix that is safe to derive. What was missing was a one-click path from a pending request to a rule, plus a guard against prefixes that are equivalent to "allow anything".Endpoint
POST /api/intercept/pending/{id}/always-allow. It sits next to.../decide, on the same mux, behind the same auth middleware.intercept_pendingrow by id, requiresstatus='pending'(otherwise 409, or 404 if the row is missing), readstool_nameandtool_input, and recomputes the prefix withintercept.ArgvPrefix.match_type=argv,match_target=tool_input,action=allow,enabled=true,priority=-1000(constantalwaysAllowPriority), namealways-allow: <prefix>. Timeouts take the rule form defaults (enabled, 60 s, deny). It then callsinterceptor.Invalidate().created:falseand does not create a second one.GET /api/intercept/history/{id}now also returnsalways_allow_prefixfor a pending request that qualifies. The UI uses it as the button label, so the client never parses the command.Denylist
The list is in
intercept/alwaysallow_denylist.go. It is code-owned: no env var, no setting. Names are compared after normalisation: basename, lower case, trailing version stripped (python3.11,php8.2,ruby3.2,perl5,pip3becomepython,php,ruby,perl,pip), and everymkfs.*becomesmkfs. So/usr/bin/envand/usr/bin/python3.11are caught.Why these programs: an argv rule does not constrain flags. For these programs, an allow rule on the prefix means arbitrary code execution (
python -c,find -exec,tar --checkpoint-action=exec,rsync -e,vim -c,ssh host cmd), arbitrary third-party code (package scripts, container images), or unbounded damage. The brief's starting list is extended with obvious variants and with exec-via-flag programs (tar, rsync, scp, editors, pagers, gdb/strace, flock, ...).The denylist is checked in three places:
validateInterceptRuleReq, create and update). An argv allow rule for a denylisted program is refused with the same message. Argv deny and ask rules for these programs stay creatable.ruleMatches). An argv allow rule whose program is denylisted never matches, so a rule that predates this PR or was written straight into the database is neutralised. Only allow rules are affected: an argv deny or ask rule for the same program still matches.Behaviour
git push *also allowsgit push --force. Any higher-priority deny or ask rule still wins: the rule sits at -1000, and the PR1 testTestArgvAllowBelowDenyis kept.Choices (where the brief was ambiguous)
.../decideputs the id in the path, so the body is not read at all. Any body (dummy tokens, another command, another pattern) is ignored, and a test checks this.Toujours autoriser "<prefix> *"when the server provides a prefix, and plainToujours autoriserotherwise. Clicking the plain button returns the server's refusal message.always_allow_prefix, so the label needs no client-side parsing.Tests run
Run in Kali with the system Go (go1.26.10). The PG tests ran against a throwaway Postgres 16 container on 127.0.0.1, with a fresh database for each run. The container was removed afterwards.
gofmt -lon changed Go files: clean.server/server.gois listed, but only because of its pre-existing unformatted lines (the same 12 diff lines as on main). The added route line is formatted.go build ./...: exit 0.go vet ./...: exit 0.go test -count=1 -p 1 ./...: exit 0, all packages ok.go test -race -count=1 -p 1 ./intercept ./server: exit 0.web:npx tsc --noEmit: exit 0. This is the same check as the CI web job.New tests:
intercept/alwaysallow_denylist_test.go: path form (/usr/bin/env,/usr/bin/python3.11), version suffixes (python3.11,php8.2,ruby3.2,perl5),mkfs.ext4; unlisted programs (nmap,git,curl,gh) stay allowable;AlwaysAllowPrefixrefusals (not Bash, compound, substitution, redirection, empty, denylisted). Matching: argv allow rules forpython,python3.11andfinddo not match and fall back to the ask rule; an argv deny rule forpythonstill matches (listed after the neutralised allow at the same priority); an argv ask rule forfindstill matches.server/intercept_argv_test.go(cases added; the PR1 test is unchanged): the form refuses an allow rule for a denylisted program with the endpoint's message, and accepts deny and ask rules.server/intercept_always_allow_pg_test.go(PG test, skipped withoutARTEX_PG_DSN): the body carries dummy tokens andrm -rf /, and the rule is derived from the row (["gh","pr","list"]); priority -1000, name, timeouts; the pending status is unchanged; the interceptor matches the new rule at once (cache invalidated); an identical rule is reused (created:false, rule count unchanged); not Bash, compound,python3.11and/usr/bin/enveach return 400 with no rule created; a decided request returns 409; the detail carriesalways_allow_prefix.Skipped: biome is not run (CI does not run it, and main already has findings).
Not verified