Skip to content

fix(security): rm floor reads reserved words, empty substitutions and ${...} spans - #23840

Merged
bolichen97 merged 1 commit into
mainfrom
fix/rm-floor-keyword-shapes
Oct 27, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/rm-floor-keyword-shapes

Conversation

@iamwhatever

@iamwhatever iamwhatever commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: The recursive-force rm floor refuses a wipe of / or ~ written behind a shell keyword, an empty quoted substitution, or a ${…} / $[…] span, the same as the plain spelling.

is_denied allowed shapes like if :; then rm -fr ~; fi, ! rm -fr ~, time rm -fr ~ and echo ${x:- #}; rm -fr /, while rm -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

  • Exec wrappers (sudo rm, command rm) and interpreter bodies: still left to the catalog rows and the OS sandbox, as before.
  • Reading heredoc bodies as commands: a heredoc body stays data.
  • An unquoted $(…) 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.
  • Narrowing the catalog row's over-refusals (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.py read more of the command as live shell. Every command the base refuses is still refused, and every existing allow case in TestRecursiveForceRmFloor still passes.

Shape Before After
then / do / else / { / ! / time before rm the keyword was read as the program the keyword is stepped over, like VAR=val
"$(true)"rm -fr ~ the quoted substitution hid rm refused: a substitution in the program word may expand to nothing, so it is dropped there. In a target it stays a real path, so rm -rf "$(go env GOCACHE)"/* stays allowed
# or << inside ${…} / $[…] read as a comment or heredoc, so the rest was skipped read as data until the expansion closes; $${ is the PID and opens nothing
a comment inside ${x:-$( # don't …)} refused still refused: every command is read with and without ${…} tracking, and the targets are joined

The keyword list is the shared shell_normalizer._KEEPS_COMMAND_POSITION set. A substitution gets its own marker, apart from the one for a literal quoted ~ or $, so rm -fr "~/" stays allowed. A leading redirection is stepped over before the substitution is dropped, so >"$(mktemp)" rm -fr ~ keeps rm as 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 an rm -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.py rises by 19 lines for this. The floor's paragraph in docs/system-specs/modules/security.md describes 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

TestRecursiveForceRmFloor gains 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 as rm -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_denied on 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, case and ${…} probe in the issue and its comments was run through kiro_crew.security.is_denied on this head: all are refused. rm -fr build, echo rm -fr ~, a cat <<EOF with an rm -fr ~ body, and heredoc commit messages with a) 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

  • 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

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/rm_floor.py

  • @iamwhatever posted a complete reasoning template for a9e3c45.

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

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision a9e3c4515259aee3ca6ca1d1e51794767711a36d 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 Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

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 .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 Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of a9e3c4515259aee3ca6ca1d1e51794767711a36d — 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. Every item closes a respelling of rm -fr ~ or / from #18464, reuses _KEEPS_COMMAND_POSITION and _matching_close_paren, and only adds refusals.

What this change ships

Inventory (8 items) — 8 justified

Intent: refuse a recursive-force wipe of / or ~ written behind a shell keyword, an empty substitution, or a ${…} / $[…] span, the same as the plain rm -fr ~. This is a FIX.

  1. then / do / else / { / ! / time [-p] before rm are now refused — justified
  2. A substitution glued to or before rm in the program word ("$(true)"rm -fr ~) is now refused, and a substitution inside a target path still stays allowed — justified
  3. # or << inside ${…} / $[…] no longer hides the rest of the command, and $${ opens nothing — justified
  4. Each command is read with and without the span tracking and the targets are joined, so tracking cannot allow anything the base reading refused — justified
  5. The tracking mode is passed down to nested substitutions, so the number of walks grows linearly with nesting depth — justified
  6. New over-refusals ("then" rm -fr ~, an rm -fr ~ inside a ${x:-…} default), stated in the description — justified
  7. The security package line budget rises by 19 lines — justified
  8. The floor's spec paragraph now describes the new readings and the narrowed out-of-scope list — justified

[FIRST-PRINCIPLES-REVIEWED] a9e3c45

Description read

[DESCRIPTION-READ] 341184c87e0d3d8fd587f79aba0192d19873e42f24e14a2ba6591b069333ed43

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 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] a9e3c45

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

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

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of a9e3c4515259aee3ca6ca1d1e51794767711a36d and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] a9e3c45

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

@github-actions

github-actions Bot commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

Which legitimate operations does a9e3c4515259aee3ca6ca1d1e51794767711a36d 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): 19 classified, 0 newly refused, 15 still allowed.
  • ubuntu-latest (platform posix): 19 classified, 0 newly refused, 15 still allowed.
  • windows-latest (platform windows): 4 classified, 0 newly refused, 2 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: This change only adds refusals to the recursive-force rm floor, and the floor still requires rm as the program, recursive plus force flags, and an operand that is exactly root or home. Of the 23 candidates written, the harness confirmed none as newly refused. Windows coverage is limited to probing POSIX-tokenizer handling of PowerShell and cmd spellings.

TIGHTENING: the rm floor's segment walk in src/kiro_crew/security/rm_floor.py -- it refuses a root/home rm -fr that was hidden behind a reserved word, a substitution in the program word, or a # / << inside an open ${…} / $[…]. The hunks are: if ENV_ASSIGNMENT_RE.match(words[0]) or words[0] in _shell._KEEPS_COMMAND_POSITION:, if _SUBST in words[0]: # a substitution in command position may expand to nothing, and if track and dollars % 2 and text.startswith(("${", "$["), step.offset): expansion.append(...). All three are joined through for segment in [*_segments(command), *_segments(command, track=False)].

ADJUDICATED: 23 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: The diff assumes POSIX shell syntax throughout: the reserved words then/do/elif/until/!/{/time -p, $(…) and backtick substitution, and ${…}/$[…] with $$ as the PID.

  • posix (19 rows): each newly-skipped keyword in front of a descendant rm -rf; a substitution in the program word ($(command -v rm), "$(git rev-parse …)"/scripts/clean.sh, $(npm bin)/rimraf); ${…} operands with nested defaults (${XDG_CACHE_HOME:-$HOME/.cache}, ${TMPDIR:-/tmp}); closed ${#…} and ${PATH//…} spans followed by comments that mention rm -rf ~; a heredoc whose body has ${VERSION}; and the home descendant ~/.cache/pip.
  • windows (4 rows): Git Bash /c/Users/..., PowerShell ${env:TEMP} (a ${ the new tracking now reads as an open expansion), PowerShell Remove-Item with a trailing # comment and \ paths, and cmd.exe %TEMP%.
  • any (0 rows): every row carries a path or executable name.

The diff adds nothing specific to Windows, but the ${ tracking now applies to PowerShell's ${env:…} braces too, which those windows rows probe. PowerShell's backtick escape character and <#…#> block comments are not probed: the floor reads every command with POSIX quoting, and I found no legitimate operation in this area that uses them next to an rm alias.

UNADJUDICATED: The ${…}/$[…] tracking flags text as live code that the base treated as a comment or heredoc, but only when a span is unclosed or misread. The over-refusal the spec itself names, an rm -fr ~ written as literal text inside a ${x:-…} default, is accepted by the spec as contrived. I submitted no row for it because I could not attribute it to a real operation.

[SCOPE-REVIEWED] a9e3c45

@iamwhatever
iamwhatever force-pushed the fix/rm-floor-keyword-shapes branch from df1e137 to f140c9f Compare October 24, 2026 21:37
@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Empty substitution glued before the program word hides the wipe (span=f6adfbd55f89)

fixed in f140c9f: a leading placeholder from a substitution is stripped from the program word, and a word that was only a substitution is dropped, so $(true)rm -fr ~, $(true) rm -fr ~ and echo hi | \true`rm -fr /` are refused again.
Tests: four new deny cases in TestRecursiveForceRmFloor; removing the step fails all four.
self-added: yes
mechanism: substitution placeholder in the rm floor's segment walk

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Empty substitutions hide a previously denied home wipe (span=e8aa6e56f6f9)

fixed in f140c9f: a substitution in command position may expand to nothing, so its placeholder is stripped from the program word (or the word dropped); $(true) rm -fr ~ and `true` rm -fr ~ are refused again.
Placeholders inside argv and quoted words are unchanged. Tests: four new deny cases.
self-added: yes
mechanism: substitution placeholder in the rm floor's segment walk

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Literal brackets hide subsequent executable commands (span=e8aa6e56f6f9)

fixed in f140c9f: a bare [ no longer pushes a closer; only ${ and $[ open a tracked span, and each closes only on its own closer, so ${x:-[} ends at its } and the later comment is skipped.
Test: echo ${x:-[} # don't remove this marker + newline + rm -fr ~ is a new deny case; ${a[1]:- #} stays covered.
self-added: yes
mechanism: expansion closer stack in the rm floor's segment walk

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Parameter-expansion data becomes a fictitious command (span=e8aa6e56f6f9)

Rebutted: this is an over-refusal, not a bypass. echo ${x:- #; rm -fr ~;} is refused because the floor reads an rm -fr ~ it cannot prove is data; nothing is run or lost, and rewording clears it.
The PR's goal is deny-only; making separators expansion-aware adds parser state to a floor that is a seatbelt, not a parser. Adjudication also downgraded this as disproportionate.
self-added: yes
mechanism: expansion closer stack in the rm floor's segment walk

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Heredoc parentheses expose document text as executable shell (span=e8aa6e56f6f9)

Rebutted: this is an over-refusal, not a bypass. A heredoc inside $(...) whose body has a bare ) and then rm -fr ~ is refused; nothing is run or lost, and rewording clears it.
Making the shared _matching_close_paren heredoc-aware is out of this deny-only PR's scope. Adjudication also downgraded this as disproportionate.
self-added: yes
mechanism: unquoted substitution branch in the rm floor's segment walk

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: f140c9f
  • What rule changed: the recursive-force rm floor in src/kiro_crew/security/rm_floor.py (behind local-destructive-rm-rf-root / -home) reads more shell shapes as live commands.
  • Before -> after (what was allowed/blocked, now): allowed before, refused now: rm -fr ~ / rm -fr / behind then, do, else, {, !, time; with $(...) or a backtick in the argv or glued before rm; after a # or << inside ${...} / $[...]; after a heredoc opened inside $(...). Nothing that was refused is now allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands — an over-refusal of an unusual command that names rm -fr ~ or rm -fr / as data (for example inside a ${x:-...} default). The user rewords it. No secret or lockout path.
  • Evidence checked (which sandbox result proves it): every probe from issue security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 and its comments run through kiro_crew.security.is_denied on this head: all refused; rm -fr build, echo rm -fr ~, rm -fr $(mktemp -d) and a heredoc body containing rm -fr ~ stay allowed. prove.py reports PROVEN for the new tests (head f140c9f).
  • No regression:
    • Tools still work (which tools/commands were run, result): the allow list in TestRecursiveForceRmFloor (plain descendants, quoted text, heredoc bodies, redirect targets) passes unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, key or caller changes; deny_gate.py calls _rm_wipe_targets the same way; a disabled row still disables its floor (test_a_disabled_row_disables_its_floor).
    • Existing tests (which suites passed on this head): test/test_denied_commands_security_rows.py, test/test_denied_commands_security_quoting.py, test/test_security_gate_liveness.py, test/test_flake_pattern_ratchet.py (304 passed).
  • How to undo: revert this PR's single commit.

🤖 AI-assisted comment 🤖

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/kiro_crew/security/rm_floor.py Outdated
resume, resume_state = pos + end, 2
resume, resume_state = pos + end, step.state
break
if step.active and text.startswith(("${", "$["), step.offset):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in efe5150 and kept in the current head 94abebc. This command is a deny case in TestRecursiveForceRmFloor: it fails on f140c9f and passes on base c24c7bc and on the fix.

🤖 AI-assisted comment 🤖

Comment thread src/kiro_crew/security/rm_floor.py Outdated
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:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in efe5150 and kept in the current head 94abebc. This command is a deny case in TestRecursiveForceRmFloor: it fails on f140c9f and passes on base c24c7bc and on the fix.

🤖 AI-assisted comment 🤖

@iamwhatever
iamwhatever force-pushed the fix/rm-floor-keyword-shapes branch from f140c9f to efe5150 Compare October 24, 2026 22:18
@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Paired dollars create fictitious expansions that hide executable commands (span=e8aa6e56f6f9)

fixed in efe5150: a ${ / $[ opens a tracked expansion only after an odd run of live $, so $${ (the PID, then a brace) opens nothing and the real comment after it is skipped again.
Test: echo $${x:- # don't remove this marker + newline + rm -fr ~ is a new deny case; dropping the pairing check fails it.
self-added: yes
mechanism: expansion closer stack in the rm floor's segment walk

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • Empty backtick expansions conceal destructive target operands (span=e8aa6e56f6f9)

fixed in efe5150: a substitution now leaves its own marker, apart from the literal-character one, and target operands are checked with substitutions treated as empty, so rm -fr ~/\true`, rm -fr /$(true)andrm -fr "$HOME$(true)"are refused;rm -fr "/"` stays allowed.
Tests: three new deny cases; checking the raw operand fails all three.
self-added: yes
mechanism: substitution placeholder in the rm floor's segment walk

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: efe5150
  • What rule changed: the recursive-force rm floor in src/kiro_crew/security/rm_floor.py (behind local-destructive-rm-rf-root / -home) reads more shell shapes as live commands.
  • Before -> after (what was allowed/blocked, now): allowed before, refused now: rm -fr ~ / rm -fr / behind then, do, else, {, !, time; with $(...) or a backtick in the argv, in a target such as ~/$(true), or glued before rm; after a # or << inside ${...} / $[...]; after a heredoc opened inside $(...). Nothing that was refused is now allowed.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands — an over-refusal of an unusual command that names rm -fr ~ or rm -fr / as data (for example inside a ${x:-...} default). The user rewords it. No secret or lockout path.
  • Evidence checked (which sandbox result proves it): every probe from issue security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 and its comments run through kiro_crew.security.is_denied on this head: all refused; rm -fr build, echo rm -fr ~, rm -fr $(mktemp -d) and a heredoc body containing rm -fr ~ stay allowed. prove.py reports PROVEN for the new tests (head efe5150).
  • No regression:
    • Tools still work (which tools/commands were run, result): the allow list in TestRecursiveForceRmFloor (plain descendants, quoted text, heredoc bodies, redirect targets) passes unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, key or caller changes; deny_gate.py calls _rm_wipe_targets the same way; a disabled row still disables its floor (test_a_disabled_row_disables_its_floor).
    • Existing tests (which suites passed on this head): test/test_denied_commands_security_rows.py, test/test_denied_commands_security_quoting.py, test/test_security_gate_liveness.py, test/test_flake_pattern_ratchet.py (308 passed).
  • How to undo: revert this PR's single commit.

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author

@bolichen97 Both inputs from your review are fixed on head efe5150:

Command Base f140c9f efe5150
echo $${x:- # don't remove this marker + newline + rm -fr ~ refused allowed refused
rm -fr ~/`true` refused allowed refused
  • $${ is now read as the PID: a ${ / $[ opens a tracked expansion only after an odd run of live $.
  • A substitution leaves its own marker, apart from the literal-character one, and target operands are checked with it removed. So rm -fr ~/$(true) and rm -fr "$HOME$(true)" are refused too, while rm -fr "~/" stays allowed.

Each has a new deny case in TestRecursiveForceRmFloor, and a mutant that removes the check fails it. The per-finding dispositions are posted above. Could you take another look on this head when CI is done?

🤖 AI-assisted comment 🤖

@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 Oct 24, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread src/kiro_crew/security/rm_floor.py Outdated
while words:
if ENV_ASSIGNMENT_RE.match(words[0]):
words = words[1:]
if _SUBST in words[0]:

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

@iamwhatever iamwhatever changed the title fix(security): rm floor reads reserved words, argv substitutions and ${...} spans fix(security): rm floor reads reserved words, empty substitutions and ${...} spans Oct 24, 2026
@iamwhatever
iamwhatever force-pushed the fix/rm-floor-keyword-shapes branch from efe5150 to 94abebc Compare October 24, 2026 23:14
@iamwhatever
iamwhatever force-pushed the fix/rm-floor-keyword-shapes branch from e8dafdc to bde464f Compare October 26, 2026 23:08
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: bde464f
  • What rule changed: the recursive-force rm floor in src/kiro_crew/security/rm_floor.py (behind local-destructive-rm-rf-root / -home) reads more shell shapes as live commands, and reads every command both with and without ${...} tracking. Its spec paragraph in docs/system-specs/modules/security.md is updated to match.
  • Before -> after (what was allowed/blocked, now): allowed before, refused now: rm -fr ~ / rm -fr / behind then, do, else, {, !, time; with a quoted substitution that expands to nothing in the program word; after a # or << inside an unpaired ${...} / $[...]. Nothing that was refused is now allowed: a 125-command corpus was run through is_denied on base c24c7bc, on main 96c4fef and on this head.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: an over-refusal of an unusual command that names rm -fr ~ or rm -fr / as data (for example inside a ${x:-...} default). The user rewords it. No secret or lockout path.
  • Evidence checked (which sandbox result proves it): the keyword, case and ${...} probes from issue security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 and the reviewers' probes run through kiro_crew.security.is_denied on this head: all refused; rm -fr build, echo rm -fr ~, rm -fr $(mktemp -d), a heredoc body containing rm -fr ~, and heredoc commit messages with a) list items stay allowed. prove.py reports PROVEN (head bde464f). Twenty nested "$( ${ levels run in about 0.18 s.
  • No regression:
    • Tools still work (which tools/commands were run, result): the allow list in TestRecursiveForceRmFloor (plain descendants, quoted text, heredoc bodies, redirect targets) passes unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, key or caller changes; deny_gate.py calls _rm_wipe_targets the same way; a disabled row still disables its floor (test_a_disabled_row_disables_its_floor).
    • Existing tests (which suites passed on this head): test/test_denied_commands_security_rows.py and test/test_security_gate_liveness.py (196 passed).
  • How to undo: revert this PR's single commit.

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author
  • The rm floor's owning spec paragraph in security.md was not updated (span=f6adfbd55f89)

fixed in bde464f: the Recursive-force rm floor paragraph in docs/system-specs/modules/security.md now covers all four behaviours: reserved words, ! and time [-p] keep command position; a substitution in the program word is dropped; # / << inside ${…} / $[…] are data, except after $$; every command is read with and without that tracking, and the targets are joined.
The out-of-scope list is narrowed to match: arithmetic and parameter-expansion defaults are tracked, not evaluated, and an unquoted $(…) or backtick in the argv stays out of scope. Docs only; no code changed.
self-added: no
mechanism: owning spec for the rm floor

🤖 AI-assisted comment 🤖

@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 Oct 27, 2026
@iamwhatever
iamwhatever force-pushed the fix/rm-floor-keyword-shapes branch from bde464f to d35d50e Compare October 27, 2026 01:45
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: d35d50e
  • What rule changed: the recursive-force rm floor in src/kiro_crew/security/rm_floor.py (behind local-destructive-rm-rf-root / -home) reads more shell shapes as live commands, and reads every command both with and without ${...} tracking. Its spec paragraph in docs/system-specs/modules/security.md is updated to match.
  • Before -> after (what was allowed/blocked, now): allowed before, refused now: rm -fr ~ / rm -fr / behind then, do, else, {, !, time; with a quoted substitution that expands to nothing in the program word; after a # or << inside an unpaired ${...} / $[...]. Nothing that was refused is now allowed: a 125-command corpus was run through is_denied on base c24c7bc, on main 8a518e1 and on this head.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: an over-refusal of an unusual command that names rm -fr ~ or rm -fr / as data (for example inside a ${x:-...} default). The user rewords it. No secret or lockout path.
  • Evidence checked (which sandbox result proves it): the keyword, case and ${...} probes from issue security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 and the reviewers' probes run through kiro_crew.security.is_denied on this head: all refused; rm -fr build, echo rm -fr ~, rm -fr $(mktemp -d), a heredoc body containing rm -fr ~, and heredoc commit messages with a) list items stay allowed. prove.py reports PROVEN (head d35d50e). Twenty nested "$( ${ levels run in about 0.18 s.
  • No regression:
    • Tools still work (which tools/commands were run, result): the allow list in TestRecursiveForceRmFloor (plain descendants, quoted text, heredoc bodies, redirect targets) passes unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, key or caller changes; deny_gate.py calls _rm_wipe_targets the same way; a disabled row still disables its floor (test_a_disabled_row_disables_its_floor).
    • Existing tests (which suites passed on this head): test/test_denied_commands_security_rows.py and test/test_security_gate_liveness.py (196 passed).
  • How to undo: revert this PR's single commit.

🤖 AI-assisted comment 🤖

@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 Oct 27, 2026
@github-actions github-actions Bot added readiness: passed Eligible automated validation passed for the current revision merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: checking Automated validation is still running labels Oct 27, 2026

@CrysisDeu CrysisDeu left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Rebase the single conflict: test/test_security_gate_liveness.py:530 — main moved _PACKAGE_LINE_BUDGET to 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).
  2. @bolichen97's CHANGES_REQUESTED at 94abebc is 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.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

@CrysisDeu, here is what I did with each point of your review at d35d50e1 (review 5663072236):

  • Rebase conflict at test_security_gate_liveness.py:530: done. _PACKAGE_LINE_BUDGET = 32_635 (+19 from main's 32,616). cat src/kiro_crew/security/*.py | wc -l is exactly 32,635. Main's install-fence paragraph and ours are both kept, our "from" now reads 32,616, and "or a target" is gone ("a quoted substitution may expand to nothing in the program word").
  • @bolichen97's stale CHANGES_REQUESTED at 94abebc: not mine to dismiss. It is left for his approval or a maintainer dismissal.
  • Nit: redirect-to-substitution deny forms: pinned <$(x) RM -fr ~ and 2>$(printf /dev/null) RM -fr ~ in test_a_recursive_force_wipe_of_root_or_home_is_denied. Each was checked as refused before it was committed.
  • Nit: $[ $( # ... ) ] variant: pinned "echo $[ $( # don't\nRM -fr ~\n# '\n) ]" in the same test. It is refused.
  • Nit: loose walk-count bound (:651, 4*20+2): left as it is, on purpose. The bound guards against the nesting hang, which grows exponentially, and loose is fine for that. Tightening it would only couple the test to the walk's internals.
  • Follow-up ${x}rm -fr ~: agreed. It is allowed on both base and head, so this PR (deny-only, Part of security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464) does not change it. It stays open under security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 with row 6 and heredoc-in-$(…).

Tests only, no prod change: rm_floor.py is still byte-identical to 2ae01846. The touched files give 258 passed, and prove.py is still PROVEN. The push with the new head follows.

🤖 AI-assisted comment 🤖

@iamwhatever
iamwhatever force-pushed the fix/rm-floor-keyword-shapes branch from d35d50e to f367bdf Compare October 27, 2026 06:37
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: f367bdf
  • What rule changed: the recursive-force rm floor in src/kiro_crew/security/rm_floor.py (behind local-destructive-rm-rf-root / -home) reads more shell shapes as live commands, and reads every command both with and without ${...} tracking. Its spec paragraph in docs/system-specs/modules/security.md is updated to match.
  • Before -> after (what was allowed/blocked, now): allowed before, refused now: rm -fr ~ / rm -fr / behind then, do, else, {, !, time; with a quoted substitution that expands to nothing in the program word; after a # or << inside an unpaired ${...} / $[...]. Nothing that was refused is now allowed: a 125-command corpus was run through is_denied on base c24c7bc, on main b06d6a8 and on this head.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: an over-refusal of an unusual command that names rm -fr ~ or rm -fr / as data (for example inside a ${x:-...} default). The user rewords it. No secret or lockout path.
  • Evidence checked (which sandbox result proves it): the keyword, case and ${...} probes from issue security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 and the reviewers' probes run through kiro_crew.security.is_denied on this head: all refused; rm -fr build, echo rm -fr ~, rm -fr $(mktemp -d), a heredoc body containing rm -fr ~, and heredoc commit messages with a) list items stay allowed. prove.py reports PROVEN (head f367bdf). Twenty nested "$( ${ levels run in about 0.18 s.
  • No regression:
    • Tools still work (which tools/commands were run, result): the allow list in TestRecursiveForceRmFloor (plain descendants, quoted text, heredoc bodies, redirect targets) passes unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, key or caller changes; deny_gate.py calls _rm_wipe_targets the same way; a disabled row still disables its floor (test_a_disabled_row_disables_its_floor).
    • Existing tests (which suites passed on this head): test/test_denied_commands_security_rows.py and test/test_security_gate_liveness.py (196 passed).
  • How to undo: revert this PR's single commit.

🤖 AI-assisted comment 🤖

@iamwhatever

Copy link
Copy Markdown
Contributor Author

@CrysisDeu rebased at f367bdf: budget 32_635, comment fixed, 3 deny forms pinned.

🤖 AI-assisted comment 🤖

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: passed Eligible automated validation passed for the current revision readiness: checking Automated validation is still running labels Oct 27, 2026

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: de51b8a
  • What rule changed: the recursive-force rm floor in src/kiro_crew/security/rm_floor.py (behind local-destructive-rm-rf-root / -home) reads more shell shapes as live commands, and reads every command both with and without ${...} tracking. Its spec paragraph in docs/system-specs/modules/security.md is updated to match.
  • Before -> after (what was allowed/blocked, now): allowed before, refused now: rm -fr ~ / rm -fr / behind then, do, else, {, !, time; with a quoted substitution that expands to nothing in the program word; after a # or << inside an unpaired ${...} / $[...]. Nothing that was refused is now allowed: a 125-command corpus was run through is_denied on base c24c7bc, on main 6b1b65d and on this head.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: an over-refusal of an unusual command that names rm -fr ~ or rm -fr / as data (for example inside a ${x:-...} default). The user rewords it. No secret or lockout path.
  • Evidence checked (which sandbox result proves it): the keyword, case and ${...} probes from issue security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 and the reviewers' probes run through kiro_crew.security.is_denied on this head: all refused; rm -fr build, echo rm -fr ~, rm -fr $(mktemp -d), a heredoc body containing rm -fr ~, and heredoc commit messages with a) list items stay allowed. prove.py reports PROVEN (head de51b8a). Twenty nested "$( ${ levels run in about 0.18 s.
  • No regression:
    • Tools still work (which tools/commands were run, result): the allow list in TestRecursiveForceRmFloor (plain descendants, quoted text, heredoc bodies, redirect targets) passes unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, key or caller changes; deny_gate.py calls _rm_wipe_targets the same way; a disabled row still disables its floor (test_a_disabled_row_disables_its_floor).
    • Existing tests (which suites passed on this head): test/test_denied_commands_security_rows.py and test/test_security_gate_liveness.py (196 passed).
  • How to undo: revert this PR's single commit.

🤖 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.
@iamwhatever

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: a9e3c45
  • What rule changed: the recursive-force rm floor in src/kiro_crew/security/rm_floor.py (behind local-destructive-rm-rf-root / -home) reads more shell shapes as live commands, and reads every command both with and without ${...} tracking. Its spec paragraph in docs/system-specs/modules/security.md is updated to match.
  • Before -> after (what was allowed/blocked, now): allowed before, refused now: rm -fr ~ / rm -fr / behind then, do, else, {, !, time; with a quoted substitution that expands to nothing in the program word; after a # or << inside an unpaired ${...} / $[...]. Nothing that was refused is now allowed: a 125-command corpus was run through is_denied on base c24c7bc, on main d069596 and on this head.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): breaks commands: an over-refusal of an unusual command that names rm -fr ~ or rm -fr / as data (for example inside a ${x:-...} default). The user rewords it. No secret or lockout path.
  • Evidence checked (which sandbox result proves it): the keyword, case and ${...} probes from issue security: rm argv floor misses keyword, comment and in-argument substitution spellings #18464 and the reviewers' probes run through kiro_crew.security.is_denied on this head: all refused; rm -fr build, echo rm -fr ~, rm -fr $(mktemp -d), a heredoc body containing rm -fr ~, and heredoc commit messages with a) list items stay allowed. prove.py reports PROVEN (head a9e3c45). Twenty nested "$( ${ levels run in about 0.18 s.
  • No regression:
    • Tools still work (which tools/commands were run, result): the allow list in TestRecursiveForceRmFloor (plain descendants, quoted text, heredoc bodies, redirect targets) passes unchanged.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, key or caller changes; deny_gate.py calls _rm_wipe_targets the same way; a disabled row still disables its floor (test_a_disabled_row_disables_its_floor).
    • Existing tests (which suites passed on this head): test/test_denied_commands_security_rows.py and test/test_security_gate_liveness.py (196 passed).
  • How to undo: revert this PR's single commit.

🤖 AI-assisted comment 🤖

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.py and test_security_gate_liveness.py file 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 before rm, and ${x#y} / $[1#2] / $$# before a separator are all refused; ls ~/x and rm -rf ./build are not.
  • Gates: readiness passed on this head, all required checks green, no AI lane BLOCK, no merge conflict, no other review requesting changes.

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.

3 participants