Repository navigation
fix(security): a redirect before the -c operand hides no payload, and the rm floor reads nested shells - #22719
Conversation
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: the change only adds refusals, it routes through the shared reader rather than adding a second parser, and a revert undoes it cleanly. Notes
[DESIGN-REVIEWED] 38577b8 Description read[DESCRIPTION-READ] c0ccfcd8caa6c8f167990968340d8cd6ddace4f06793576024b33a34638ff079 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 The rm floor's nested read is a third payload walk next to two that already exist. It differs from them in how it handles Notes
What this change shipsInventory (8 items) — 7 justifiedIntent: stop a recursive-force wipe of root or home from getting past the gates inside a nested shell or behind a redirect before
[FIRST-PRINCIPLES-REVIEWED] 38577b8 Description read[DESCRIPTION-READ] b4e500e0ef27b8ba9202080721445648664034e00f86805911c23b54228b6073 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 — ✅ no blocking findingsGPT 6.1 completed its review of This comment is updated in place on each push. Review detailsNo findings. 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 only adds refusals inside the shell deny composite: the rm floor now reads nested-shell payloads, payloads hidden behind a redirect are added to the deny views and the self-protection and git-publish floors, and the shared reader now treats TIGHTENING: The ADJUDICATED: 30 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: posix (22 rows): UNADJUDICATED: Narrowing to check, not a guard outside the classifier: [SCOPE-REVIEWED] 38577b8 |
8376d8e to
26e0757
Compare
|
|
|
|
26e0757 to
a0bca5b
Compare
|
a0bca5b to
8f7b800
Compare
|
|
|
Security Scope note (head Main already refuses the same command without the redirect. Bash removes the redirect before it runs the script, so both spellings run the same push, to a branch the gate cannot read from the text. Main refused the plain spelling and missed the redirect spelling; this PR makes them agree. No legitimate operation is newly narrowed, so there is no code change. A maintainer can override the Security Scope lane for this head if they agree. |
8f7b800 to
1ac968b
Compare
Sensitive change review
🤖 AI-assisted comment 🤖 |
|
Dependency License Gate on 🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
|
Holding this PR for a maintainer: head The regression (Opus 5.5 on
This is reachable: a cron Suggested fix (Opus): have Why we pause: this is the fifth review round on the same seam (the rm floor's nested read and the shared reader's operators). The retro and design are on #22756, and the remaining equal-to-main shapes are tracked in #25477. The PR is set to draft until a maintainer rules on the fix and the approach. 🤖 AI-assisted comment 🤖 |
|
Hold lifted. The PR is ready for review again on head What changed: the Opus finding on Test: Other updates: the rm floor paragraph in Gates: scoped security tests 427 passed; black, flake8, mypy, comment-history and docs-lint clean; 🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
|
Rebased: conflict with main in 🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 Sensitive change review
🤖 AI-assisted comment 🤖 |
|
self-added: yes
This replaces #22719 (comment), whose marker was malformed; the reasoning is unchanged. 🤖 AI-assisted comment 🤖 |
|
self-added: no
Issue: #25477 (the row list is in #25477 (comment)). This replaces #22719 (comment), whose marker was malformed; the reasoning is unchanged. 🤖 AI-assisted comment 🤖 |
|
self-added: yes
This replaces #22719 (comment), whose marker was malformed; the reasoning is unchanged. 🤖 AI-assisted comment 🤖 |
|
self-added: no
🤖 AI-assisted comment 🤖 |
|
self-added: no
🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
|
Rebased: conflict with main in The conflict was the security package line budget only. Main's new note and its raise are kept; the budget is set to the measured 33,086 (main's tree measures 32,909, plus this PR's 177). No code change. Scoped tests: 434 passed; 🤖 AI-assisted comment 🤖 |
|
self-added: no
🤖 AI-assisted comment 🤖 |
|
The
🤖 AI-assisted comment 🤖 |
|
Rebased onto the #25947 and #25944 fixes for the main-only reds; CI re-running. New head 🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
… the rm floor reads nested shells
|
Rebased: PR was CONFLICTING with main; CI re-running. New head 🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
|
Review-ready on The 9 heredoc/flag shapes and the dash 🤖 AI-assisted comment 🤖 |
buluoray
left a comment
There was a problem hiding this comment.
🤖 Kiro Crew Auto-Pipeline [operator: buluoray]:
Approving at 38577b8.
What this fixes: on main, bash -c 'rm -fr ~' and busybox sh -c 'rm -fr /' passed the recursive-force rm floor, and a redirect placed before the -c operand (sh -c 2>/dev/null '<script>') hid the script from every gate that reads nested payloads. Both now read through the shared quote-aware command reader instead of a new parser or a new regex row, and nothing in the sandbox scope changes.
Checked:
- CI on this head is green (84 pass, 14 skipping) and the branch merges cleanly into current main.
- The spec in
docs/system-specs/modules/security.mdchanges in the same diff. - Ran the three touched test modules locally: 359 passed.
- Mutation: switching
deny_gate.pyback to the top-level-only_rm_wipe_targetsfails 59 tests, includingtest_a_nested_wipe_is_refused_by_the_floor[bash -c 'RM -fr /']. - Mutation: dropping the redirect-hidden payloads from
shell_normalizer._shell_payload_walkfails 11 tests, includingtest_a_redirect_hides_no_publish_from_the_git_floor[env -S 2>/dev/null 'bash -c "{}"']. - Compared main and this head on everyday commands (
bash -c 'make test' 2>&1 | tee log,sh -c "cd /tmp && rm -rf build", agit commit -morgh pr comment --bodythat quotesbash -c 'rm -fr ~',ls &>/dev/null && echo ok,sh -c 'rm -rf "$HOME/.cache"'): all still allowed. Only the nested root or home wipes changed to refused.
Follow-ups, not blocking:
- The per-line argv reader in
rm_floor.pyreads each line up to eight ways. I did not measure walk time myself; the body's measurement is the evidence for it. _shell_payload_walkimportsshell_commandsinside its loop to dodge the import cycle;_submodule("shell_commands"), asdeny_gate.pydoes, would match the existing pattern.
Problem / Motivation
Goal: A recursive-force wipe of root or home is refused when it is wrapped in a nested shell, and a redirect placed before a
-coperand no longer hides that operand from any gate.On main, two gaps let a nested-shell command through:
-coperand hid the payload from every gate. The shared_nested_shell_payloadstook the redirect word itself as the-cscript, so every gate that reads nested payloads (the self-protection floors, the deny views, the rm floor) looked at the redirect instead of the script bash runs.deny_gateran_rm_wipe_targetson the top-level text only, sobash -c 'rm -fr /'andbusybox sh -c 'rm -fr /'were allowed (the two catalog rows match-rfonly).Why it matters
The rm floor exists to catch common respellings of
rm -rf /andrm -rf ~; wrapping the command inbash -cwas a one-step way around it. The redirect gap was wider: it reached every gate that relies on the shared nested-payload extractor.Not a goal
rm_floor.py(the paused fix(security): rm floor reads a nested shell's -c operand as bash does #22390 approach).evalstacks: a known open gap, the same as on main. Eachevalre-joins its words, and reading that exactly costs O(N) per level; the floor skipseval/source/.arguments, left to a follow-up.HOME=rebinding,envwrappers, heredoc bodies, or backticks /$\+newline+(inside double quotes._shell_payload_walkand_segmentsinrm_floor.py, which fix(security): delimit a quoted $( body from a fresh quote context #20851 edits.-c, a comment ending in a glued backslash, a heredoc fed to a shell, a decoded newline inside$'...'. Tracked in rm floor: nested-shell spellings still read wrong after #22719 (option after -c, comment backslash, heredoc into a shell) #22756.echo "$(bash -c 'rm -fr ~')"is allowed, as on main (d5b8c2099c). The shared_matching_close_parencannot prove where a$(opened inside"..."ends, and the floor reads only proven spans. Known limit, tracked in rm floor does not read a command substitution inside double quotes #23694.What changed (motivation → approach → change)
Both fixes read commands through the shared quote-aware reader,
shell_commands.read_commands(#25175). It knows where a command ends at a live separator, even one glued to a word, and which words are redirections.shell_commands.pyredirect_free_views(text): each command holding a live redirection, rendered without it, read for every frame holding a<or>, so a quoted or escaped carrier flag (bash "-c",bash -\c) hides nothing.read_commandsreads&>,&>>and `>shell_normalizer._shell_payload_walkdeny_gatedeny viewsecho/catexemption still applies.rm_floor._rm_wipe_targets_nested(called fromdeny_gate)_nested_shell_payloads. A payload is skipped when it is aneval/source/.argument, or when the shared data-consumer exemption marks it inert in its own command. At a live<<, the stopped command runs to the line's end (a herestring is a payload) and the rest of the line is read too; only the heredoc body is data.A redirect view ends at its command's separator, so a later command's words are never read as the script:
bash -c 2>/dev/null 'make lint' && git commit -m '...'is allowed again. Each command is read on its own, so a glued&&/&no longer lets anechoexemption cover the next command.Each payload is read as yielded and
\$-unescaped (fail closed: a single-quotedbash -c 'rm -fr \$HOME'is over-refused). A single-quoted$HOMEinside a double-quoted payload is not read, as on main (#25385).docs/system-specs/modules/security.mdcovers the reader helpers and the rm floor's nested read.test/test_security_gate_liveness.py: package line budget 32,793 → 32,930 (measured).Before / after
bash -c 'rm -fr ~'bash -c 2>/dev/null 'rm -fr ~'bash -c 2>$(printf /dev/null) 'rm -fr ~'bash -c &>/dev/null 'rm -fr ~'env -S 2>/dev/null '<protected-branch publish>'echo x&&bash -c 'rm -fr /'true&>x rm -r -f ~(dash runs the rm)echo $( bash -c 'rm -fr ~' )echo '<home wipe>' | shecho '<home wipe>' | tee x; sh run.shgit log --oneline | head -3bash -c 'rm -fr \<newline>~'bash -c 2>/dev/null 'make lint' && git commit -m 'git push origin main'echo "$(date)" bash -c 'rm -fr ~'echo bash -c 'rm -fr ~'bash -c 'rm -fr /tmp/x'Backwards compatibility
Compatible: the change only adds refusals for wipes of root or home itself, and for payloads a redirect used to hide. Redirect-hidden payloads are added beside the frame's own; the original text is still walked, so no gate sees less than on main. Walk time on deep nesting stays at main's level (measured below).
Removes nothing: no rule, pattern, key or function is removed.
Tests
test/test_denied_commands_security_rows.py::TestRmFloorReadsNestedShellPayloads:component=argv-floor):bash -c,busybox sh -c,$"..."forms, redirect shapes before or glued to the operand (a target spanning words or a substitution, a quoted(or;target, two redirects, a target namedeval/source),env -S, glued herestring and-c'...'decoys, comments, a newline afterecho, substitution bodies, a heredoc marker's own line, line continuations, single-quoted$HOMEinside a double-quoted payload, and glued&&/&/||/|before a nested wipe.bash -c 'rm -fr /tmp/x',echo bash -c '...',echo "$(date)" bash -c '...',bash -c 2>/dev/null 'ls', heredoc bodies, andrm -rf /tmp/xstays refused by its row as on main.evalarguments are not walked: a 1,200-deepevalstack reads one frame.Proof: PROVEN test/test_denied_commands_security_rows.py::TestRmFloorReadsNestedShellPayloads::test_a_nested_wipe_is_refused_by_the_floor[bash -c 'RM -fr /'], test/test_denied_commands_security_rows.py::TestRmFloorReadsNestedShellPayloads::test_a_nested_wipe_is_refused_by_the_floor[busybox sh -c 'RM -fr /'], test/test_denied_commands_security_rows.py::TestRmFloorReadsNestedShellPayloads::test_a_nested_wipe_is_refused_by_the_floor[bash -c $" RM -fr
"], test/test_denied_commands_security_rows.py::TestRmFloorReadsNestedShellPayloads::test_a_nested_wipe_is_refused_by_the_floor[bash -c "RM -fr "$""], test/test_denied_commands_security_rows.py::TestRmFloorReadsNestedShellPayloads::test_a_nested_wipe_is_refused_by_the_floor[bash -c 'cd x && RM -fr ~'] (head 49c6590)Scoped tests: 434 passed on
49c6590050.Cost through
is_denied(best of 5 x 300 calls, under one host lock):git log --oneline -5 2>/dev/null | head -3 > /tmp/out.txtbash -c 'make lint' 2>&1 | tee build.logcd src && python -m pytest … > /tmp/t.log 2>&1; tail -5 /tmp/t.log'echo "$(' * 300nesting (one call)echo >xat every nesting levelbash -c >xat every nesting level"rm x " + "<<a " * 5000(one call)Every new refuse row is allowed on main (probed through
is_denied); the glued&&rows are allowed and the commit-message row refused on the prior headdd699a4adb.Targeted: every test file that imports the shell normalizer, the reader, the rm floor,
is_deniedor the argv floors: 9,620 passed, 21 skipped.Manual verification
N/A — unit coverage sufficient: the change is a pure function of the command text, probed through
is_denied.Related Issues
Part of #19473
Sibling sweep
Swept: git grep -n "_nested_shell_payloads(" -- src/
Sibling: src/kiro_crew/security/shell_normalizer.py -- changed here
Sibling: src/kiro_crew/security/deny_gate.py -- changed here
Sibling: src/kiro_crew/security/argv_floor_git.py -- not affected -- its defer check waits for frames
_shell_payload_walkalready judgesPattern harvest
Rule candidate: review-prompt
Pattern: an argv walker that picks "the next word" after a flag must skip shell redirections, which bash removes from argv wherever they sit.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)