Skip to content

Intercept: always allow a pending Bash prefix (argv rule, code-owned denylist) - #211

Merged
BaaRai merged 1 commit into
mainfrom
feat/always-allow-argv
Nov 13, 2026
Merged

BaaRai merged 1 commit into
mainfrom
feat/always-allow-argv

Conversation

@BaaRai

@BaaRai BaaRai commented Nov 13, 2026

Copy link
Copy Markdown
Owner

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 example git 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.

  • The id is in the path. The handler never reads the request body. It reloads the intercept_pending row by id, requires status='pending' (otherwise 409, or 404 if the row is missing), reads tool_name and tool_input, and recomputes the prefix with intercept.ArgvPrefix.
  • It returns 400 and creates no rule when: the tool is not Bash; the command does not parse as one simple command (compound, substitution, redirection, assignment, wrapper, ...); the prefix is empty; or the program is on the denylist.
  • Otherwise it creates the rule: match_type=argv, match_target=tool_input, action=allow, enabled=true, priority=-1000 (constant alwaysAllowPriority), name always-allow: <prefix>. Timeouts take the rule form defaults (enabled, 60 s, deny). It then calls interceptor.Invalidate().
  • If an enabled argv allow rule with the same tokens already exists, the endpoint returns it with created:false and does not create a second one.
  • The pending request is never decided and its status never changes.
  • GET /api/intercept/history/{id} now also returns always_allow_prefix for 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, pip3 become python, php, ruby, perl, pip), and every mkfs.* becomes mkfs. So /usr/bin/env and /usr/bin/python3.11 are caught.

  • interpreters and shells: sh bash zsh dash ksh fish csh tcsh ash mksh rbash pwsh powershell python pypy ipython perl ruby irb node deno bun php lua luajit rscript tclsh wish expect awk gawk mawk nawk sed jshell osascript
  • launchers (run their arguments, or a flag's value, as a command): env command builtin exec eval source . nohup timeout nice ionice stdbuf setsid chroot unshare nsenter systemd-run su sudo doas pkexec runuser setpriv sg watch busybox toybox xargs parallel make gmake mapfile trap script find ssh scp sftp rsync socat ncat nc netcat flock strace ltrace gdb taskset chrt unbuffer rlwrap firejail bwrap proot proxychains torsocks tar zip vim vi nvim emacs less more man
  • package managers and build tools (run package scripts and hooks): npm npx pnpm yarn bunx corepack pip pipx uv uvx poetry conda composer gem bundle bundler rake cargo go mvn gradle dotnet apt apt-get dpkg dnf yum rpm pacman apk brew snap flatpak
  • orchestration (runs images, playbooks and plans): docker docker-compose podman nerdctl kubectl helm ansible ansible-playbook terraform pulumi vagrant
  • destructive: rm dd mkfs (every mkfs.*) mkswap wipefs fdisk sfdisk parted shred truncate chmod chown kill pkill killall systemctl service iptables ip6tables nft ufw mount umount swapoff shutdown reboot poweroff halt init telinit crontab insmod rmmod modprobe

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:

  1. At creation, in this endpoint.
  2. In the manual rule form (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.
  3. At matching (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

  • The rule is created, and the request stays pending. The approver still has to allow or deny it. The UI says "Rule created, the request is still pending approval", or "Rule already exists, ..." when the rule is reused.
  • Flags are not constrained: git push * also allows git push --force. Any higher-priority deny or ask rule still wins: the rule sits at -1000, and the PR1 test TestArgvAllowBelowDeny is kept.
  • The prefix does not cover what the program does next: git hooks, npm scripts, docker images, configuration files the program reads. The UI says so next to the button.
  • On a refusal the UI shows the server message as is.

Choices (where the brief was ambiguous)

  • Path id instead of a body id. "Same path style" as .../decide puts 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.
  • Only an enabled identical rule is reused. If an identical rule is disabled, a new enabled rule is created, because someone may have disabled the old one on purpose.
  • The button is shown for every pending Bash approval. It is labelled Toujours autoriser "<prefix> *" when the server provides a prefix, and plain Toujours autoriser otherwise. Clicking the plain button returns the server's refusal message.
  • The detail endpoint returns always_allow_prefix, so the label needs no client-side parsing.
  • Concurrent clicks are not serialised. Two simultaneous first clicks could create two identical rules. This is harmless (same effect) and not handled.

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 -l on changed Go files: clean. server/server.go is 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; AlwaysAllowPrefix refusals (not Bash, compound, substitution, redirection, empty, denylisted). Matching: argv allow rules for python, python3.11 and find do not match and fall back to the ask rule; an argv deny rule for python still matches (listed after the neutralised allow at the same priority); an argv ask rule for find still 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 without ARTEX_PG_DSN): the body carries dummy tokens and rm -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.11 and /usr/bin/env each return 400 with no rule created; a decided request returns 409; the detail carries always_allow_prefix.

Skipped: biome is not run (CI does not run it, and main already has findings).

Not verified

  • No end-to-end run against a live stack or a real agent.
  • The UI is type-checked only (locally and by CI). It was not rendered or clicked.

…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.
@BaaRai
BaaRai merged commit 0edf3f0 into main Nov 13, 2026
4 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