Skip to content

fix(security): cover rm flag variants in the rm-rf-root/home deny rules - #8240

Closed
soroush5 wants to merge 2 commits into
kirodotdev:mainfrom
soroush5:fix/rm-flag-variant-deny
Closed

soroush5 wants to merge 2 commits into
kirodotdev:mainfrom
soroush5:fix/rm-flag-variant-deny

Conversation

@soroush5

@soroush5 soroush5 commented Sep 3, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

The two rm deny rules (local-destructive-rm-rf-root / -home) only recognize the exact -rf flag spelling, and the home rule only recognizes literal ~. Equivalent recursive-force invocations sail through the PreToolUse gate — verified via is_denied: reordered (-fr), combined (-rfv), split (-r -f), long-option (--recursive/--force/--no-preserve-root) spellings, one interspersed operand (rm harmless -rf --no-preserve-root /), and every $HOME/${HOME} spelling (which the shell expands to ~) all return None.

Why it matters

Any agent run that reaches for a destructive delete with a non-canonical spelling gets zero confirmation. This is the same bug class as #4824 (which widened only the four self-protection rules for interposed flags) — the rm rules were left exact-match, so the floor has a hole exactly where the damage is total.

What changed

Both rm patterns widened with NO .* gap (single fragment, exact full-input semantics): literal single spaces plus runs of single-letter flag tokens, one optional unquoted operand slot, and the $HOME family on the home rule. That shape is what keeps the separator pins holding (a .* gap would fabricate commands across ;/newlines), the ReDoS screens green (bare * over quantifier-free bodies; the operand slot ends in a literal so the polynomial screen stays blind to it), and the documented " " residual intact. rm is token-anchored (/bin/rm, {rm;}, backtick programs still match), with one deliberate exception: quote-glued rm matches when a separator follows later in the string — that keeps the Pass-1 whole-string closure for pipelines (grep 'rm -rf /...' | python must deny even though the literal is quoted), while a lone "rm" -rf / still misses raw text for the respelling-proof twin. rm -f/-r-only, flagless rm, lone --recursive, rm -- -rf /, --preserve-root, and lookalikes ($HOMEx, file~) all stay allowed. Governance legacy map gains the two pre-widening spellings (#4824 precedent); search-verb carve-out (#8802) registered from the live patterns; golden fixture synced (111 rows).

Residuals (documented in-code): interposed LONG flags (-r --verbose -f), leading long-flag padding, 2+ or quoted operands, operands between flags and path, getopt-permuted trailing flags — each needs a repeated operand gap the ReDoS screens forbid.

Tests

  • Extended TestRmFlagVariantsStayDenied (flag/operand/program variants + allow shapes) and new TestRmHomeEnvSpellingsStayDenied ($HOME/${HOME} incl. braced operators, lookalikes) in test/test_denied_commands_security.py.
  • Full suites green on fresh main: test_denied_commands_security.py + test_security.py + test_deny_guidance.py + test_denied_commands_hooks.py + test_heartbeat_safe_tools.py + test_security_regex_linearity.py — 1934 passed, 2 skipped (pre-existing).
  • Three pin flips, each sanctioned by the test's own docstring: the flag-interposition gap, the first over-block (double-quoted ANSI-C is inert), and the governance-map emptiness.
  • ReDoS: both patterns pass is_safe_user_regex, take the unbounded single-fragment path, hostile inputs (20k-quote, flag-chain, padded needle) evaluate in ≤0.1s.
  • black gate green; isort/mypy not installed in this environment (no import or typing changes in the diff).

Fixes #8237
Fixes #8387

Pattern harvest

Rule candidate: deny-list regexes that match one spelling of equivalent destructive invocations — worth a pass over the other local-destructive patterns for packed/split/long-option variants.

@soroush5
soroush5 requested review from a team and cixuuz September 3, 2026 18:35
@iamwhatever

Copy link
Copy Markdown
Contributor

👋 Hi! This PR's description is missing some required sections from our PR template. Workflow runs won't be auto-approved until the description is updated.

Missing sections:

  • ## Problem / Motivation
  • ## Why it matters
  • ## What changed
  • ## Tests

Please update your PR description to include these sections, then push or re-save the description. The workflows will be approved on the next cycle.

@github-actions github-actions Bot added fork Pull request from a fork (external contributor) readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 3, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Open PR relationship audit

This is a consolidated, point-in-time code-level audit note. It compares complete merge-base diffs and current/merged code; it does not treat a shared topic as duplication or partial coverage as completion.

Relationship findings

  • PR #8262 is OVERLAPPING relative to this PR. The goals differ or the implementations can complement each other; this is not a duplicate claim. Recommended action for PR #8262: KEEP. Same file, disjoint hunks and disjoint rules. No coordination needed. Files: src/kiro_crew/security.py. The two independent directions used different labels; the matrix conservatively retains OVERLAPPING for coordination.

No PR, Issue, label, branch, or review state was changed by the relationship-note portion of this audit.

@soroush5

soroush5 commented Sep 4, 2026

Copy link
Copy Markdown
Contributor Author

Two notes in one: the template-bot warning above is stale — all listed sections (Problem/Motivation, Why it matters, What changed, Tests, Pattern harvest) are in the body now. And on the relationship audit: agreed, #8262 is same-file/disjoint-hunks, KEEP with no coordination needed from this side.

@soroush5
soroush5 force-pushed the fix/rm-flag-variant-deny branch from b7cbff0 to 450dbe7 Compare September 5, 2026 22:05
@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 Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Fable 5, fork) — 🟡 CONCERNS

Design-level review of a155aeed6955547a291b9ace7fcb4171e2b86c5d via the fork AI-review pipeline — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: CONCERNS

Sound widening within the catalog's documented instrument limits, but the user-facing refusal now carries a 300-char regex where a legible literal was the payload.

Watch

  • The refusal line is Blocked by security policy: <pattern> by contract (_deny_reason, denied_rules.py:2947 — RecoveryCard.tsx extracts that pattern, the blocked-by-policy skill tells the agent to read it). These two rules are the first whose pattern is unreadable as a message; the PR's own loosening of "rm -rf" in _error(rows) to "rm" in _error(rows) is the trace of a dashboard/agent-visible text change the description never states. Anything downstream keying on the old literal breaks silently, and the operator's Recovery/Settings surface now shows regex soup instead of rm -rf /.*.
    Clears when: the description owns the refusal-text change and the author confirms RecoveryCard/blocked-by-policy stay usable with the long pattern (or the refusal names the rule id/description for these rows).

Suggestions

  • Factor the flag-run core (repeated verbatim in both rules) into one module constant composed into each pattern — the PR already refused to restate long literals for the carve-out map for exactly this drift reason; the golden fixture pins each rule separately and won't catch the cores diverging.

[DESIGN-REVIEWED] a155aee

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

GPT 5.6 Review (fork) — 🔴 changes requested (blocking)

Reviewed a155aeed6955547a291b9ace7fcb4171e2b86c5d via the fork AI-review pipeline; updated in place on each push.

1 of 1 blocking finding(s) are security-class and were withheld from adjudication, so the blocking verdict stands.

BLOCKING -- src/kiro_crew/security/denied_rules.py:1318 -- Valid rm spellings still bypass the gate

(?:(?!--)[^\s;|&()\"']+ )? and \$\{HOME:[^}]*\}
rm --verbose -rf "$HOME" or rm -rf ${HOME#x} -> PreToolUse misses -> home deletion proceeds.
Anchor: residual/security
Fix: recognize destructive rm argv structurally, including valid option ordering and HOME parameter-expansion operators.
[BLOCK-MERGE] a155aee
[GPT-REVIEWED] a155aee

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

I've read the prompt and examined both the base tree and the diff. Let me verify the fenced finding F1 against the widened rm patterns in the diff.

The two claimed bypasses:

Case 1 — rm --verbose -rf "$HOME": After matching rm, the leading flag run (?: -[a-z])* cannot consume --verbose (its second char is -, not [a-z]), the optional operand (?:(?!--)[^\s;|&()\"']+ )? is blocked by the (?!--) lookahead, and the mandatory flag core (?:-[a-z]*r[a-z]*f[a-z]*|…|--recursive…|--force…) does not match --verbose. The match fails — home deletion proceeds. This is exactly the residual the diff itself documents ("interposed LONG flags … and leading long-flag padding") and the added test deliberately omits ("Padding with LONG flags … is a documented residual"). rm --verbose -rf "$HOME" is an entirely ordinary spelling.

Case 2 — rm -rf ${HOME#x}: The home-path alternation "?(?:~|\$HOME(?![A-Za-z0-9_])|\$\{HOME\}|\$\{HOME:[^}]*\}) matches only ~, bare $HOME, ${HOME}, or ${HOME:…}. The #-prefix-strip operator ${HOME#x} (which resolves to $HOME when it has no x prefix) matches none of them — bypass confirmed.

Both are genuine, and both are reachable through plainly ordinary command spellings — not extreme, self-contradicting, or writer-impossible conditions. FLAG requires the reaching conditions to be so extreme a human would accept the residual risk; a bare rm --verbose -rf "$HOME" is the opposite of extreme. I cannot complete a rarity record, so the fenced finding stands as written.

UNBOUNDED harm (irreversible home/root deletion), conditions confirmed at denied_rules.py:1298-1306 / diff hunk lines 78-89 (home rule) and 51-59 (root rule); no recovery path exists for rm -rf of $HOME.

[ADJUDICATION] a155aeed6955547a291b9ace7fcb4171e2b86c5d total=0 uphold=0 downgrade=0
[GPT-ADJUDICATED] a155aeed6955547a291b9ace7fcb4171e2b86c5d
[ADJUDICATION-FENCED] a155aeed6955547a291b9ace7fcb4171e2b86c5d fenced=1 flagged=0
UPHOLD-FENCED F1 src/kiro_crew/security/denied_rules.py:1318 -- Ordinary spellings `rm --verbose -rf "$HOME"` (leading long-flag, a documented residual) and `rm -rf ${HOME#x}` (unhandled `#`-strip operator) bypass the widened rule and delete home irreversibly; the reaching conditions are commonplace, not extreme, so no FLAG rarity record can be completed.
[GPT-ADJUDICATED-FENCED] a155aeed6955547a291b9ace7fcb4171e2b86c5d

@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Fable 5, fork) — 🟡 CONCERNS

Premise-level review of a155aeed6955547a291b9ace7fcb4171e2b86c5d via the fork AI-review pipeline — 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/CONCERNS are advisory.

Evidence gathered: the base patterns (denied_rules.py:1291,1300) mechanically cannot match the spellings the new tests assert, the legacy-map and carve-out mechanisms both have live consumers (denied_rules.py:1766, __init__.py:1607,1670), and the flag-exact sibling rules are countable. Ready to emit the review.

First-Principles-Verdict: CONCERNS

Point patch: the same one-spelling defect stays open in three counted sibling deny rules the PR's own "Pattern harvest" admits exist.

Not justified as shipped

  • Item 4 — rides along: token-anchoring flips two previously-denied inputs to allowed (confirm -rf /-style substring matches; the pinned double-quoted ANSI-C over-block), declared only obliquely as "rm is token-anchored".
  • Item 9 — rides along: error-text pins loosened from "rm -rf" in _error to "rm" in _error, weaker than the widened pattern forces.

What this change ships

Inventory (9 items) — 7 justified

Intent: make the two rm deny rules catch equivalent recursive-force spellings, not just literal -rf and ~ — a FIX (new tests fail on base: rm -rf /.* cannot match -fr).

  1. Root rule denies packed/reordered/split/long-option flag spellings — justified
  2. Home rule same, plus $HOME/${HOME}/braced-operator spellings — justified
  3. One interspersed operand (rm harmless -rf /) now denied — justified
  4. Two former denials now allowed via token-anchoring — rides along (see above)
  5. Legacy map resolves the two pre-widening spellings to their rules — justified
  6. Search-verb carve-out registered for the widened patterns — justified
  7. Golden fixture and security.md updated in-commit — justified
  8. Three pin flips, each sanctioned by the pin's own docstring — justified
  9. test_llm_helpers error-text assertions loosened — rides along (see above)

Watch

  • Unfixed siblings, counted: grepping BUILTIN_DENIED_RULES for flag-exact patterns finds nc -e.* (denied_rules.py:1264), ncat -e.* (:1273), git reset --hard.* (:1236) — packed (nc -ve) or interposed (git reset -q --hard) spellings bypass identically. Author names the class ("worth a pass over the other local-destructive patterns") but ships no tracking. Clears when: an issue is filed for the sibling sweep, or those rules are widened.
  • The allow-direction flip (item 4) rests on "every spelling that does execute still denies through a view that strips the quotes" — pinned only by this PR's own RESPELLINGS cross. Clears when: that cross is confirmed green on the merged HEAD.

[FIRST-PRINCIPLES-REVIEWED] a155aee

@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 Sep 5, 2026
@github-actions

github-actions Bot commented Sep 5, 2026 •

Copy link
Copy Markdown
Contributor

Opus 4.8 Review (fork) — ✅ no blocking findings

Reviewed a155aeed6955547a291b9ace7fcb4171e2b86c5d via the fork AI-review pipeline; updated in place on each push.

Review details

No findings.

The single candidate describes rm --no-preserve-root -rf / slipping past the widened local-destructive-rm-rf-root rule. Verified: after rm, the (?: -[a-z])* run cannot consume the double-dash --no-preserve-root, the operand slot is blocked by its (?!--) lookahead, and the flag core requires an r/f-bearing token, so matching fails and the command is allowed. But this is not a defect this diff introduces:

  • The old pattern rm -rf /.* required a contiguous rm -rf / and equally did not match rm --no-preserve-root -rf / (no such substring). So this is a pre-existing gap, not a regression — the PR strictly widens coverage and removes no guard.
  • The rule's own added documentation explicitly lists this as an accepted residual: "Other residuals: interposed LONG flags (-r --verbose -f) and leading long-flag padding." --no-preserve-root before the flags is exactly leading long-flag padding.
  • The proposed fix — add --no-preserve-root / a long-flag run to the pre-core option group — is a spelling-chase against a best-effort text tier. The OS sandbox is the load-bearing control for a root-filesystem wipe; the candidate cites no sandbox mask that fails.

It fails the Step-1 bar (no observable wrong outcome newly caused by the changed lines) and, even taken at face value, would be neither a removed guard nor a regression on a path this diff changes. Dropped.

[OPUS-REVIEWED] a155aee

@soroush5

soroush5 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Verified each claim live, and you were right on the core point — reworked accordingly:

  • Confirmed the escape through the real gate: rm -v ×5 -rf / was allowed with the bounded slots. They are gone now; every pad site uses the exact house idiom (_DANGEROUS_AWS_FLAG_RUN spelling, so _linearize_deny_pattern rewrites it — verified rewritten + gate green), with the r+f combination still carried by the alternation.
  • 5-pad/10-pad/combo-internal/verbose padding all denied now; allows (-r/-f alone, flagless, quoted-whitespace A quoted whitespace-only word bypasses the command-shape deny rules #8124 pin) unchanged. 636 green locally.
  • On the 'contradicted' point, one precision: my first draft used literal-space separators (to preserve the A quoted whitespace-only word bypasses the command-shape deny rules #8124 pin), not the byte-identical \s+ spelling — and the linearizer only rewrites the exact constant, so that draft was genuinely skipped (verified: exact→rewritten, literal-space-star→untouched). The body told that story imprecisely; fixed.
  • On breaking A quoted whitespace-only word bypasses the command-shape deny rules #8124: the pin view is rm -rf /home/x (3-space run from the quoted word) — it matches under neither spelling, so the pin test stays green. The pin is about the quoted word, not multi-space separators.

@soroush5

soroush5 commented Sep 6, 2026

Copy link
Copy Markdown
Contributor Author

Same rework addresses this: the bounded slots are replaced by the linearized house idiom at every pad site, so padding count no longer matters (verified 5- and 10-pad denied through the real gate). On scope: structural argv parsing would mean re-architecting the regex-view tier, which is beyond this fix; the residual class for pads is closed, with the #8124 quoted-whitespace pin intact and rarity/recovery as your adjudication notes (default flow still prompts).

@soroush5
soroush5 force-pushed the fix/rm-flag-variant-deny branch from c71571d to 2a8e32d Compare September 6, 2026 06:26
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 6, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: checking Automated validation is still running labels Sep 8, 2026
@soroush5
soroush5 force-pushed the fix/rm-flag-variant-deny branch from 52a5f33 to f93511b Compare September 9, 2026 06:13
@github-actions github-actions Bot added readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge and removed readiness: action required A blocking check or review needs attention labels Sep 9, 2026
…spellings

Covers packed (-fr, -rfv), split (-r -f), and long-option
(--recursive/--force) flag spellings, one interspersed operand,
--no-preserve-root, and the $HOME spellings the shell expands to ~,
without any .* gap so separator pins and ReDoS screens keep holding.
@soroush5
soroush5 force-pushed the fix/rm-flag-variant-deny branch from f93511b to e2a82f5 Compare September 11, 2026 07:59
@github-actions github-actions Bot added readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running and removed readiness: checking Automated validation is still running merge conflict Branch has merge conflicts with its base — author must resolve before merge readiness: action required A blocking check or review needs attention labels Sep 11, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: action required A blocking check or review needs attention and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Sep 11, 2026
@NicholasRBowers NicholasRBowers added needs-pr-triage PR scanner: awaiting automated triage needs-human-security-review Security scan flagged — needs manual review and removed needs-pr-triage PR scanner: awaiting automated triage labels Sep 18, 2026
@NicholasRBowers

Copy link
Copy Markdown
Contributor

🤖 Kiro Crew [operator: NicholasRBowers#a942f9ca]: Security scan flagged this PR for manual review.

The drive-to-green triage pass runs a mandatory content scan (code/diff + PR text) before any automated action. This PR tripped the code layer 31 times, on two rules:

  • rm\s+-(?=[a-z]*r)(?=[a-z]*f)[a-z]+\s+(/(?!\s)|~|\$HOME|\$\{HOME\}|\.\.|/tmp/kc) — 27 hits
    • src/kiro_crew/security/denied_rules.py:1811 — "rm -rf /.*": "local-destructive-rm-rf-root",
    • src/kiro_crew/security/denied_rules.py:1812 — "rm -rf ~.*": "local-destructive-rm-rf-home",
    • test/fixtures/denied_commands_golden.json:608 — "description": "Blocks recursive force-deletion rooted at the filesystem root (rm -rf /...)…
    • test/test_denied_commands_security.py:8676-8677 — "rm -rf /", / "rm -fr /",
  • rm\s+(-[a-z]+\s+)*-[rf]\s+(-[a-z]+\s+)*-[rf]\s+(/(?!\s)|~|\$HOME|\$\{HOME\}|\.\. — 4 hits, same three files

Hits by file: src/kiro_crew/security/denied_rules.py (3), test/fixtures/denied_commands_golden.json (2), test/test_denied_commands_security.py (26).

Two things a maintainer should weigh, stated plainly rather than hidden behind the count:

  1. The matches are self-referential. This PR's purpose is to widen the local-destructive-rm-rf-root / -home deny rules, so literal rm -rf / spellings necessarily appear in the patterns, the golden-fixture descriptions, and the test corpus. The scanner cannot tell a rule that blocks a destructive command from a diff that runs one.
  2. The PR text layer is clean — zero prompt-injection, embedded-directive, or social-engineering findings in the title, body, or comments.

That said, the diff edits src/kiro_crew/security/denied_rules.py — the security trust root — and widening a denylist is a policy decision, not a mechanical fix. Triage does not self-clear either condition, so no automated driving is queued.

Labels: added needs-human-security-review, removed needs-pr-triage. A maintainer will review before any automated action is taken. Add pr-no-autofix to opt this PR out of future automation entirely.

@iamwhatever

Copy link
Copy Markdown
Contributor

Thanks for the careful work here, @soroush5, and for verifying each finding live.

Closing this in favour of your planned consolidated PR. Quoting your own comment: "I will fold both axes into one PR against the new denied_rules.py layout (composing the flag-run idiom into the $HOME alternation, regenerating the golden fixture on current main, dropping the em-dash rows) and close these two. I will also cover the operand-before-flags shape so Fixes #8237 stays."

That folds the flag-run widening here together with the $HOME operand axis, rebased onto the post-#9183 src/kiro_crew/security/denied_rules.py layout — which avoids the "whichever lands second silently drops the first axis" problem the relationship audit flagged. Leaving #8262 untouched per that same discussion.

You're very welcome to reopen this if plans change, or just open the consolidated PR when it's ready. Thanks again.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Sep 24, 2026
@soroush5

Copy link
Copy Markdown
Contributor Author

Thanks, that makes sense. Sorry it sat this long.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fork Pull request from a fork (external contributor) needs-human-security-review Security scan flagged — needs manual review

Projects

None yet

4 participants