Repository navigation
fix(security): a bare opener in a redirect target is not grammar (#8634) - #8672
Conversation
Design Review (Fable 5) — ✅ PASSDesign-level review of Design-Verdict: PASS A real deny-scan bypass at the agent boundary, closed by a strictly narrowing one-line rule whose fail-closed monotonicity is provable from the diff, with residuals honestly documented. [DESIGN-REVIEWED] fb2662f |
GPT 5.6 Review — ✅ no blocking findingsGPT 5.6 completed its review of This comment is updated in place on each push. Review detailsNo findings. False positive or not applicable? A repository writer can comment: |
First Principles Review (Fable 5) — ✅ PASSPremise-level review of The change is a one-line rule tightening in First-Principles-Verdict: PASS A measured deny-scan bypass is closed with one subtractive rule, no new surface, and the deeper cause and unfixed siblings are declared, counted, and tracked. What this change shipsIntent: stop a quoted
The fix sits at mechanism level; the nameable cause (quote-preserving tokenization at the frame level) and the 3 sibling scanners sharing the #8150 root cause ( [FIRST-PRINCIPLES-REVIEWED] fb2662f |
Opus 4.8 Review — ✅ no blocking findingsReviewed Verdict parsed from the review's SHA-scoped output markers for commit False positive or not applicable? A repository writer can comment: |
5746aa4 to
fb2662f
Compare
|
Disposition — First Principles BLOCK ("delete the _quoting_step wiring; keep only the depth-zero rule") on 5746aa4: ACCEPTED, subtraction taken in full on head fb2662f. Verified on-source before acting, then shipped exactly the demanded subtraction. The
|
|
Disposition — Design watch item "the documented residual needs a filed issue, not a docstring note" on 5746aa4: ACCEPTED, resolved on head fb2662f. The residual class (quoted |
|
Disposition — Design watch item " The First Principles lane proved the wiring had zero quote-bearing production callers and actively misread data quotes as grammar, so the helper and all its guards were subtracted rather than the pact strengthened. This PR no longer carries any code from #8579; the helper lands there with its real consumer. |
Problem / Motivation
_output_redirect_scanfinds where an output redirect's target ends so the shell-command security gate can tell a redirect from a script path. Its span walk counted every(/{as a depth opener. The tokenizer that feeds it resolves quoting, so a quoted(— one filename character to bash — arrived bare, opened a span that never closed, and the target ran past the<<</<<operator that should have ended it. The program arriving on stdin was then never scanned.Measured in bash — each of these runs the here-string program while the gate returned
is_denied = None:Third site of the #8150 defect class (a delimiter counted in text where quoting decides whether it is a delimiter at all).
Why it matters
A program arriving on stdin via a here-string bypasses the deny scan entirely — the exact failure mode the scanner's own docstring describes for a glued heredoc marker, reached through a quoting spelling. The end-to-end consequence is real:
python3 2>'a)(b'<<< 'from kiro_crew.cli import main; main()'was allowed on main and is denied with this fix.What changed (motivation → approach → change)
The issue proposed routing the walk through #8150's shared
_quoting_steprule. Two review rounds subtracted that to a single, smaller rule:_self_token_framesshlex-resolves quoting, so the production tokens arrive de-quoted (2>'a)(b'<<<→2>a)(b<<<) and there are no quotes left to track.2>"a'b"→2>a'b), and reading it as grammar consumed the<<<to end-of-text — reopening the defect in the opposite direction. Its subtraction demand was verified and taken.What ships is one rule: at depth zero, only a
$-prefixed opener ($(,${,$(() starts a substitution span. A bare(mid-word is never grammar in a command that runs — unquoted it is a bash syntax error, so the only executable spelling that reaches the scan bare is a quoted filename character. A bare{is an ordinary filename character (measured). Inside a substitution every opener still counts (a nested subshell closes with its own)). Quote characters are stepped over as data.Not changed, per the issue's scope: where a redirect target begins, the unterminated-target fallback, and the sibling scanners (
_substitution_depth_delta,_is_self_kill,_operand_span_end— #8633's territory).Residuals, documented in the code: a quoted
'$('or a quoted backtick in a filename de-quotes to the same characters as real grammar and still holds/toggles a span — indistinguishable without the quoting the tokenizer already destroyed. Closing that class needs quote-preserving tokenization at the frame level (follow-up issue, see comments).Tests
TestOutputRedirectScanQuoting(6 tests), every assertion measured against real bash; reverting the one-line rule is caught by 4 distinct tests:is_denied()with the exact production spellings (allNoneon main).2>a)(b<<<,2>a{b<<<x,$((arith))still spans).(,{; ANSI-C$'a(b'.2>a'b<<<xkeeps its boundary;$$', backtick-interior quote unchanged).2>$( (x)>y ),2>`echo>x`,${x:->}, unterminated quote, trailing backslash._python_reads_stdinon both token forms.By construction the rule only ever opens fewer spans than main, so the target can only end earlier-or-equal — an operator main exposed can never be hidden by this change.
Manual verification
All bash ground-truth probes in the docstrings/tests were executed against real bash (file creation + program execution observed):
> 'a(b' <<<, glued2>'a)(b'<<<,2>a{b<<<,2>"a'b"<<<,2>$'a\')', and the syntax-error control2>a(b.Related Issues
Closes #8634
Refs #8150
Pattern harvest
Rule candidate: review-prompt
Pattern: a fix must be proven at the public verdict level on the tokens production actually carries — the tokenizer between the entry point and the helper can both destroy the information a rule keys on (quotes stripped) and deliver that information as data the rule must not re-interpret as grammar (quotes surviving as filename characters).
Checklist
feat|fix|docs|refactor|perf|test|chore|ci|build|revert: ...)