Repository navigation
fix(security): read heredoc bodies in the shared shell reader and the rm floor - #30600
Conversation
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/security/rm_floor.py:235 -- Producer-name check treats disconnected heredoc data as executable
BLOCKING -- src/kiro_crew/security/rm_floor.py:372 -- ANSI-C normalization manufactures executable commands from heredoc data
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1. LOW. Both triggers are contrived. The pipeline must be F2. LOW. The trigger needs an ANSI-C False positive or not applicable? A repository writer can comment: |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concern blocks this: the reader flag is opt-in, the rm floor now reads heredoc bodies only when a shell runs them, and every new reading only adds refusals. Notes
[DESIGN-REVIEWED] 886abe8 Description read[DESCRIPTION-READ] ab0d26419a216744225e54e35bd949363ff1884735a8daf373e2923e4ca71d9c 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 |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Nothing blocks. Two notes: the wrapper-table rider has no reported defect behind it, and this leaves two heredoc-body cutters in Notes
What this change shipsInventory (9 items) — 7 justifiedIntent: stop a root or home
[FIRST-PRINCIPLES-REVIEWED] 886abe8 Description read[DESCRIPTION-READ] f88c367e586724b77c24fb6d32c9d7be06f4f95e31f9ccee535cf07e65d60622 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: |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: The change makes the TIGHTENING: ADJUDICATED: 23 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix (20 rows): the new code assumes POSIX heredoc grammar (
windows (3 rows): the tag-line match compares the line to the tag exactly and splits on UNADJUDICATED: Nothing outside the shell deny composite was changed, so the whole tightening went through the classifier. One narrowing I could argue but could not confirm with a legitimate row: [SCOPE-REVIEWED] 37802ca |
|
self-added: yes
Notes item ( |
|
self-added: yes
|
|
self-added: yes
|
|
37802ca to
13820b0
Compare
Sensitive change review
|
Sensitive change review
|
13820b0 to
1b1e21a
Compare
Sensitive change review
|
|
self-added: yes
|
92dbb4f to
b90e7a1
Compare
Sensitive change review
|
b90e7a1 to
886abe8
Compare
|
self-added: yes
|
Sensitive change review
|
) The budget raise in #30600 was measured on a base without the security fixes that merged before it, so main landed 34 lines over budget and test_the_package_stays_within_its_line_budget fails on every PR. Set the budget to the measured size. No code change.
Problem / Motivation
Goal: The shared shell reader reads here-document bodies and the substitutions in them, so the rm floor refuses a root or home wipe that a shell runs from a heredoc, and other gates can use the same reading.
On main,
shell_commands.read_commandsstops at the first live<<. So the recursive-forcermfloor never sees these, and bash runs each of them:bash <<EOF,bash <<'EOF',bash <<-EOF,bash -s <<EOF,cat <<EOF | bash;cat <<EOFwith$(<wipe>)in the body;\nescape in$'...'handed to-c(bash -c $'echo\n<wipe>'): the tokenizer decodes it to a blank, so the payload reads as oneechocommand.Why it matters
Each shape is a wipe of
/or~the floor lets through when the regex rows miss its spelling. It is also the blocker on the exfil gate's gh body-from-file check (#21307): the maintainer ruled that it should consume the parsed here-documents and substitutions instead of its own scanner, and wait for this reader work.Not a goal
read_commandsread:exfil_bash,acp/batch_guardand the per-line read inrm_floorkeep the stopping read. Only callers that passheredocs=Trueget the new one.<<shift inside$((…))or((…))still reads as a heredoc, the same as main.cat,tee,git commit -F -): it stays data.argv_rules._without_heredoc_bodies: it keeps its own heredoc regex. Switchingargv_rules._commandstoread_commands(..., heredocs=True)is follow-up work.$(…)in an unquoted heredoc body that holds a nested heredoc with a), nor$+ backslash-newline +(…): the reader does not see that substitution, so a wipe inside it is not refused. Main allows both too; left out by the owner's choice and tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593.cat <<EOF |& bash:|&is read as|plus an empty&command, so the body is not read as a script. Main misses it too; tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593.ssh host bash <<EOFsends the body to a remote shell, which this local floor does not read.xargs bash <<EOF: it is refused although xargs hands the body to bash as arguments, not as its script. It fails closed.sufeeding a heredoc to a shell:su -s <shell> <user> <<EOFand plainsu <user> <<EOF(the login shell reads stdin) are not read as a shell script. Main allows both too, so this is not a regression. Tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593._PACKAGE_LINE_BUDGETintest/test_security_gate_liveness.pygoes from 34,524 to 34,699. The raise is only the production lines this PR adds to the security package: 34,464 on main plus a net 235 inrm_floor.py(+132/-8),shell_commands.py(+115/-9) andargv_rules.py(+5).What changed (motivation → approach → change)
Root cause: the reader stopped at
<<, so the floor had no body to read and nothing after it.security/shell_commands.py):read_commands(..., heredocs=True)reads on past<</<<-. Each body goes to its command as aHereDoc(text, offsets, quoted tag or not). In an unquoted body, each$(…)and backtick body is read once as commands of its own; quotes there are plain text.security/rm_floor.py): it reads with that flag, so commands after a heredoc are read. A body is a payload only when a shell reads its script from stdin (directly or behind a wrapper, found by the sharedargv_rules._program_args, with no-cand no script file; a-cafter-sstill wins), or the command pipes into one. Only the body on the command's last fd 0 redirection counts (3<<Bis not fd 0,bash <<EOF </dev/nullreads no body), a pipe's body is not read when the receiving shell has its own stdin redirect, a-n,-o noexec,--helpor--versionshell runs nothing, only acatorteeproducer forwards its heredoc down a pipe, line continuations are folded only outside heredoc bodies, and an unquoted body folds backslash-newline before its end word is matched. The tag line that closed a body is cut out with it; an unclosed body (inside a backtick) is never stretched past its own text.argv_rules._WRAPPERSlearnsnsenter,unshare,flock,tasksetandchrt. One more view keeps\nin$'...'as a newline. The walk reads at most_WALK_BUDGET_CHARS(16 timesMAX_SCANNABLE_COMMAND_CHARS) across the command and its nested payloads; past that it fails closed, so deep heredoc nesting cannot stall the gate. Each new reading only adds refusals.docs/system-specs/modules/security.md): records the reader flag and what the floor reads now.Issue rows 1 and 2 (an option after
-c, a comment ending in a backslash) are already refused on main; the new test file pins them. The issue's known false refusal (cat <<EOFwith a nested shell line in the body) is allowed on main and stays allowed.Backwards compatibility
Compatible: the default read is byte-for-byte unchanged, and the floor only adds refusals for shapes bash runs.
Removes nothing: no row, key or public function is removed;
ShellCommandgains aheredocsfield with an empty default.Tests
test/test_shell_heredoc_reader.py(new):<<; bodies go to their command and the read goes on; quoted tags,<<-tab stripping, two bodies on one line; raw offsets; substitutions in an unquoted body read once with literal quotes; an unclosed body runs to the end.is_deniedgate): each heredoc-into-shell shape, a substitution or nested shell in an unquoted body, a command after a heredoc, the$'...'newline, a command after an unclosed heredoc inside a backtick, a wrapper or shell option with a value (-euo pipefail),chrootandbusyboxshells, a command after a nested heredoc, plus regression rows for options after-cand a comment ending in a backslash.cat, a script written to a file, a commit message, a substitution in a quoted body,echo $'<wipe>',bash -c cat <<EOF,tee bash <<EOF,bash script.sh <<EOF,bash <<EOF </dev/null,bash -s -c cat <<EOF, a tag line that spells a wipe,bash <<A 3<<B,cat <<EOF | bash </dev/null,bash -n/bash -o noexec/bash --help,printf ... <<EOF | bash, a backslash-newline in a quoted body, andprefix\+ newline +EOFin an unquoted body.test/test_shell_commands_reader.py: the segment parity test now skips commands holding<<, where the floor reads past the body on purpose; the target and verdict parity tests still run on them.test/test_security_gate_liveness.py: the package line budget is raised by 175 with its note.Walk budget: 1,180 nested
bash <<Elevels at the size cap are refused with the budget reason, and the test counts the characters the walk reads (at most the budget plus one source; 12.2 M without the budget). A 2-level nested home wipe is still refused by its content.Mutants: main's
rm_floor.pyfails every new refusal row;_runs_shellalways true fails the allow rows for a body given tocator a file; not cutting bodies out of the per-line read fails 2 allow rows; the any-shell-word_runs_shelland the unmerged nested cut fail the 3 shell-name allow rows and the nested-heredoc refusal row.Determinism: 20 of 20 runs at
-n0, 5 of 5 at-n 4besidetest_shell_commands_reader.py, and one shuffled-order run, all green.Proof: PROVEN test/test_shell_heredoc_reader.py::test_the_floor_refuses[bash-heredoc], test/test_shell_heredoc_reader.py::test_the_floor_refuses[bash-quoted-heredoc], test/test_shell_heredoc_reader.py::test_the_floor_refuses[bash-tab-heredoc], test/test_shell_heredoc_reader.py::test_the_floor_refuses[bash-s-heredoc], test/test_shell_heredoc_reader.py::test_the_floor_refuses[cat-heredoc-into-bash] (head 886abe8)
Manual verification
N/A — unit coverage sufficient: the change is a text reader and a deny check, both run directly by the tests through
is_denied.Related Issues
Fixes #22756
Unblocks #21307 (it rebases onto this and reads the gh argv of every command, heredoc substitutions included).
Sibling sweep
Swept: git grep -n "read_commands" -- src/
Sibling: src/kiro_crew/security/exfil_bash.py -- not affected -- reads only the first word of the first command, before any heredoc
Sibling: src/kiro_crew/acp/batch_guard.py -- not affected -- splits a batch into commands; a heredoc body there is data
Sibling: src/kiro_crew/security/rm_floor.py -- changed here
Pattern harvest
Not generalizable: the defect is one reader's stop at
<<; the fix moves heredoc reading into that shared reader instead of a per-gate scanner.Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)