Skip to content

fix: close a gap in how the command check reads nested commands - #30736

Merged
bolichen97 merged 1 commit into
mainfrom
fix/9181-shell-span
Nov 5, 2026
Merged

bolichen97 merged 1 commit into
mainfrom
fix/9181-shell-span

Conversation

@bolichen97

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: Make the command check read a nested command as far as the shell runs it, so a command it refuses in its plain form is still refused when written another way.

For one shell spelling the command check stopped reading a nested command before the shell does. The rest of that command went unchecked, so a command the check refuses in its plain form was allowed.

Why it matters

The command check is one of the layers that keeps an agent from running a command the operator's policy refuses. Any spelling that hides part of a command from it lets that part through.

Not a goal

  • No new deny rule, and no change to the denied-command catalog.
  • No change to how quoting is read.
  • No other shell spellings beyond the one the issue names.

What changed (motivation → approach → change)

The check now reads the spelling the issue names to the same end the shell does, nested parts included. It keeps the longer of its old and new readings, so it never checks less of a command than before. The change sits in the shell reader in src/kiro_crew/security that every check shares, and one test covers it.

It builds on #23620 by @iamwhatever and is smaller: there is no fallback to the old reading, so the cases where that fallback brought the short reading back do not arise.

Backwards compatibility

Compatible: the check only reads more of a command than before, never less, so a command allowed today is refused only when the newly read part holds a refused command.

Removes nothing: no rule, key or public function is removed or renamed.

Tests

Test Locks in
one new test, four spellings the whole nested command is read and refused
one new test where the new reading cannot finish, the old reading stands
two entries in the list of shapes that must stay allowed ordinary commands in these shapes stay allowed
one entry in the existing here-document test the reading is never shorter than before

Determinism: 20 repeats at -n0 and 10 at -n 4 --dist loadgroup with two sibling files, all green; the whole file in a shuffled order (seed 25108) green.

Proof: PROVEN every case of the four-spelling test fails without the fix (head e6c7944)

Manual verification

Each spelling in the test was run through bash to confirm where bash ends the nested command; the check now ends it at the same place.

Screenshots / video

N/A — no frontend change.

Related Issues

Closes #9181

Builds on #23620 by @iamwhatever.

Sibling sweep

Siblings: none -- every check reads nested commands through the one shared reader this changes

Pattern harvest

Not generalizable: a one-off gap in reading one shell construct, in the single shared reader

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

Contribution License Agreement

For one shell spelling the command check stopped reading a nested
command before the shell does, so the rest of it went unchecked and a
command the check refuses in its plain form was allowed. The check now
reads that spelling to the same end the shell does, and never reads
less than it did before.
@github-actions

github-actions Bot commented Nov 5, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/shell_normalizer_walk.py

  • @KiroCrewCaptain: missing the ## Sensitive change review heading

How to clear this check:

  1. The PR author posts the template below as a PR comment, with
    every field filled (N/A needs a reason). Keep the
    Head commit line: it must name the current head SHA.
  2. The check turns green within a minute, with no push.
  3. A new push resets this check: post it again for the new head.

Only the author's comment counts this way. A reviewer can instead
paste the filled template into an "Approve" review on this head.
Merging still needs a reviewer's approval.

## Sensitive change review
- Head commit: e6c7944d18a67a438c8c4b76770259e91ef9126c
- What rule changed:
- Before -> after (what was allowed/blocked, now):
- Worst case if wrong (breaks commands / leaks secret / locks user out):
- Evidence checked (which sandbox result proves it):
- No regression:
  - Tools still work (which tools/commands were run, result):
  - Backward compatible (old config / old data / old callers still work, how checked):
  - Existing tests (which suites passed on this head):
- How to undo:

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

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision e6c7944d18a67a438c8c4b76770259e91ef9126c touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Does not block merge.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Nothing blocks: the reader is a shared extractor that treats a longer span as safe, and taking the longer of the two readings keeps it from ever checking less of a command than before.

Notes

  • The ${...} word now tracks its own nesting inside the shared closer, so it stays a reading of how the shell parses the command, not a new pattern-matching rule. Leave nested-word handling here and don't add any per-spelling deny rows.

[DESIGN-REVIEWED] e6c7944

Description read

[DESCRIPTION-READ] c508a8db7becbc07d6edc40995d3b8be56a6b98f3541e9bb23a5636fe98b2e92

That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with .github/scripts/pr-description-capture.sh over the same inputs; if it differs, the description or that evidence changed after this verdict was formed and any finding drawn from either is unproven.

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of e6c7944d18a67a438c8c4b76770259e91ef9126c — 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: a linked issue (#9181), a fix in the one shared reader all five callers use, and tests that fail on base.

What this change ships

Inventory (3 items) — 3 justified

Intent: stop a command the policy refuses from slipping through when it is written inside a ${...} default value within $(...). FIX.

  1. A refused command behind ${v:-)} (and its variants with $(, <( or a backtick inside the braces) in a $(...) substitution is now read in full and refused — justified
  2. Where the new reading cannot finish (a ${ inside here-document data), the old, longer span is kept, so no span gets shorter — justified
  3. Ordinary commands in these shapes stay allowed (two shapes added to the benign list, plus one here-document case) — justified

[FIRST-PRINCIPLES-REVIEWED] e6c7944

Description read

[DESCRIPTION-READ] 8439ac65dc5ae297a550eaf60968628d532edcae0cb8a8a76edb5278b2a7a619

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] e6c7944

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

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

@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

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

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

This comment is updated in place on each push.

Review details

BLOCKING -- src/kiro_crew/security/shell_normalizer_walk.py:864 -- Heredoc data extends a substitution into unrelated commands

return spanned if spanned[1] and spanned[0] > paren[0] else paren
Trigger: Submit (kill $(: <<'E'\n${\nE\nprintf 123); echo }; echo kirocrew) with \n representing newlines. is_denied → _is_self_kill → _bare_kill_raw_bodies reaches this selection; the quoted heredoc’s literal ${ incorrectly opens an expansion frame.
Outcome: The later echo } closes that frame, making the enclosing subshell’s ) the substitution boundary. The unrelated echo kirocrew enters the PID-lookup body and triggers a self-protection refusal, although Bash passes only 123 to kill and the base allows the command.
Anchor: defect
Fix: Skip heredoc data when tracking parameter expansions, or retain the legacy span when heredoc data prevents proving the longer boundary.

[BLOCK-MERGE-DOWNGRADED] e6c7944
[GPT-REVIEWED] e6c7944

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

F1 — LOW. The only outcome is a false refusal, and the user sees it. Bash itself still kills only 123. The span only feeds extractors that inspect text, as the docstring says (shell_normalizer_walk.py:856-858), and the refusal is the _SELF_NAME_RE match on the overlong body (argv_floor_self.py:832-836). Rewording the command recovers it; nothing escapes the scan.
The trigger needs every one of these together: a bare kill whose $( holds a quoted heredoc containing a literal ${, a later unrelated }, a later word naming kirocrew, and an enclosing ). The ${-aware walk then has to close later than the paren-only walk, which is the selection at shell_normalizer_walk.py:864. Commands shaped like that are very rare.
The real fix means adding here-document state to _close_paren_walk (shell_normalizer_walk.py:867): new state on a security tokenizer that only this one rare path needs. That costs more than a rare, visible, recoverable false denial is worth.

[ADJUDICATION] e6c7944d18a67a438c8c4b76770259e91ef9126c total=1 uphold=0 downgrade=1
DOWNGRADE F1 src/kiro_crew/security/shell_normalizer_walk.py:864 reason=disproportionate-remedy
[GPT-ADJUDICATED] e6c7944d18a67a438c8c4b76770259e91ef9126c

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

@bolichen97
bolichen97 enabled auto-merge (squash) November 5, 2026 20:13
@github-actions

github-actions Bot commented Nov 5, 2026

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

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

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

Reason: The change only lengthens a substitution body when the ${...}-aware walk closes later than the paren-only walk, so extractors get more text to scan. They never get less. No row came back as a confirmed refusal. The candidates probe ${...} words inside $(...), <(...), case and here-documents, plus PowerShell ${env:...} subexpressions.

TIGHTENING: _matching_close_paren substitution-span walk (shell_normalizer_walk.py), which now treats a ${...} parameter expansion as one word up to its matching } -- it refuses a payload hidden behind a ) in a default word: "the ) in $(: ${v:-)}; printf token) is the default value and the body runs on to the later )", via return spanned if spanned[1] and spanned[0] > paren[0] else paren.

ADJUDICATED: 18 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE: posix (15 rows) covers the bash grammar the walk now models: ${...} with defaults, prefix and suffix removal, ${#...}, $$/${$} dollar runs, case inside a body, process substitution, here-documents, and kill substitutions near the self-kill floor. windows (3 rows) covers PowerShell's $(...) subexpression around ${env:...}, including ${env:ProgramFiles(x86)}, where a (/) pair sits inside the braced word. The diff assumes nothing about paths, separators or executable names, so no any rows were needed. cmd.exe %VAR% syntax does not reach this walk, so no candidates were written for it.

[SCOPE-REVIEWED] e6c7944

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

@KiroCrewCaptain KiroCrewCaptain left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Approved: T1 fix, lanes and checks clean on this head.

@bolichen97
bolichen97 merged commit 165dbc0 into main Nov 5, 2026
100 of 102 checks passed
@bolichen97
bolichen97 deleted the fix/9181-shell-span branch November 5, 2026 21:44
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Nov 5, 2026
buluoray pushed a commit that referenced this pull request Nov 6, 2026
For one shell spelling the command check stopped reading a nested
command before the shell does, so the rest of it went unchecked and a
command the check refuses in its plain form was allowed. The check now
reads that spelling to the same end the shell does, and never reads
less than it did before.

(cherry picked from commit 165dbc0)
buluoray pushed a commit that referenced this pull request Nov 7, 2026
For one shell spelling the command check stopped reading a nested
command before the shell does, so the rest of it went unchecked and a
command the check refuses in its plain form was allowed. The check now
reads that spelling to the same end the shell does, and never reads
less than it did before.

(cherry picked from commit 165dbc0)
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.

security: _iter_shell_chars does not model parameter expansion or comments, so a literal ) inside them truncates every substitution span

2 participants