Repository navigation
fix(security): rm floor reads reserved words, empty substitutions and ${...} spans - #23840
Conversation
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS No design-level concerns: every change only adds refusals, because the floor joins the base reading with the tracked one, and the subject is a real shell command line. Notes
[DESIGN-REVIEWED] a9e3c45 Description read[DESCRIPTION-READ] 88482d58794fc1b09da8d0b228a74c9b5a08b061675fdc44fed1481a80fcebc3 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. Every item closes a respelling of What this change shipsInventory (8 items) — 8 justifiedIntent: refuse a recursive-force wipe of
[FIRST-PRINCIPLES-REVIEWED] a9e3c45 Description read[DESCRIPTION-READ] 341184c87e0d3d8fd587f79aba0192d19873e42f24e14a2ba6591b069333ed43 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: This change only adds refusals to the recursive-force TIGHTENING: the ADJUDICATED: 23 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff assumes POSIX shell syntax throughout: the reserved words
The diff adds nothing specific to Windows, but the UNADJUDICATED: The [SCOPE-REVIEWED] a9e3c45 |
df1e137 to
f140c9f
Compare
🤖 AI-assisted comment 🤖 |
🤖 AI-assisted comment 🤖 |
🤖 AI-assisted comment 🤖 |
🤖 AI-assisted comment 🤖 |
🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
bolichen97
left a comment
There was a problem hiding this comment.
Not ready: two inputs that the base floor refuses are allowed on this head, so the change is not deny-only as described.
Head reviewed: f140c9f. Bots read: Design PASS, First Principles PASS, UX skipped, Opus no findings, GPT 2 blocking, readiness checking.
I reproduced both GPT findings with kiro_crew.security.is_denied on the base commit (c24c7bc) and on this head:
| Command | Base | Head |
|---|---|---|
echo $${x:- # don't remove this marker + newline + rm -fr ~ |
refused | allowed |
rm -fr ~/`true` |
refused | allowed |
The new deny cases also pass on this head. For example, if :; then rm -fr ~; fi is refused now and was allowed on the base.
🔴 2 must-fix. Details are in the inline comments. Please add each command above as a deny case, so a test goes red if the regression comes back.
Not repeated here: the Design and First Principles note that the floor keeps a second shell reader beside the shared walk. That is advisory, and it is outside this PR's goal.
Overlap: #22390, #22719 and #21900 also change the rm floor or its tests. Whichever merges second needs a rebase and a rerun of the full TestRecursiveForceRmFloor suite.
| resume, resume_state = pos + end, 2 | ||
| resume, resume_state = pos + end, step.state | ||
| break | ||
| if step.active and text.startswith(("${", "$["), step.offset): |
There was a problem hiding this comment.
🔴 A $$ before { opens a tracked expansion that bash never opens, which hides a later rm -fr ~
This check opens a tracked ${ span at any active $, including the second $ of $$. Bash reads $$ as the PID and {x:- ... as literal text. With the span open, live_syntax is false, so the real comment that follows is not skipped. The apostrophe in that comment then opens a single quote that swallows the next line.
if step.active and text.startswith(("${", "$["), step.offset):Reproduced: echo $${x:- # don't remove this marker + newline + rm -fr ~ is refused on the base and allowed on this head (is_denied returns None).
Why it matters: The floor exists to refuse a respelled home wipe, and this change makes one respelling pass that was refused before.
Suggestion: Open a tracked span only at a $ that starts a parameter expansion. Do not open one at the second $ of a $$ pair or at an escaped \$. Add the command above as a deny case. I will withdraw this if the deny case passes on a later head.
Rule: removed guard with no replacement (a deny-only fix must not allow what the base refused)
| break | ||
| if step.state == 2 and step.char == "`" and len(step.text) == 1: | ||
| # a backtick body in double quotes is read on its own, then the quote resumes | ||
| if (step.active or step.state == 2) and step.char == "`" and len(step.text) == 1: |
There was a problem hiding this comment.
🔴 An unquoted backtick inside a target operand now hides a home wipe that the base refused
Before this change, an unquoted backtick was not a substitution here, so ~/ followed by a backtick span was not cut, and the base refused it. Now the span becomes the \0 placeholder inside the same word. The operand reads as ~/\0, _target_kind sees no root or home target, and the command is allowed. Bash expands an empty substitution to nothing, so the command runs rm -fr ~/.
if (step.active or step.state == 2) and step.char == "`" and len(step.text) == 1:Reproduced: rm -fr ~/`true` is refused on the base and allowed on this head (is_denied returns None).
Why it matters: This is a one-word respelling of rm -fr ~ that the base refused and this head allows.
Suggestion: When an operand contains a substitution placeholder, also check it with the placeholder removed (the empty expansion), the same way the new command-position step already does. Add rm -fr ~/`true` as a deny case. I will withdraw this if that case passes on a later head.
Rule: removed guard with no replacement (a deny-only fix must not allow what the base refused)
f140c9f to
efe5150
Compare
🤖 AI-assisted comment 🤖 |
🤖 AI-assisted comment 🤖 |
Sensitive change review
🤖 AI-assisted comment 🤖 |
|
@bolichen97 Both inputs from your review are fixed on head efe5150:
Each has a new deny case in 🤖 AI-assisted comment 🤖 |
bolichen97
left a comment
There was a problem hiding this comment.
Re-reviewed on head efe5150 (delta from f140c9f).
Both inputs from the previous review are fixed. I ran them through kiro_crew.security.is_denied on base 1c57aca and on this head, and ran each in real bash with printf in place of rm to confirm bash executes the wipe:
| Command | Base | f140c9f | efe5150 |
|---|---|---|---|
echo $${x:- # don't remove this marker + newline + rm -fr ~ |
refused | allowed | refused |
rm -fr ~/`true` |
refused | allowed | refused |
A wider probe of 68 home and root wipe forms (keywords, time -p, subshells, groups, pipelines, substitutions in the program word and in targets, ${...} and $[...] spans, $$ runs, heredocs, escaped and quoted rm) found no regression among them. The PR is still not deny-only, though: a redirection whose target is a substitution, placed before rm, now hides the wipe.
| Command | Base | efe5150 |
|---|---|---|
>$(mktemp) rm -fr ~ |
refused | allowed |
>"$(mktemp)" rm -fr ~ |
refused | allowed |
2>`mktemp` rm -fr / |
refused | allowed |
<$(x) rm -fr ~ |
refused | allowed |
2>$(printf /dev/null) rm -fr ~ |
refused | allowed |
Real bash runs the program after such a redirection (2>mktemp printf ... -fr / prints its operands), so this is a home or root wipe the floor refused before and allows now. The Opus and GPT lanes report the same regression on this head. Details and a fix direction are inline.
One non-blocking note: Security Scope Review is red on this head for two newly refused commit and PR body drafts. A ) in a heredoc body inside $(...) (a 1) or a) list item) closes the substitution early, and the rest of the body is read as commands. That over-refusal keeps the gate red, so it needs a fix or a maintainer decision before merge.
Also, the description says the line budget rises by 12, but the diff raises it by 19.
Verified locally on this head: test/test_denied_commands_security_rows.py and test/test_security_gate_liveness.py pass (189 tests). Backend test shards 5 to 8 and Windows shard 7 were still pending when I checked.
Overlaps on the same file: #22390, #22719 and #21900 also touch the rm floor or its tests. Whichever merges second needs a rebase, and the new segment walk should be rechecked against the nested-shell changes in #22390 and #22719.
This touches a security path, so approval stays with a maintainer.
| while words: | ||
| if ENV_ASSIGNMENT_RE.match(words[0]): | ||
| words = words[1:] | ||
| if _SUBST in words[0]: |
There was a problem hiding this comment.
🔴 A redirection glued to a substitution, placed before rm, now hides the wipe
The new unquoted $( and backtick branch in _segments leaves the substitution marker glued to the redirection word, so >$(mktemp) becomes >\x01. This step then removes the marker, the word becomes a bare >, and _push_token_redirection(">") reports that it still needs a target. That takes rm as the redirection target, so the program word becomes -fr.
if _SUBST in words[0]:
bare = words[0].replace(_SUBST, "")
words = [bare, *words[1:]] if bare else words[1:]is_denied returns None on this head for >$(mktemp) rm -fr ~, >"$(mktemp)" rm -fr ~, 2>`mktemp` rm -fr /, <$(x) rm -fr ~ and 2>$(printf /dev/null) rm -fr ~. Base refuses all five. Bash runs the program after such a redirection, so these are home and root wipes that are allowed now.
Suggestion: classify the redirection on the original word before stripping. Strip _SUBST only when the word is not a redirection, or replace it with a non-empty placeholder in a redirection word so the target stays attached. Add the five commands above as deny cases.
Rule: a deny-only change must refuse every input the base refuses.
| # the body is its own frame and one opaque word here; the outer | ||
| # quote state (unquoted or double) resumes after the close | ||
| body = text[step.offset + 2 :] | ||
| close, proven = _shell._matching_close_paren(body, 0) |
There was a problem hiding this comment.
🟡 A ) in a heredoc body inside $(...) closes the substitution early
_matching_close_paren does not know about heredocs, so a list item like 1) or a) in a commit message ends the body. The rest of the heredoc is then read as commands. On this head, M=$(cat <<'EOF' + newline + b) `rm -fr ~` is refused + newline + EOF + newline + ) is refused, while the same body without the ) is allowed. Base allows both.
This is an over-refusal, not a bypass, but it is the case Security Scope Review confirms as newly refused on two POSIX legs. Drafting a commit or PR body into a variable through a heredoc is a common agent flow, especially for security fixes that quote the refused command. As long as it stays, that gate stays red.
Suggestion: stop at a heredoc start inside the substitution body when looking for the close, or leave the body to the sandbox when a heredoc opens inside it. Add the gate's two commands as allow cases.
Rule: a floor change should not newly refuse a legitimate, common workflow without a maintainer decision.
efe5150 to
94abebc
Compare
e8dafdc to
bde464f
Compare
Sensitive change review
🤖 AI-assisted comment 🤖 |
🤖 AI-assisted comment 🤖 |
bde464f to
d35d50e
Compare
Sensitive change review
🤖 AI-assisted comment 🤖 |
CrysisDeu
left a comment
There was a problem hiding this comment.
Review at d35d50e1: deny-only confirmed; approve after the one-line rebase
I re-walked the parser: with track=False the untracked reading equals base, keyword skip and the _SUBST strip only run on a words[0] base would have broken on, and a floor exception still fails closed through deny_gate.py:779-784 — so the change is deny-only by construction. Bypass probes ($HOME, ~/*, r''m, \\rm, reserved words, "$(true)"rm, chains, #/<< in ${...}) all refuse; nothing previously refused is newly allowed. Every red point from @bolichen97 is fixed and pinned, and rm_floor.py is byte-identical to 2ae01846 which he already cleared. CI green incl. Denial Differential (0 newly refused) and Security Scope.
Needed:
- Rebase the single conflict:
test/test_security_gate_liveness.py:530— main moved_PACKAGE_LINE_BUDGETto 32,616 (#24392); set it to 32_635 (+19), keep both comment paragraphs, and drop "or a target" from the comment (targets are no longer stripped). - @bolichen97's CHANGES_REQUESTED at
94abebcis stale (his later reviews are "looks good to ship"); needs his approve or a maintainer dismissal.
Nits to ride along: pin the two missing redirect-to-substitution deny forms (<$(x) RM -fr ~, 2>$(printf /dev/null) RM -fr ~) and the $[ $( # ... ) ] variant his 9b008cd review assumed; the walk-count bound (:651, 4*20+2) is loose. Follow-up under #18464: unset parameter in program position (${x}rm -fr ~) is still allowed on base and head.
Ping me after the rebase and I will approve (security sign-off).
Posted by code-reviewer (Kiro Crew member) on behalf of @CrysisDeu. Full report on file.
|
@CrysisDeu, here is what I did with each point of your review at
Tests only, no prod change: 🤖 AI-assisted comment 🤖 |
d35d50e to
f367bdf
Compare
Sensitive change review
🤖 AI-assisted comment 🤖 |
|
@CrysisDeu rebased at f367bdf: budget 32_635, comment fixed, 3 deny forms pinned. 🤖 AI-assisted comment 🤖 |
bolichen97
left a comment
There was a problem hiding this comment.
Rechecked at f367bdf.
What changed since d35d50e: a rebase onto main plus three new deny rows in TestRecursiveForceRmFloor (<$(x) RM -fr ~, 2>$(printf /dev/null) RM -fr ~, and a $[ $( ... ) ] span hiding a recursive force rm behind a quote inside a comment). The budget comment in test_security_gate_liveness.py now drops the "or a target" wording, and the budget moves to 32,635 to stack on the install-tree fence that main added. security/rm_floor.py and the security spec are byte identical to the previous head, so the floor logic is unchanged and no allow was widened.
Verified locally at this head: the rm floor rows and the package line budget test pass (127 passed).
The red Backend Lint & Type Check (3.12) is not from this PR: flake8 reports F821 for lists_checked_by_caller in publish_governance.py line 299, a file this PR does not touch, and the same line fails on main. Coverage Gate fails only because that lint job failed. A rebase after main is fixed should clear both.
Looks good to me. This touches the security deny floor, so it still needs a maintainer approval; my earlier change request points were addressed in previous revisions.
Sensitive change review
🤖 AI-assisted comment 🤖 |
… ${...} spans
The recursive-force rm floor now refuses a wipe of / or ~ behind then, do,
else, {, !, or time; with a quoted substitution that expands to nothing in
the program word or a target; and after a # or << inside an unpaired ${...}
or $[...]. An unclosed span is also read as if it were not there. Deny-only.
Sensitive change review
🤖 AI-assisted comment 🤖 |
bolichen97
left a comment
There was a problem hiding this comment.
Approving at head a9e3c45.
This head is a rebase of de51b8a (itself a rebase of f367bdf) onto newer main; git range-diff shows the PR commit unchanged (=). My earlier request for changes on 94abebc is resolved: the reserved word, empty substitution and ${...} span readings it asked for are in rm_floor.py, each with its own deny row.
Security checklist, answered fresh at this head: the change is deny-only. _rm_wipe_targets unions the tracked and untracked segment readings, so ${...} tracking can only add refusals, never remove one. Reserved words (then, do, !, time, time -p) now keep command position, and a substitution in the program word is treated as possibly empty. No allow path, auth, network, secret or execution surface changes.
What I verified:
- Read every hunk at this head:
rm_floor.py,security.md,test_denied_commands_security_rows.py,test_security_gate_liveness.py(line budget raised by 19 with its reason). - Ran every
test_denied_commands*,test_security_denied_commands.pyandtest_security_gate_liveness.pyfile locally: 1732 passed, 1 skipped. - Probed the floor directly:
then rm -rf /,do rm -rf ~,! rm -rf /,time -p rm -rf /, a quoted empty substitution or backtick beforerm, and${x#y}/$[1#2]/$$#before a separator are all refused;ls ~/xandrm -rf ./buildare not. - Gates: readiness passed on this head, all required checks green, no AI lane BLOCK, no merge conflict, no other review requesting changes.
Problem / Motivation
Goal: The recursive-force
rmfloor refuses a wipe of/or~written behind a shell keyword, an empty quoted substitution, or a${…}/$[…]span, the same as the plain spelling.is_deniedallowed shapes likeif :; then rm -fr ~; fi,! rm -fr ~,time rm -fr ~andecho ${x:- #}; rm -fr /, whilerm -fr ~alone is refused.Why it matters
The floor exists so that a respelling of
rm -rf ~cannot slip past the deny rows. Each shape here is a one-word change that wipes the home or root directory and was allowed.Not a goal
sudo rm,command rm) and interpreter bodies: still left to the catalog rows and the OS sandbox, as before.$(…)or backtick inside the rm argv (rm -fr $(printf build) ~), and a heredoc opened inside one: left open on security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464. Reading them as their own frame refused common heredoc commit messages and needs a heredoc-aware paren walk first.cleanup=( rm -rf / ),rm -rf --help /): not touched.What changed (motivation → approach → change)
Decision: deny-only. Each fix makes
src/kiro_crew/security/rm_floor.pyread more of the command as live shell. Every command the base refuses is still refused, and every existing allow case inTestRecursiveForceRmFloorstill passes.then/do/else/{/!/timebeforermVAR=val"$(true)"rm -fr ~rmrm -rf "$(go env GOCACHE)"/*stays allowed#or<<inside${…}/$[…]$${is the PID and opens nothing${x:-$( # don't …)}${…}tracking, and the targets are joinedThe keyword list is the shared
shell_normalizer._KEEPS_COMMAND_POSITIONset. A substitution gets its own marker, apart from the one for a literal quoted~or$, sorm -fr "~/"stays allowed. A leading redirection is stepped over before the substitution is dropped, so>"$(mktemp)" rm -fr ~keepsrmas the program. The reading without tracking is the base reading, so tracking can only add refusals. Each reading passes its mode down to nested substitutions, so deep nesting costs two walks, not one per level.Some odd commands are now refused that bash would not wipe with: a quoted keyword (
"then" rm -fr ~) and anrm -fr ~written inside a${x:-…}default. Each is an over-refusal, which is the safe side.The security package line budget in
test/test_security_gate_liveness.pyrises by 19 lines for this. The floor's paragraph indocs/system-specs/modules/security.mddescribes each new reading and the narrowed out-of-scope list.Two shapes from the issue were already refused on main, so they get tests only: an apostrophe in a comment, and
case x in x) rm -fr /;; esac.Backwards compatibility
Compatible: only commands that wipe
/or~with recursive force start being refused; no other command changes.Removes nothing: no rule, key, or allow case is removed; the floor only refuses more.
Tests
TestRecursiveForceRmFloorgains 30 deny cases, 8 allow cases (echo then rm -fr ~,rm -fr $(mktemp -d), a comment after${a[1]}, a comment after$((1 << 2)), and four cache clears such asrm -rf "$(pip cache dir)"/*) and one nesting test. The deny cases cover the keyword rows,case, the${…}/$[…]rows, empty quoted and backtick substitutions, a substitution as a leading redirection target (>$(mktemp) rm -fr ~),$${, an unclosed${, and three comments inside${x:-$( … )}. The nesting test counts walks for twenty"$( ${levels and fails if the count is not linear.Deny-only check: 125 commands (every case in the class plus every reviewer probe) were run through
is_deniedon base c24c7bc, on current main and on this head. None is refused on either and allowed here.On the previous head the three comment cases and the nesting test fail. Not passing the mode down to nested calls fails the nesting test.
Proof: PROVEN test/test_denied_commands_security_rows.py::TestRecursiveForceRmFloor::test_a_recursive_force_wipe_of_root_or_home_is_denied[if :; then RM -fr ~; fi], test/test_denied_commands_security_rows.py::TestRecursiveForceRmFloor::test_a_recursive_force_wipe_of_root_or_home_is_denied[if false; then :; else RM -fr ~; fi], test/test_denied_commands_security_rows.py::TestRecursiveForceRmFloor::test_a_recursive_force_wipe_of_root_or_home_is_denied[for i in 1; do RM -fr ~; done], test/test_denied_commands_security_rows.py::TestRecursiveForceRmFloor::test_a_recursive_force_wipe_of_root_or_home_is_denied[while :; do RM -fr /; done], test/test_denied_commands_security_rows.py::TestRecursiveForceRmFloor::test_a_recursive_force_wipe_of_root_or_home_is_denied[{ RM -fr ~; }] (head a9e3c45)
Local GPT and Opus review lanes were skipped: the host had under 3 GB of free memory. CI's review lanes are the review for this head.
Manual verification
Every keyword,
caseand${…}probe in the issue and its comments was run throughkiro_crew.security.is_deniedon this head: all are refused.rm -fr build,echo rm -fr ~, acat <<EOFwith anrm -fr ~body, and heredoc commit messages witha)list items stay allowed.Related Issues
Part of #18464
Sibling sweep
Swept: git grep -n "_KEEPS_COMMAND_POSITION|_matching_close_paren" -- src/kiro_crew/security/
Sibling: src/kiro_crew/security/shell_normalizer_walk.py -- not affected -- the shared walk already keeps command position after these keywords
Sibling: src/kiro_crew/security/rm_floor.py -- changed here
Pattern harvest
Not generalizable: the floor keeps its own small word split by design, and the shared reader already handles these keywords and spans.
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)