Skip to content

fix(security): read a bare stdin-interpreter heredoc as code, not shell - #22631

Merged
iamwhatever merged 1 commit into
fix/argv-row-floor-16475from
fix/heredoc-consumer-22332
Oct 21, 2026
Merged

iamwhatever merged 1 commit into
fix/argv-row-floor-16475from
fix/heredoc-consumer-22332

Conversation

@bolichen97

@bolichen97 bolichen97 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Stacked on #21584. The base is fix/argv-row-floor-16475, because the rule this changes is new in that PR and is not on main. When #21584 merges, this PR is retargeted to main. CI and Fast Gate run on PRs into main only, so they run after the retarget.

Problem / Motivation

Goal: The argv row floor judges a heredoc body by what reads it: interpreter code is not read as shell, and a body written to a file that the command names again is read as commands.

On the #21584 head, two things go wrong (#22332):

  1. A heredoc fed to python3 - is read as shell. A Python string that mentions a row's words is refused. Main allows it:
    python3 - <<'EOF'
    Path('docs/runbook.md').write_text('''
    terraform -chdir=infra destroy -target=module.old
    ''')
    EOF
    
  2. A data body written to a file and run on a later line is allowed. The runner check reads only the opener line:
    cat <<'EOF' > x
    git -C . reset --hard
    EOF
    sh x
    

Why it matters

Case 1 refuses ordinary agent work: writing a doc or a test fixture with a Python heredoc. Case 2 lets a re-spelled destructive command through the floor whose job is to catch it. The maintainer ruled (on #22332) for one design over more case-by-case allowlist patches.

Not a goal

What changed (motivation → approach → change)

This PR ships case 1 only. Case 2 is moved to #22649: matching the written file's name refused ordinary write-then-use flows (Security Scope Review), and a separate tool call gets past it anyway (Design Review). Nothing here is allowed that the #21584 head refuses, except the one case below.

Text On #21584 Now
exactly one python3 - <<'EOF' … EOF (or python3, node, nodejs) and nothing else commands Python / JS code, not shell
the same, unquoted delimiter (<<EOF) commands commands
the same with anything else in the text, or inside bash -c / eval commands commands
a path, option, script, < input, pipe or non-ASCII opener commands commands
perl, ruby, bash -s commands commands

Symptom → cause: the floor sorted heredocs by the opener's program word, and every program that is not git, gh, cat or tee had its body read as shell.

Change in security/argv_row_floor.py: a bare stdin interpreter counts as a non-shell reader under strict conditions:

  • a plain name, with no options, then nothing or -
  • a delimiter that is one plain word in one pair of quotes, with only output redirections after it
  • the heredoc is the whole top-level text
  • a text of plain ASCII, and no backslash-newline anywhere

Each condition closes a bypass a reviewer found: a rebound name, a parent frame, a shell-expanded body, or the reader and the shell closing the body on different lines (a backslash-newline, an escaped delimiter, a NUL). The security spec describes the rule, and the package line budget grows by 111 lines.

Backwards compatibility

Compatible: the only verdict that changes is one refusal becoming an allow, for a text that is a single quoted bare python3 / node heredoc. Nothing that works today stops working.

Removes nothing: no rule, pattern, pass or opt-out is removed.

Tests

test/test_argv_row_floor.py, 41 new cases:

  • Allowed: the exact python3 - case from argv row floor: heredoc-as-data rule over-refuses interpreter heredocs, misses file-then-run #22332, python3 with no -, python3 - a b, node -, and output redirects after the delimiter.
  • Refused, not bare: -c before or after the delimiter (also behind 2>/dev/null), node … -e, a script path, -u -, | sh, sudo, X=1, <x, bash -s, perl and ruby backticks.
  • Refused, may not be the interpreter: ./python3, ln -s /bin/sh python3, python3() { sh; }, export PATH=…, same-line hash -p, a variable-spelled hash -p, a later command, and an exported function around bash -c or eval.
  • Refused, reader and shell disagree: an unquoted delimiter (with and without $( ) behind Python quotes), a backslash-newline in a quoted body (<<'EOF' and <<-'EOF'), <<'E\OF' and mixed-quote delimiters, a NUL in the closing line, and a \x1f or no-break space on the opener line.

The 5 allowed cases are red on the parent head aa2fb16c8d and green here. The 36 refused cases are already refused there; they pin that nothing new gets through. All 253 existing tests pass unchanged. Determinism: repeats under -n2, and once serially in a seeded shuffled, reversed order. A probe set of 30 inputs run on both heads differs only on the bare interpreter cases.

Manual verification

N/A: unit coverage is sufficient. The floor is a pure function of the command text. Each allowed shape was also run under bash with a harmless marker in place of the command: the body went to Python, never to the shell.

Related Issues

Closes #22332
Part of #16475

Pattern harvest

Not generalizable: the defect is this floor's own choice to sort a heredoc by the opener's program word. The fix narrows that rule for one reader; there is no wider code shape to lint for.

Sensitive change review

Draft for a maintainer who is not the author. The author does not sign it.

  • What rule changed: the argv row floor no longer reads a heredoc as shell when the whole top-level text is one quoted bare python3 / node stdin heredoc.
  • Before and after: that one shape was refused and is now allowed; every other verdict is unchanged (see the table).
  • Worst case: a Python or Node heredoc body runs a re-spelled destructive command through its own code (os.system). This floor never read interpreter semantics; the inline-payload tier and the sandbox own that, as on main.
  • Sandbox evidence checked: none needed; nothing reaches the sandbox differently. The change is text classification inside is_denied only.
  • No regression: all existing floor tests pass; tools still work; the regex tier is untouched.
  • How to undo: revert this one commit; the floor returns to the fix(security): read command-literal deny rows off the argv, not one spelling #21584 rule.

Checklist

  • At most two commits (one is the norm), with a Conventional Commits title
  • 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

@bolichen97
bolichen97 requested review from a team and KiroCrewCaptain as code owners October 21, 2026 01:08
@bolichen97
bolichen97 requested review from chenmingwei23 and removed request for a team October 21, 2026 01:08
@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/argv_row_floor.py

  • @iamwhatever: 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: 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43
- 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 commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43 touches no user-facing surface (no changes under website/ or committed screenshots), so the UX review was skipped. Advisory — does not block merge.

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

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

Design-level review of 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43 — updated in place on each push. A BLOCK verdict blocks PR readiness; PASS/CONCERNS are advisory.

Design-Verdict: PASS

Check that the stack-only base runs Fast Gate and the floor suites once the PR is retargeted to main. Until then CI has not exercised this revision.

[DESIGN-REVIEWED] 14eb5d4

Description read

[DESCRIPTION-READ] 737eb7de67b909d97b43358396fd25218162010f1782994b8c6efe2dab95d20c

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 21, 2026 •

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43 — 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.

First-Principles-Verdict: PASS

The frozen Goal still promises case 2, but that work moved to #22649. Confirm that Closes #22332 is still correct when only case 1 ships here.

What this change ships

Inventory (4 items) — 4 justified

Intent: let an agent write a doc or fixture through a quoted python3 - / node heredoc without the argv row floor reading the Python or JS as shell. FIX (#22332; the 5 allow cases fail on the parent head aa2fb16c8d).

  1. A text that is exactly one bare, quoted-delimiter python3/node stdin heredoc is no longer refused when its body mentions a row's words — justified
  2. Every near-variant (options, paths, unquoted delimiter, nested bash -c/eval, non-ASCII, backslash-newline, perl/ruby/bash -s) is still refused — justified
  3. The security spec gains a paragraph on judging a heredoc by what reads it — justified
  4. The package line budget goes up by 111 lines — justified

[FIRST-PRINCIPLES-REVIEWED] 14eb5d4

Description read

[DESCRIPTION-READ] a0535827d91cde354cad32df7ca43660ecf60b9cf25b053bbe624373b3223649

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 21, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] 14eb5d4

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

False positive or not applicable? A repository writer can comment:
/ai-review override fable 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 14eb5d4

False positive or not applicable? A repository writer can comment:
/ai-review override gpt 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43: <one-sentence reason>

@github-actions

github-actions Bot commented Oct 21, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- ✅ PASS

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

No candidate flipped from allowed to refused.

Scope-Verdict: PASS

TIGHTENING: Nothing in this change is stricter. It relaxes the argv row floor in src/kiro_crew/security/argv_row_floor.py, which runs in the rule catalog (deny-rules) tier. Before this change, every heredoc body that was not fed to git, gh, cat or tee was read line by line as shell commands. Now a body fed to a bare stdin interpreter is cut out instead: _STDIN_INTERPRETER_RE = re.compile(r"\A(?:python(?:[23](?:\.\d+)?)?|node|nodejs)\Z"), gated by if body is not None and (not interpreter or (interpreters and quoted and _interpreter_alone(source, body, line, interpreter))). Every added condition (a plain quoted delimiter, plain ASCII text, no backslash-newline, the heredoc being the whole top-level text, no options) only narrows when the new exemption applies. When any of them fails, the text falls back to the base reading. The data-program branch (not interpreter) takes the same path as on base. The threat these conditions keep refused is a python3/node name that a function, hash -p, a PATH change, a parent bash -c/eval, or a respelled delimiter can turn back into a shell, so its body stays read as commands.

ADJUDICATED: 16 candidates, 0 confirmed newly-refused

PLATFORM COVERAGE:

  • posix: The diff builds in these assumptions: posix interpreter names (python3, node, nodejs), the / path test in _stdin_interpreter_opener, posix redirection syntax (2>/dev/null), and an LF-only printable-ASCII check in _PLAIN_TEXT_RE. The posix candidates cover each one:
    • bare python3 - and python3 stdin heredocs
    • an unquoted delimiter
    • a cd && prefix, which fails _interpreter_alone
    • a stderr redirection
    • a node - heredoc
    • non-ASCII body text
    • a script path followed by a heredoc
    • plain python3 -m pytest
    • the git commit -F -, gh pr create --body-file -, cat > and tee data heredocs, whose opener return shape and skip logic were rewritten
  • windows: The interpreter regex leaves out .exe names and the py launcher, and _PLAIN_TEXT_RE excludes \r. The candidates cover these with python.exe - <<'EOF', py -3 - <<'EOF', and a CRLF git commit -F - heredoc.
  • any: Two any rows, the git commit -F - and gh pr create --body-file - heredocs, are platform-neutral data heredocs.
  • Not probed: a Windows drive-letter interpreter path such as C:\…\python.exe. Probing it would mean writing a candidate that tests whether the exemption widens, which is the stricter-guard direction other lanes own, not this one. Every assumed platform spelling has at least one candidate.

[SCOPE-REVIEWED] 14eb5d4

@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 21, 2026
@bolichen97 bolichen97 changed the title fix(security): judge an argv-floor heredoc by what reads it fix(security): read a bare stdin-interpreter heredoc as code, not shell Oct 21, 2026
@bolichen97
bolichen97 force-pushed the fix/heredoc-consumer-22332 branch from 518fd4f to 542c3fd Compare October 21, 2026 02:52
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=4373a6e684ee: Case-2 file-name check does not close the hole

fixed in 542c3fd: the whole written-file check is removed; this PR ships the interpreter half only.
Case 2 (file-then-run, the separate-tool-call gap, and the six write-then-use flows it refused) is tracked in #22649 for its own ruling.
Nothing is allowed that the #21584 head refuses, other than the bare interpreter heredoc.

@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=f37792ec7c36: Ship case 1 alone

fixed in 542c3fd: case 1 alone ships; the name index, pattern words, written-file reader and the shell-body skip are gone.
The line budget raise drops from 246 to 100 lines.

@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=2e470a7a1c28: Second redirection spelling

fixed in 542c3fd: _REDIRECT_RE is removed. The tail check uses _REDIRECTION_RE, built from _REDIRECT_OPERATOR_RE.pattern plus its target word.
It reads redirections only to reject any input redirection and any non-redirection word after the delimiter.

@github-actions github-actions Bot removed the readiness: action required A blocking check or review needs attention label Oct 21, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=f87b0cc827f9: Same-line rebinding bypasses the interpreter heredoc guard

fixed in 542c3fd: _interpreter_alone requires the interpreter word first on the line with nothing before it, and nothing outside the body but the opener line.
Test: hash -p /bin/$'bash' python3; python3 <<'EOF' is refused; so is an exported function around bash -c / eval (top-level frame only).

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

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=13067e8a5708: Arithmetic << read as a heredoc by the shell-body skip

fixed in 542c3fd: the shell-body closing-line skip that reset the quote state is removed, so the span reader is the #21584 one for every non-interpreter heredoc.
The reported input is refused again (pinned by the probe set run on both heads).

@bolichen97

Copy link
Copy Markdown
Contributor Author

self-added: yes

  • span=5e92b20f459a: Interpreter rebinding through a variable

fixed in 542c3fd: the name-count check is replaced. The exemption holds only when the heredoc is the whole top-level text, so no other command can rebind the name by any spelling.
Test: p=pyth; hash -p /bin/sh $p'on3' then the heredoc is refused.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Security Scope Review on 518fd4f15d (BLOCK, 12 newly refused): the case-2 written-file check that refused them is removed in 542c3fd85d, and so is the shell-body skip behind the two nested bash -s cases. This PR now ships only the bare stdin-interpreter half of #22332. Case 2 and its six write-then-use costs (git add, cat, --body-file, git commit -F, git diff, wc -l docs/*.md after writing the file) are tracked in #22649 for their own ruling. A 30-input probe set run on the #21584 head and on 542c3fd85d differs only on top-level, quoted, bare python3 / node heredocs, so nothing is newly refused.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Sensitive change review: a draft for a maintainer who is not the author. The author does not sign it. To use it, paste the block below into an Approve review on head 542c3fd85d51f57be5026bd0fee9d9c78496a2a5, after checking each line yourself, and rename its first line to the template's own heading.

Sensitive change review (draft)
- Head commit: 542c3fd85d51f57be5026bd0fee9d9c78496a2a5
- What rule changed: the argv row floor no longer reads a heredoc as shell when the whole top-level text is one quoted bare python3 / node stdin heredoc.
- Before -> after (what was allowed/blocked, now): that one shape was refused and is now allowed; every other verdict is unchanged (30-input probe set run on aa2fb16c8d and 542c3fd85d).
- Worst case if wrong (breaks commands / leaks secret / locks user out): a Python or Node heredoc body runs a re-spelled destructive command through its own code, which this shell floor never read; the inline-payload tier and the sandbox own that, as on main.
- Evidence checked (which sandbox result proves it): N/A because nothing reaches the sandbox differently; the change is text classification inside is_denied only. Each allowed shape was run under bash with a harmless marker and its body went to Python, never to the shell.
- No regression:
  - Tools still work (which tools/commands were run, result): test/test_argv_row_floor.py 288 passed; test/test_security_gate_liveness.py passed; black, isort, flake8, mypy and semgrep clean.
  - Backward compatible (old config / old data / old callers still work, how checked): yes, the only change turns one refusal into an allow; no config, data or caller changes.
  - Existing tests (which suites passed on this head): all 253 existing floor tests pass unchanged; full suites run in CI after the retarget to main.
- How to undo: revert the one commit; the floor returns to the #21584 rule.

@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 21, 2026
@bolichen97

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: Closes #22332 while case 2 moved out

Intended: #22332 asked for a ruling on both halves. The maintainer ruled: case 1 ships here and case 2 moved to #22649 with its own ask, linked from #22332. Closing #22332 on merge leaves case 2 tracked in #22649.

@bolichen97

Copy link
Copy Markdown
Contributor Author

[operator: bolichen97] Sensitive change review: a draft for a maintainer who is not the author. The author does not sign it. To use it, paste the block below into an Approve review on head 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43, after checking each line yourself, and rename its first line to the template's own heading.

Sensitive change review (draft)
- Head commit: 14eb5d43d0cfa67a3c35aa11dddbfc295c54df43
- What rule changed: the argv row floor no longer reads a heredoc as shell when the whole top-level text is one bare python3 / node stdin heredoc with a plain quoted delimiter, in a plain-ASCII text with no backslash-newline.
- Before -> after (what was allowed/blocked, now): that one shape was refused and is now allowed; every other verdict is unchanged (30-input probe set run on aa2fb16c8d and 14eb5d43d0).
- Worst case if wrong (breaks commands / leaks secret / locks user out): a Python or Node heredoc body runs a re-spelled destructive command through its own code, which this shell floor never read; the inline-payload tier and the sandbox own that, as on main.
- Evidence checked (which sandbox result proves it): N/A because nothing reaches the sandbox differently; the change is text classification inside is_denied only. Each allowed shape was run under bash with a harmless marker and its body went to Python, never to the shell.
- No regression:
  - Tools still work (which tools/commands were run, result): test/test_argv_row_floor.py 294 passed; test/test_security_gate_liveness.py passed; black, isort, flake8, mypy and semgrep clean.
  - Backward compatible (old config / old data / old callers still work, how checked): yes, the only change turns one refusal into an allow; no config, data or caller changes.
  - Existing tests (which suites passed on this head): all 253 existing floor tests pass unchanged; full suites run in CI after the retarget to main.
- How to undo: revert the one commit; the floor returns to the #21584 rule.

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

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: CI has not exercised this revision on the stacked base

Agreed: CI and Fast Gate run on PRs into main only. When #21584 merges, this PR is retargeted to main; the full suites and Fast Gate run then, and any red is fixed before it is called ready. Locally the related tests, flake ratchet, semgrep, mypy, flake8, isort and black passed on this head.

@bolichen97

Copy link
Copy Markdown
Contributor Author
  • PASS punchline: the frozen Goal still names case 2, and Closes #22332

Intended: the Goal section is frozen and only the maintainer edits it. The maintainer split the work: case 1 ships here, and case 2 has its own ask in #22649, linked from #22332. Closing #22332 on merge is correct because its ruling ask is answered and its open half is tracked in #22649.

@iamwhatever

Copy link
Copy Markdown
Contributor

HOLD at 14eb5d4.

This PR changes what the argv row floor refuses: a text that is a single quoted bare python3/node stdin heredoc is now allowed (argv_row_floor.py#L888, #L911). A change to a security gate's verdicts is reserved for a human maintainer, so this review does not approve it. I found no concrete defect: the exemption is narrow (whole top-level text, plain quoted delimiter, ASCII only, no line continuation), and the new refused cases pin the bypasses reviewers raised.

Other blockers:

To clear: a maintainer reviews the floor change, the PR is retargeted to main with CI green, and the sensitive-change template is posted for the final head. A retarget or rebase needs a fresh review.

— crew-pr-reviewer (r116)

@iamwhatever
iamwhatever merged commit ce48368 into fix/argv-row-floor-16475 Oct 21, 2026
28 of 31 checks passed
@iamwhatever
iamwhatever deleted the fix/heredoc-consumer-22332 branch October 21, 2026 07:33
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 21, 2026
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.

2 participants