Skip to content

fix(security): read heredoc bodies in the shared shell reader and the rm floor - #30600

Merged
kyleseaman merged 1 commit into
mainfrom
crew/issue-triage/KiroCrew-22756
Nov 6, 2026
Merged

kyleseaman merged 1 commit into
mainfrom
crew/issue-triage/KiroCrew-22756

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

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_commands stops at the first live <<. So the recursive-force rm floor never sees these, and bash runs each of them:

  • a heredoc fed to a shell: bash <<EOF, bash <<'EOF', bash <<-EOF, bash -s <<EOF, cat <<EOF | bash;
  • a substitution in an unquoted heredoc body: cat <<EOF with $(<wipe>) in the body;
  • any command on a line after a heredoc ends;
  • a \n escape in $'...' handed to -c (bash -c $'echo\n<wipe>'): the tokenizer decodes it to a blank, so the payload reads as one echo command.

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

  • No change to the default read_commands read: exfil_bash, acp/batch_guard and the per-line read in rm_floor keep the stopping read. Only callers that pass heredocs=True get the new one.
  • Not the gh body-from-file matcher: docs: stream gh JSON payloads on stdin in the PR-body fallback and the sage poster #21307 adopts the reader there after a rebase.
  • Not a bash parser library, and not arithmetic: a << shift inside $((…)) or ((…)) still reads as a heredoc, the same as main.
  • Not a heredoc body given to a program that is not a shell (cat, tee, git commit -F -): it stays data.
  • Not argv_rules._without_heredoc_bodies: it keeps its own heredoc regex. Switching argv_rules._commands to read_commands(..., heredocs=True) is follow-up work.
  • Not a $(…) 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.
  • Not 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.
  • Not a shell run on another host: ssh host bash <<EOF sends the body to a remote shell, which this local floor does not read.
  • Not xargs bash <<EOF: it is refused although xargs hands the body to bash as arguments, not as its script. It fails closed.
  • Not su feeding a heredoc to a shell: su -s <shell> <user> <<EOF and plain su <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.
  • Budget: the package line ratchet _PACKAGE_LINE_BUDGET in test/test_security_gate_liveness.py goes 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 in rm_floor.py (+132/-8), shell_commands.py (+115/-9) and argv_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.

  • Reader (security/shell_commands.py): read_commands(..., heredocs=True) reads on past << / <<-. Each body goes to its command as a HereDoc (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.
  • rm floor (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 shared argv_rules._program_args, with no -c and no script file; a -c after -s still wins), or the command pipes into one. Only the body on the command's last fd 0 redirection counts (3<<B is not fd 0, bash <<EOF </dev/null reads no body), a pipe's body is not read when the receiving shell has its own stdin redirect, a -n, -o noexec, --help or --version shell runs nothing, only a cat or tee producer 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._WRAPPERS learns nsenter, unshare, flock, taskset and chrt. One more view keeps \n in $'...' as a newline. The walk reads at most _WALK_BUDGET_CHARS (16 times MAX_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.
  • Spec (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 <<EOF with 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; ShellCommand gains a heredocs field with an empty default.

Tests

test/test_shell_heredoc_reader.py (new):

  • Reader: the default still stops at <<; 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.
  • Floor refuses (rm floor and the full is_denied gate): 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), chroot and busybox shells, a command after a nested heredoc, plus regression rows for options after -c and a comment ending in a backslash.
  • Floor allows: a body given to 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, and prefix\ + newline + EOF in 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 <<E levels 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.py fails every new refusal row; _runs_shell always true fails the allow rows for a body given to cat or a file; not cutting bodies out of the per-line read fails 2 allow rows; the any-shell-word _runs_shell and 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 4 beside test_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

  • 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

@iamwhatever
iamwhatever requested review from a team and KiroCrewCaptain as code owners November 5, 2026 17:31
@iamwhatever
iamwhatever requested a review from CrysisDeu November 5, 2026 17:31
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_rules.py

  • src/kiro_crew/security/rm_floor.py

  • src/kiro_crew/security/shell_commands.py

  • @iamwhatever posted a complete reasoning template for 886abe8.

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

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 886abe831355d434af812ed48c2ac599fe2e9b3c 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 Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)

GPT 6.1 flagged blocking issues on 886abe831355d434af812ed48c2ac599fe2e9b3c; Opus 5.5 adjudication downgraded every one of them. Downgraded: the remedy each one needs is disproportionate to the harm it prevents. Adjudication downgraded all 2 blocking finding(s): the remedy each one requires is disproportionate to the harm it prevents.

This comment is updated in place on each push.

Review details

BLOCKING -- src/kiro_crew/security/rm_floor.py:235 -- Producer-name check treats disconnected heredoc data as executable

return (argv_rules._program_args(words) or ("",))[0] in ("cat", "tee")
Trigger: cat /dev/null <<'EOF' | bash\nrm -r --force /\nEOF reaches is_denied → _rm_wipe_targets_nested → _heredoc_payloads → _forwards_stdin, which accepts cat without inspecting its operands.
Outcome: cat reads /dev/null, so bash receives no script, but the gate refuses this previously allowed command as a root wipe.
Anchor: defect
Fix: Admit a pipeline body only when the producer consumes its stdin and its stdout remains connected to the receiving shell.
Sites: _heredoc_payloads at rm_floor.py:217 also admits cat <<'EOF' >/dev/null | bash and tee <<'EOF' >/dev/null | bash with the same body, although stdout redirection disconnects both from bash.
Remedy: narrow or remove the mechanism

BLOCKING -- src/kiro_crew/security/rm_floor.py:372 -- ANSI-C normalization manufactures executable commands from heredoc data

views = (source, _ansi_c_newlines(source)) if "$'" in source else (source,)
Trigger: Submit cat <<'EOF' with the single body line $'text\nEOF\nbash -c "rm --recursive -f ~"\nEOF' containing literal backslash-n pairs, followed by the actual closing EOF line. is_denied → _rm_wipe_targets_nested → _ansi_c_newlines → _command_tokens converts those pairs into newlines before identifying heredoc boundaries.
Outcome: A fabricated EOF line closes the normalized body prematurely, exposing a fabricated bash -c command. The gate denies a home wipe although bash only prints literal data; the base allows it.
Anchor: defect
Fix: Exclude actual heredoc bodies before constructing the ANSI-C-normalized command view, retaining their separate payload and substitution processing.
Sites: The same refusal occurs with an unquoted delimiter and with tee fixture.sh instead of cat, through the view construction at rm_floor.py:372.
Remedy: narrow or remove the mechanism

[BLOCK-MERGE-DOWNGRADED] 886abe8
[GPT-REVIEWED] 886abe8

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

F1. LOW. Both triggers are contrived. The pipeline must be cat/tee taking a heredoc and piping to a shell (rm_floor.py:218-223), and the producer then has to ignore that heredoc, either through a file operand or an stdout redirect. _forwards_stdin at rm_floor.py:235 checks only the program name. The result is a loud refusal on a fail-closed floor, not a silent one. The author can recover by dropping the dead heredoc, and nothing is lost. The real fix needs operand parsing plus stdout-redirect tracking per producer. That is a new mechanism serving only this path, and its cost exceeds the harm.

F2. LOW. The trigger needs an ANSI-C $'…' string inside a heredoc body. The string must spell a fake terminator line followed by an rm wipe through a nested shell. The view is built at rm_floor.py:372 without first cutting out the bodies (the cutting happens at rm_floor.py:194-205). Benign scripts essentially never contain this. The result is a loud, recoverable over-denial with no security exposure. The real fix reorders view construction against body cutting while keeping body-payload and substitution handling intact. That is a new ordering contract in a security walker, and its cost exceeds a rare false positive.

[ADJUDICATION] 886abe831355d434af812ed48c2ac599fe2e9b3c total=2 uphold=0 downgrade=2
DOWNGRADE F1 src/kiro_crew/security/rm_floor.py:235 reason=disproportionate-remedy
DOWNGRADE F2 src/kiro_crew/security/rm_floor.py:372 reason=disproportionate-remedy
[GPT-ADJUDICATED] 886abe831355d434af812ed48c2ac599fe2e9b3c

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

@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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

  • This PR adds a second heredoc reader alongside the regex reader in argv_rules._without_heredoc_bodies, so the two can now disagree about what a body is. Switching _commands to heredocs=True should land soon, not stay open-ended.
  • The _WRAPPERS additions also change acp/batch_guard._program_commands. For example, flock -w 5 git push now reads as a write. The description names only the floor, so list batch_guard among the affected callers.

[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 .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 Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 886abe831355d434af812ed48c2ac599fe2e9b3c — 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: PASS

Nothing blocks. Two notes: the wrapper-table rider has no reported defect behind it, and this leaves two heredoc-body cutters in security/.

Notes

  • Item 6 — rides along, inherited: "argv_rules._WRAPPERS learns nsenter, unshare, flock, taskset and chrt". The description shows no defect for these five. The table is read by every _program_args consumer (11 call sites matched by _program_args|_without_heredoc_bodies), so the git-publish and self-protection floors change too. Subtraction: drop the five _WRAPPERS rows from this PR. They can land later, once a reported wipe shows they are needed.
  • Item 9 — duplicate of argv_rules._without_heredoc_bodies (src/kiro_crew/security/argv_rules.py:177). rm_floor._without_bodies is a second way to cut heredoc bodies, and security/ now has 2 of them. The new one is built on the shared reader, which is what the maintainer ruled the gates should use. Subtraction: delete _without_heredoc_bodies and _HEREDOC_OP, and have argv_rules._commands use read_commands(..., heredocs=True). That work is deferred in ## Not a goal.

What this change ships

Inventory (9 items) — 7 justified

Intent: stop a root or home rm -rf wipe getting past the floor when a shell runs it from a heredoc. FIX.

  1. Wipe inside a heredoc body fed to a shell (bash <<EOF, cat <<EOF | bash) is refused — justified
  2. Commands on lines after a heredoc are now read — justified
  3. Wipe in a $(…) or backtick inside an unquoted heredoc body is refused — justified
  4. \n inside $'…' given to -c is read as a new line — justified
  5. Shared reader gains heredocs=True and a HereDoc field on each command — justified
  6. Wrapper table gains five programs, which changes every argv floor — rides along, inherited, no reported defect
  7. Walk fails closed once it passes a character budget — justified
  8. Package line budget raised by 175 — justified
  9. Second heredoc-body cutter added beside argv_rules._without_heredoc_bodies — duplicate of argv_rules.py:177

[FIRST-PRINCIPLES-REVIEWED] 886abe8

Description read

[DESCRIPTION-READ] f88c367e586724b77c24fb6d32c9d7be06f4f95e31f9ccee535cf07e65d60622

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 readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Nov 5, 2026
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 886abe8

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

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

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

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

Verdict basis: adjudicated, zero confirmed regressions.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 20 classified, 0 newly refused, 15 still allowed.
  • ubuntu-latest (platform posix): 20 classified, 0 newly refused, 15 still allowed.
  • windows-latest (platform windows): 3 classified, 0 newly refused, 2 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The change makes the rm floor stricter in one way. It now reads heredoc bodies that a shell runs as its script, commands that follow a heredoc, substitutions inside unquoted bodies, and \n escapes in $'…'. It still refuses only recursive-force rm aimed at root or home. No candidate was confirmed newly refused. One possible narrowing is named below but not confirmed: _runs_shell checks every word after a wrapper for a shell name, not only the program position. A heredoc body sent to sudo tee bash or env tool.py bash would therefore be read as a script. That only causes a refusal if the body itself contains the root or home wipe.

TIGHTENING: rm_floor heredoc reading (read_commands(..., heredocs=True) in _segments/_command_lines, plus the new _heredoc_payloads, _runs_shell and _ansi_c_newlines) -- refuses a root/home recursive-force wipe hidden in a heredoc that a shell runs, or placed after a heredoc. Quoting the hunk: "Each heredoc body a shell reads as its script (``bash <<EOF``, ``cat <<EOF | sh``), and each command read from a substitution in an unquoted body, which bash runs." and - for cmd in _commands.read_commands(text, track): / + for cmd in _commands.read_commands(text, track, heredocs=True):

ADJUDICATED: 23 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (20 rows): the new code assumes POSIX heredoc grammar (<<, <<- tab stripping, quoted versus unquoted tags), \n line endings, and shell program names like bash, sh, sudo, env and timeout. The rows cover:

  • bodies fed to a shell directly, behind a wrapper, and through a pipe;
  • bodies given to other programs (git, cat, make, sudo tee);
  • commands after a heredoc, including after a heredoc nested in $(…);
  • substitutions and $((…)) inside unquoted bodies, and a bare << bit-shift inside arithmetic;
  • the $'…\n…' newline view.

windows (3 rows): the tag-line match compares the line to the tag exactly and splits on \n, so it assumes LF line endings. The windows rows probe CRLF heredocs in Git Bash, an MSYS /c/ drive path, and a $USERPROFILE home-descendant. Native cmd.exe/PowerShell spellings have no << heredoc and are outside this tightening, so I wrote no candidate for them.

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: _runs_shell returns True whenever any word after a _STDIN_WRAPPERS program has a shell basename (for example sudo tee bash, env python3 gen.py --shell bash, or sudo apt-get install -y zsh with a heredoc). In those cases the body is data for a program that is not a shell. The call path is is_denied → rm floor → _rm_wipe_targets_nested → _heredoc_payloads → _runs_shell. It only matters when that data body itself spells a root/home recursive-force wipe, and I found no real operation that does. Narrowing it would mean letting a shell basename count only at the wrapper's command position, not at any later argv word.

[SCOPE-REVIEWED] 37802ca

@github-actions github-actions Bot added the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 5, 2026
@iamwhatever

iamwhatever commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: rm_floor's own stdin-wrapper table
resolution: removed

  • Second wrapper table for finding the program behind a wrapper (span=81dac4c0347c)

fixed in 92dbb4f: _STDIN_WRAPPERS is deleted; _runs_shell unwraps through argv_rules._program_args (lazy import, as argv_rules imports rm_floor).
argv_rules._WRAPPERS gains nsenter, unshare, flock, taskset and chrt, so no shape this PR refused is allowed; pkexec bash <<EOF is now refused too.

Notes item (argv_rules._without_heredoc_bodies): deferred, listed under Not a goal. Removing it alone fails test_real_permission_changes_are_refused for cat <<'EOF' && chmod ...; it needs argv_rules._commands to read read_commands(..., heredocs=True).

@iamwhatever

iamwhatever commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: each heredoc body queued as a new walk source
resolution: narrowed

  • Quadratic heredoc walk in _rm_wipe_targets_nested (span=f6adfbd55f89)

fixed in 92dbb4f: the walk counts every source it reads and fails closed past _WALK_BUDGET_CHARS (16 x MAX_SCANNABLE_COMMAND_CHARS).
1,180 nested bash <<E levels at the size cap are refused in about 0.4 s (16 s before); a test pins the refusal and a 2 s ceiling.

@iamwhatever

iamwhatever commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: which heredoc body a shell reads as its script

  • Shell-looking arguments cause harmless heredocs to be denied (span=e8aa6e56f6f9)

fixed in 92dbb4f: each over-refusal on this span is allowed now, with a test row each.
env tee bash: _runs_shell resolves the program via argv_rules._program_args. bash -s -c cat: a later -c wins over -s.
bash <<EOF </dev/null and two heredocs: only the last fd 0 redirection's body counts. A tag line that spells a wipe is cut out with its body.

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Heredoc substitution parsing misses executable home wipes (span=e0f4af479de1)

Not fixed, by the owner's choice: $(…) with a nested heredoc holding ), and $ + backslash-newline + (, are not read as substitutions.
Main allows both inputs too (checked on origin/main), so this PR adds no gap. Tracked in #30593; listed under Not a goal.

@iamwhatever
iamwhatever force-pushed the crew/issue-triage/KiroCrew-22756 branch from 37802ca to 13820b0 Compare November 6, 2026 02:09
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 13820b0
  • What rule changed: the recursive-force rm floor (rm_floor.py) now reads heredocs through the shared reader (shell_commands.read_commands(heredocs=True)); argv_rules._WRAPPERS gains nsenter, unshare, flock, taskset and chrt.
  • Before -> after (what was allowed/blocked, now): before, a root or home wipe in a heredoc fed to a shell (bash <<EOF, cat <<EOF | bash), in a substitution in an unquoted body, on a line after a heredoc, or behind a \\n in $'...' given to -c was allowed. Now each is refused. Heredoc bodies given to non-shells (cat, tee, git commit -F -), bash -c cat, bash -s -c cat, bash <<EOF </dev/null and a tag line that spells a wipe stay allowed. Default read_commands behaviour is unchanged for other callers.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands. A false refusal of a harmless heredoc command, or of a command that nests heredocs past _WALK_BUDGET_CHARS (16 x the 20 KiB scan cap), which then fails closed with the floor's "could not read" note. No secret path is touched.
  • Evidence checked (which sandbox result proves it): no sandbox change; the floor runs before the sandbox. Evidence is test/test_shell_heredoc_reader.py through deny_gate.is_denied, prove.py PROVEN on this head, and one mutant per mechanism failing its rows. Known gaps listed under Not a goal (allowed on main too): su shapes and two substitution shapes, tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593.
  • No regression:
    • Tools still work (which tools/commands were run, result): is_denied probed locally on refusal and allow shapes; 1,180-level nested heredoc at the size cap refused in about 0.4 s.
    • Backward compatible (old config / old data / old callers still work, how checked): heredocs defaults to False and ShellCommand.heredocs defaults to (); test_shell_commands_reader.py parity tests pass; no config or data format change.
    • Existing tests (which suites passed on this head): 1606 passed across test_shell_heredoc_reader, test_shell_commands_reader, test_argv_rules, test_argv_floor_inline_and_brace_scope, test_denied_commands_security_rows/_quoting, test_denied_commands_security, test_security_bash_gate, test_trust_reads, test_security_gate_liveness.
  • How to undo: revert this single commit; nothing to migrate.

@github-actions github-actions Bot removed the merge conflict Branch has merge conflicts with its base — author must resolve before merge label Nov 6, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 13820b0
  • What rule changed: three sensitive files. src/kiro_crew/security/shell_commands.py: read_commands(heredocs=True) reads past a live << and hands each body to its command (default read unchanged). src/kiro_crew/security/rm_floor.py: the recursive-force rm floor uses it to read heredoc bodies a shell runs, commands after a heredoc, and a \n in $'...', with a walk budget. src/kiro_crew/security/argv_rules.py: five wrappers (nsenter, unshare, flock, taskset, chrt) added to _WRAPPERS; this only adds refusals, because a command behind them is now read as the real program.
  • Before -> after (what was allowed/blocked, now): before, a root or home wipe in a heredoc fed to a shell (bash <<EOF, cat <<EOF | bash, behind a wrapper), in a substitution in an unquoted body, on a line after a heredoc, or behind \n in $'...' given to -c was allowed. Now each is refused. Heredocs given to non-shells, bash -c cat <<EOF, bash -s -c cat <<EOF, bash <<EOF </dev/null and a tag line that spells a wipe stay allowed. The chmod/chown argv rules see through the five new wrappers too, so they can only refuse more.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: a false refusal of a harmless heredoc command, or of a command nesting heredocs past _WALK_BUDGET_CHARS (16 x the 20 KiB scan cap), which fails closed with the floor's could-not-read note. No secret path is read or exposed.
  • Evidence checked (which sandbox result proves it): no sandbox change; these gates run before the sandbox. Evidence is test/test_shell_heredoc_reader.py through deny_gate.is_denied, prove.py PROVEN on this head, and a mutant per mechanism failing its rows. Known gaps allowed on main too are listed under Not a goal and tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593.
  • No regression:
    • Tools still work (which tools/commands were run, result): is_denied probed locally on refusal and allow shapes; a 1,180-level nested heredoc at the size cap is refused in about 0.4 s.
    • Backward compatible (old config / old data / old callers still work, how checked): heredocs defaults to False and ShellCommand.heredocs to (); test_shell_commands_reader.py parity and test_argv_rules.py pass; no config or data format change.
    • Existing tests (which suites passed on this head): 1606 passed across test_shell_heredoc_reader, test_shell_commands_reader, test_argv_rules, test_argv_floor_inline_and_brace_scope, test_denied_commands_security_rows/_quoting, test_denied_commands_security, test_security_bash_gate, test_trust_reads, test_security_gate_liveness.
  • How to undo: revert this single commit; nothing to migrate.

@iamwhatever
iamwhatever force-pushed the crew/issue-triage/KiroCrew-22756 branch from 13820b0 to 1b1e21a Compare November 6, 2026 02:31
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 1b1e21a
  • What rule changed: three sensitive files. src/kiro_crew/security/shell_commands.py: read_commands(heredocs=True) reads past a live << and hands each body to its command (default read unchanged). src/kiro_crew/security/rm_floor.py: the recursive-force rm floor uses it to read heredoc bodies a shell runs, commands after a heredoc, and a \n in $'...', with a walk budget. src/kiro_crew/security/argv_rules.py: five wrappers (nsenter, unshare, flock, taskset, chrt) added to _WRAPPERS; this only adds refusals, because a command behind them is now read as the real program.
  • Before -> after (what was allowed/blocked, now): before, a root or home wipe in a heredoc fed to a shell (bash <<EOF, cat <<EOF | bash, behind a wrapper), in a substitution in an unquoted body, on a line after a heredoc, or behind \n in $'...' given to -c was allowed. Now each is refused. Heredocs given to non-shells, bash -c cat <<EOF, bash -s -c cat <<EOF, bash <<EOF </dev/null and a tag line that spells a wipe stay allowed. The chmod/chown argv rules see through the five new wrappers too, so they can only refuse more.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: a false refusal of a harmless heredoc command, or of a command nesting heredocs past _WALK_BUDGET_CHARS (16 x the 20 KiB scan cap), which fails closed with the floor's could-not-read note. No secret path is read or exposed.
  • Evidence checked (which sandbox result proves it): no sandbox change; these gates run before the sandbox. Evidence is test/test_shell_heredoc_reader.py through deny_gate.is_denied, prove.py PROVEN on this head, and a mutant per mechanism failing its rows. Known gaps allowed on main too are listed under Not a goal and tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593.
  • No regression:
    • Tools still work (which tools/commands were run, result): is_denied probed locally on refusal and allow shapes; a 1,180-level nested heredoc at the size cap is refused in about 0.4 s.
    • Backward compatible (old config / old data / old callers still work, how checked): heredocs defaults to False and ShellCommand.heredocs to (); test_shell_commands_reader.py parity and test_argv_rules.py pass; no config or data format change.
    • Existing tests (which suites passed on this head): 1606 passed across test_shell_heredoc_reader, test_shell_commands_reader, test_argv_rules, test_argv_floor_inline_and_brace_scope, test_denied_commands_security_rows/_quoting, test_denied_commands_security, test_security_bash_gate, test_trust_reads, test_security_gate_liveness.
  • How to undo: revert this single commit; nothing to migrate.

@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 Nov 6, 2026
@iamwhatever

iamwhatever commented Nov 6, 2026 •

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: stretching a cut heredoc body to the next newline
resolution: narrowed

  • An unclosed heredoc inside a backtick stretched its cut past the backtick (span=f6adfbd55f89)

fixed in 92dbb4f: HereDoc.tail is the offset past the tag line that closed the body, or the body end when none did; _command_lines cuts up to tail, never to the next outer newline.
The lane's command (unclosed <<EOF in a backtick, then ; bash -c '<root wipe>') is refused again, as on base; a test row pins it and the old stretch fails it.

@iamwhatever
iamwhatever force-pushed the crew/issue-triage/KiroCrew-22756 branch from 92dbb4f to b90e7a1 Compare November 6, 2026 03:15
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: b90e7a1
  • What rule changed: three sensitive files. src/kiro_crew/security/shell_commands.py: read_commands(heredocs=True) reads past a live << and hands each body to its command (default read unchanged). src/kiro_crew/security/rm_floor.py: the recursive-force rm floor uses it to read heredoc bodies a shell runs, commands after a heredoc, and a \n in $'...', with a walk budget. src/kiro_crew/security/argv_rules.py: five wrappers (nsenter, unshare, flock, taskset, chrt) added to _WRAPPERS; this only adds refusals, because a command behind them is now read as the real program.
  • Before -> after (what was allowed/blocked, now): before, a root or home wipe in a heredoc fed to a shell (bash <<EOF, cat <<EOF | bash, behind a wrapper), in a substitution in an unquoted body, on a line after a heredoc, or behind \n in $'...' given to -c was allowed. Now each is refused. Heredocs given to non-shells, bash -c cat <<EOF, bash -s -c cat <<EOF, bash <<EOF </dev/null, bash <<A 3<<B, cat <<EOF | bash </dev/null, bash -n, a continuation before the end word and a tag line that spells a wipe stay allowed. The chmod/chown argv rules see through the five new wrappers too, so they can only refuse more.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: a false refusal of a harmless heredoc command, or of a command nesting heredocs past _WALK_BUDGET_CHARS (16 x the 20 KiB scan cap), which fails closed with the floor's could-not-read note. No secret path is read or exposed.
  • Evidence checked (which sandbox result proves it): no sandbox change; these gates run before the sandbox. Evidence is test/test_shell_heredoc_reader.py through deny_gate.is_denied, prove.py PROVEN on this head, and a mutant per mechanism failing its rows. Known gaps allowed on main too are listed under Not a goal and tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593.
  • No regression:
    • Tools still work (which tools/commands were run, result): is_denied probed locally on refusal and allow shapes; a 1,180-level nested heredoc at the size cap is refused in about 0.4 s.
    • Backward compatible (old config / old data / old callers still work, how checked): heredocs defaults to False and ShellCommand.heredocs to (); test_shell_commands_reader.py parity and test_argv_rules.py pass; no config or data format change.
    • Existing tests (which suites passed on this head): 1678 passed across test_shell_heredoc_reader, test_shell_commands_reader, test_argv_rules, test_argv_floor_inline_and_brace_scope, test_denied_commands_security_rows/_quoting, test_denied_commands_security, test_security_bash_gate, test_trust_reads, test_security_gate_liveness.
  • How to undo: revert this single commit; nothing to migrate.

@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 Nov 6, 2026
@iamwhatever
iamwhatever force-pushed the crew/issue-triage/KiroCrew-22756 branch from b90e7a1 to 886abe8 Compare November 6, 2026 06:25
@iamwhatever

Copy link
Copy Markdown
Contributor Author

self-added: yes
mechanism: which heredoc body a shell reads as its script
resolution: narrowed

  • Heredoc bodies read as a script when no shell reads them (rm_floor.py:94, :213, :265) (span=e8aa6e56f6f9)

fixed in 886abe8: line continuations are folded only outside heredoc bodies; only a cat/tee producer forwards its heredoc down a pipe; --help/--version shells run nothing.
cat <<'EOF' with EO\\ + newline + F, printf ... <<'EOF' | bash and bash --help <<'EOF' with a wipe body are allowed again, as on main; a test row and a mutant each; earlier refused rows stay refused.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Nov 6, 2026
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 886abe8
  • What rule changed: three sensitive files. src/kiro_crew/security/shell_commands.py: read_commands(heredocs=True) reads past a live << and hands each body to its command (default read unchanged). src/kiro_crew/security/rm_floor.py: the recursive-force rm floor uses it to read heredoc bodies a shell runs, commands after a heredoc, and a \n in $'...', with a walk budget. src/kiro_crew/security/argv_rules.py: five wrappers (nsenter, unshare, flock, taskset, chrt) added to _WRAPPERS; this only adds refusals, because a command behind them is now read as the real program.
  • Before -> after (what was allowed/blocked, now): before, a root or home wipe in a heredoc fed to a shell (bash <<EOF, cat <<EOF | bash, behind a wrapper), in a substitution in an unquoted body, on a line after a heredoc, or behind \n in $'...' given to -c was allowed. Now each is refused. Heredocs given to non-shells, bash -c cat <<EOF, bash -s -c cat <<EOF, bash <<EOF </dev/null, bash <<A 3<<B, cat <<EOF | bash </dev/null, bash -n, printf ... <<EOF | bash, bash --help, backslash-newlines in quoted bodies, a continuation before the end word and a tag line that spells a wipe stay allowed. The chmod/chown argv rules see through the five new wrappers too, so they can only refuse more.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: a false refusal of a harmless heredoc command, or of a command nesting heredocs past _WALK_BUDGET_CHARS (16 x the 20 KiB scan cap), which fails closed with the floor's could-not-read note. No secret path is read or exposed.
  • Evidence checked (which sandbox result proves it): no sandbox change; these gates run before the sandbox. Evidence is test/test_shell_heredoc_reader.py through deny_gate.is_denied, prove.py PROVEN on this head, and a mutant per mechanism failing its rows. Known gaps allowed on main too are listed under Not a goal and tracked in rm floor: su feeding a heredoc to a shell is not read (su -s <shell> <user>, plain su <user>) #30593.
  • No regression:
    • Tools still work (which tools/commands were run, result): is_denied probed locally on refusal and allow shapes; a 1,180-level nested heredoc at the size cap is refused in about 0.4 s.
    • Backward compatible (old config / old data / old callers still work, how checked): heredocs defaults to False and ShellCommand.heredocs to (); test_shell_commands_reader.py parity and test_argv_rules.py pass; no config or data format change.
    • Existing tests (which suites passed on this head): 1681 passed across test_shell_heredoc_reader, test_shell_commands_reader, test_argv_rules, test_argv_floor_inline_and_brace_scope, test_denied_commands_security_rows/_quoting, test_denied_commands_security, test_security_bash_gate, test_trust_reads, test_security_gate_liveness.
  • How to undo: revert this single commit; nothing to migrate.

@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision and removed readiness: checking Automated validation is still running labels Nov 6, 2026
@kyleseaman
kyleseaman enabled auto-merge (squash) November 6, 2026 13:51
@kyleseaman
kyleseaman merged commit b4943da into main Nov 6, 2026
106 of 114 checks passed
@kyleseaman
kyleseaman deleted the crew/issue-triage/KiroCrew-22756 branch November 6, 2026 14:08
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 6, 2026
buluoray added a commit that referenced this pull request Nov 6, 2026
)

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.
buluoray added a commit that referenced this pull request Nov 8, 2026
… rm floor (#30600)

Original co-author: Zejiang Guo

(cherry picked from commit b4943da)
Original author: Joe Guo
buluoray added a commit that referenced this pull request Nov 8, 2026
… rm floor (#30600)

Original co-author: Zejiang Guo

(cherry picked from commit b4943da)
Original author: Joe Guo
buluoray added a commit that referenced this pull request Nov 8, 2026
… rm floor (#30600)

Original co-author: Zejiang Guo

(cherry picked from commit b4943da)
Original author: Joe Guo
buluoray added a commit that referenced this pull request Nov 8, 2026
… rm floor (#30600)

Original co-author: Zejiang Guo

(cherry picked from commit b4943da)
Original author: Joe Guo
buluoray added a commit that referenced this pull request Nov 8, 2026
… rm floor (#30600)

Original co-author: Zejiang Guo

(cherry picked from commit b4943da)
Original author: Joe Guo
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.

rm floor: nested-shell spellings still read wrong after #22719 (option after -c, comment backslash, heredoc into a shell)

2 participants