Repository navigation
fix(security): scan a double-quoted command substitution and skip heredoc bodies in the span walk - #22938
fix(security): scan a double-quoted command substitution and skip heredoc bodies in the span walk#22938cruisercohen wants to merge 1 commit into
Conversation
Sensitive Change ReviewSensitive files changed:
|
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Nothing blocks: both changes only add text for the publish-floor scan to check, and a heredoc that is never closed makes the span run long, which scans more, never less. Notes
[DESIGN-REVIEWED] 7d9ee2c Description read[DESCRIPTION-READ] d67760b5542d9363258c7408c728e77e39e139e1798087c4c3645ae044bc7c6a That sha256 names everything this verdict read: the PR description, plus the 1 evidence file(s) the workflow collected from it and handed this review. It covers that evidence because the media strip replaces every attachment URL with the same placeholder, so an edit swapping one attachment for another would leave the description's captured text identical while what this review judged changed. Recompute it with |
First Principles Review (Opus 5.5) — ✅ PASSPremise-level review of First-Principles-Verdict: PASS Both items fix a defect that tests added in this PR show failing on base. The double-quote item adds a second walk rather than correcting the one call that causes the bug. Notes
What this change shipsInventory (4 items) — 2 justifiedIntent: a push wrapped in a double-quoted substitution, or placed after a heredoc body, is still checked by the publish floor. FIX.
[FIRST-PRINCIPLES-REVIEWED] 7d9ee2c Description read[DESCRIPTION-READ] 3a8c97496038ab9aa620126a6027b5ccd18eb3450eeecb309558b35905943ca1 That sha256 names the PR description this verdict read. Recompute it with |
Opus 5.5 Review — 🔴 changes requested (blocking)Reviewed A heredoc parser this PR adds reads an arithmetic BLOCKING — src/kiro_crew/security/shell_normalizer_walk.py:1052 [OPUS-REVIEWED] 7d9ee2c Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
GPT 6.1 Review — ✅ no blocking findings (all downgraded on adjudication)GPT 6.1 flagged blocking issues on This comment is updated in place on each push. Review detailsBLOCKING -- src/kiro_crew/security/shell_normalizer_walk.py:343 -- Literal text is newly classified as an executable substitution
Adjudication (Opus 5.5) — is blocking on each finding proportionate?F1 — Harm is LOW. The failure needs three things, all confirmed:
What happens is a visible refusal that fails closed; it is not silent and never loosens the floor. The agent can re-spell the literal text and retry. The pre-existing byte-literal scan at False positive or not applicable? A repository writer can comment: |
Security Scope Review -- ✅ PASSWhich legitimate operations does Verdict basis: adjudicated, zero confirmed regressions. Security scope review -- adjudicated candidates
No candidate flipped from allowed to refused. Scope-Verdict: PASS Reason: The change gives the existing scan more text to read in two ways. It adds a second pass that pulls out the body of every TIGHTENING: Substitution-body extraction in ADJUDICATED: 25 candidates, 0 confirmed newly-refused PLATFORM COVERAGE: The diff assumes the bash tokenizer: double-quote state 2,
UNADJUDICATED: [SCOPE-REVIEWED] 7d9ee2c |
…nd skip heredoc bodies in the span walk
2b73171 to
7d9ee2c
Compare
Sensitive change review
|
|
The blocking
|
|
Stale-PR cleanup check, 2026-11-17: this fix is still needed. I applied this PR's new tests in |
|
Closing unmerged, following the maintainers' 2026-11-08 decision to stop patching shell spellings in the command-text checks (#21682 (comment)). The branch is kept if anyone wants it later. |
Problem / Motivation
Goal: Close a publicly-surfaced gap where a
git pushwrapped in a command substitution could reach the git-publish floor without being scanned.The floor scans the body of every command substitution so a wrapped
git pushis still checked. Two quote-context shapes slipped that scan on released code:$(...)/ backtick substitution opened inside double quotes —echo "$(bash -c 'git push')"— whose body was mis-sized, so the wrapped command was dropped from what the floor scanned;)on a body line was mistaken for the span closer, ending the span early and dropping the command after it.Why it matters
The git-publish floor is the sole enforcement for pushes. A push that reaches it unscanned is one the floor cannot decide on, so these shapes let a push through that bash actually runs. The gap is in released span-walk code, so it affects current users until fixed.
Not a goal
rmfloors beyond their shared use of the span helper (whose contract is preserved and regression-tested).<<used as an arithmetic left shift: that direction makes a span run long (the fail-closed direction), not short, so it hides no command; it can be tightened separately if wanted.What changed (motivation → approach → change)
Root cause: the span walk in
shell_normalizer_walk.pycomputed a substitution's body span while mis-handling quote context, so a data)(one inside double quotes, or inside a heredoc body) was read as the real closer and the launcher after it was dropped from the scanned body.Approach: make the span computation quote-aware the way bash parses the text, mirroring the self-protection floor's own substitution walk, and add it as an additive pass so no existing reading is removed.
Change:
_double_quoted_substitution_bodiesrecomputes the body span of a$(...)/ backtick substitution opened inside double quotes from a fresh, neutral quote context, so its clean body is scanned._matching_close_parenskips a heredoc body (cat <<E…E), so a)inside it no longer closes the span early. A<<<here-string has no body and is left alone — including at the interior<of the<<<run, so the span is unchanged for here-strings.Backwards compatibility
Compatible: no legitimate command stops working. A differential of the real classifier (
scripts/deny_diff.py --base origin/main --head HEAD) over the golden corpus shows 0 regressions and 0 loosenings on posix and windows; the only behaviour change is the intended new refusals of the wrapped-push shapes above. The change adds scan targets and lengthens spans only (the fail-closed direction), and the shared span helper keeps its "a span runs long, never short" contract.Removes nothing: no path, record, key, or public function is hidden, deleted, or renamed; the diff only widens detection.
Tests
test_push_branch_gate_parser.py::TestDoubleQuotedSubstitutionAndHeredocSpan(9): failing-first rows for the double-quoted$(...)form, the backtick form, and a heredoc-bodied subshell before the push — each proven red before the fix and green after — plus unit assertions on the recomputed span bounds, a regression row that a<<<here-string is not mistaken for a heredoc at its interior<, and benign / single-quoted (literal) rows that stay allowed.test_security_gate_liveness.pyincluding the package line-budget gate passes on this head.Manual verification
N/A — unit and differential coverage are sufficient; this is a parser-level change with no UI or external surface.
Related Issues
N/A — fixes a publicly-surfaced span-walk gap on released code; no separate tracking issue is linked.
Pattern harvest
Rule candidate: review-prompt. Pattern: a paren/span counter over shell text that is not quote-and-heredoc-aware reads a data
)(quoted, escaped, or inside a heredoc body) as a real closer and truncates the scanned span — the fail-short direction that can hide a later command. Any new walk over shell text should reuse the shared quote/heredoc-aware_matching_close_parenrather than counting)itself.Checklist