Skip to content

fix(approvals): make redirect detection in trusted patterns quote-aware - #19968

Merged
javenciu merged 2 commits into
mainfrom
fix/19319-quote-aware-redirect-detection
Oct 14, 2026
Merged

javenciu merged 2 commits into
mainfrom
fix/19319-quote-aware-redirect-detection

Conversation

@javenciu

@javenciu javenciu commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A trusted program grant such as git *, gh * or grep * covers a command whose only > sits inside a quoted argument without asking again, while every redirect bash really performs still needs a grant that spells it.

A program grant does not cover a write redirect: redirect_outside_grant (src/kiro_crew/trust_patterns.py:255) declines the grant for a segment that writes through one. The write test it uses, writes_through_redirect (src/kiro_crew/security/readonly_bash.py:1488), counts every > that is not a discard idiom, quoted or not. So git log --format='%h -> %s', gh api repos/o/r/pulls --jq 'select(.n > 1)' and grep -E "a>b" file.txt each raise an approval card under a grant that should cover them, as #19319 describes.

Why it matters

Format strings, jq filters and regular expressions carry > routinely, so a user who trusted git or gh keeps answering cards for commands that write nothing. Each needless card teaches the user to approve without reading, which weakens the card that guards a real redirect.

Not a goal

  • The read-only tier. _classify_bash keeps refusing every >; only the trusted-pattern tier changes.
  • Full bash parsing. Where the quoting is not followed (heredocs, comments, ANSI-C $'...', ${...}, Windows) every > keeps counting, as on main.
  • Reading a > inside [[ ]] or (( )) as a comparison. An unquoted one there still counts as a write.
  • The substitution check in split_command_segments (_COMMAND_SUBSTITUTION_RE, src/kiro_crew/trust_patterns.py:33). It also ignores quotes, so grep '>(' f or grep '$(' f matches no grant at all. That guard decides whether a command is matched in the first place, not whether a matched command writes, and loosening it is a separate decision.

What changed (motivation → approach → change)

Symptom: a quoted > raises the "trusted pattern not applied" card. Root cause: the trusted-pattern tier hands raw segment text to a write rule that does not know about quoting. Change, all in src/kiro_crew/trust_patterns.py:

  • _literal_gt_offsets (src/kiro_crew/trust_patterns.py:292) walks the whole command with bash's rules for '...', "..." and a backslash outside single quotes, and returns the offset of each > bash reads as text. A quote left open returns an empty set, so every > counts.
  • _mask_quoted_separators (src/kiro_crew/trust_patterns.py:154) masks an escaped > as well as the separators inside quotes. An escaped > is text for the splitter too, so the redirect mask (_REDIRECT_RE, src/kiro_crew/trust_patterns.py:27) never reads it as the start of >&, and the & after it separates commands. An unescaped 2>&1, >&2 or &>file stays one redirect, as before.
  • _segment_writes (src/kiro_crew/trust_patterns.py:326) reads quote state once over the whole command, not per segment, because the splitter also cuts at a separator escaped inside double quotes (_mask_quoted_separators, src/kiro_crew/trust_patterns.py:154), so a segment can start inside quotes an earlier one opened. It finds each segment at its offset in the command, and _writes_through_redirect (src/kiro_crew/trust_patterns.py:348) applies the unchanged writes_through_redirect to the segment without the > at those offsets; quotes and backslashes stay in place, so a discard idiom (>/dev/null, 2>&1) ends its word exactly where it did before. A segment that is not cut verbatim from the command is read, with every later one, with every > counted.
  • The empty set, with every > counted, also applies when the whole command contains one of _UNMODELLED_QUOTING (src/kiro_crew/trust_patterns.py:289: <<, #, $', ${), or on Windows, where kiro-cli runs the command with PowerShell and a backslash is not an escape (src/kiro_crew/name_grant.py:73, src/kiro_crew/name_grant.py:99). The constructs are searched in the whole command rather than the segment, because a heredoc body or a comment can sit in a later segment than the << or # that changes its quoting.
  • The reading is used at all three places that ask the question: each segment in redirect_outside_grant (src/kiro_crew/trust_patterns.py:276), whether a pattern spells a write in _covers_write_redirect (src/kiro_crew/trust_patterns.py:370), and each part in timed_grant_deadline (src/kiro_crew/trust_patterns.py:557). Without the last one, a chat-long git * grant and a quoted > would be approved by one function and given an already-passed deadline by the other.
  • docs/system-specs/modules/security.md: the redirect paragraph states the quote-aware rule, that quote state is read over the whole command, its fallbacks, and that the read-only tier is unchanged.

Rejected: making writes_through_redirect itself quote-aware. It states the read-only classifier's rule, which this issue does not ask to loosen.
Rejected: looking for the unmodelled constructs per segment. A heredoc body lands in a later segment than its <<, and a quote walk over that segment alone sees balanced quotes around a redirect bash runs (the heredoc case below).
Rejected: walking quotes per segment. echo "x\|ls '" > out '\' is cut at the \| inside the double quotes, and a walk that starts the second segment unquoted reads its > as single-quoted text while bash writes out.
Rejected: counting every > in any command with a backslash before |, &, ; or a newline. It closes the same case but keeps prompting for quoted > the whole-command reading gets right, such as echo "x\|ls '>'".

Backwards compatibility

Breaking: a trusted pattern whose only > sits inside quotes (jq '.a > 1' *) no longer counts as spelling a write redirect, so a command it matches that also writes (jq '.a > 1' x > out) shows the approval card instead of auto-approving. Nothing is blocked. Writer sweep on origin/main @ 3791b79: the "trust this command" card stores exact_trust_pattern of the command (src/kiro_crew/dashboard/chat_handlers.py:10442), which keeps the command's own quoting, so an exact grant still covers its own redirect (test_an_exact_grant_for_the_line_covers_its_redirect); the "trust this program" card stores base_trust_patterns (src/kiro_crew/dashboard/chat_handlers.py:10462), which contain no >; acquire_worker_slot in src/kiro_crew/apps/worker_slots.py takes app-supplied patterns, and no app in the tree passes any.

Reader: src/kiro_crew/dashboard/chat_runner.py:_redirect_outside_grant -- chat -- the trusted-pattern tier declines and the card is shown, as for any uncovered redirect; test_a_quoted_gt_in_a_pattern_does_not_spell_a_write
Reader: src/kiro_crew/dashboard/chat_runner.py:_timed_grant_deadline -- chat -- reads coverage through the same helper, so the deadline matches the decision; test_a_quoted_gt_is_covered_by_a_chat_long_base_grant

Security

Fail-closed: compared with main, the only commands newly auto-approved are ones whose every non-discard > is literal under bash's quoting, in a command with no <<, #, $' or ${, on a POSIX host. A case the walk cannot decide (an open quote, an unmodelled construct, Windows) keeps the current rule. On the pattern side the change only removes coverage.

Redirects that still need a grant spelling them, pinned by test_a_redirect_bash_runs_still_needs_a_grant_that_spells_it (\n is a newline):

Command Why it is a write
echo 'a' > b, echo "a > b" > c the last > is outside quotes
echo hi >> out.txt, &> out.txt, 2> err.txt, 2>&1 > out.txt, >| out.txt unquoted operators
echo \"a > out\", echo \'a > out\' the quote is escaped, so the > is not quoted (bash writes out")
echo 'a\' > out a backslash escapes nothing inside single quotes
ls && echo '>' > out, ls; echo '>' > out after a separator
echo 'a > b, echo "a > b a quote left open: not decided, so counted
cat <<EOF\n'\nEOF\nls > out '\n' heredoc: the body's ' is text to bash
ls # '\nls > out # ' comment: the ' after # is text to bash
echo $'\'' > out \' ANSI-C quoting: \' is an escaped quote inside $'...'
echo "${x:-'"'}" > out \' the quotes inside ${...} pair differently
echo $(echo '>' > out) a substitution matches no grant at all (unchanged)

For each of the last five rows, bash 5.2 writes out while a plain quote walk sees the > inside quotes.

Two more shapes, each pinned by its own test, with grants echo * and ls *:

  • echo "x\|ls '" > out '\', and the same with \;, \& or a backslash-newline: the splitter cuts at the escaped separator inside the double quotes, so the second segment starts inside them and its > is outside every quote (test_a_cut_inside_double_quotes_does_not_hide_a_redirect).
  • echo a \>&2, echo 1\>&2, echo a \>& touch out, echo a \>&touch out: an escaped > is text for the splitter too, so the & after it separates commands, as bash reads it, and the command after the & needs a grant of its own (test_an_escaped_gt_is_text_for_the_splitter_too).

Tests

In short: the issue's three commands and the other quoted or escaped spellings stay covered by a base grant; every redirect bash runs still needs a grant that spells it; red on main and green on the fix, three runs each, and each fallback has a mutant that its own case catches.

test/test_trust_patterns.py::TestQuotedRedirectIsText:

  • test_a_quoted_or_escaped_gt_stays_covered: the issue's three commands, echo "a > b", echo a \> b, echo "a \" > b", echo 'a'\''b > c', echo 'a\' 'b > c', echo hi 2'>'file, echo '>' 2>/dev/null, echo '>|' x, ls && grep 'a > b' f, echo "a\>&b".
  • test_a_redirect_bash_runs_still_needs_a_grant_that_spells_it: the first table above, plus a heredoc whose quotes balance over the whole command (cat <<EOF\nls '\nEOF\nls > out '\').
  • test_a_cut_inside_double_quotes_does_not_hide_a_redirect and test_an_escaped_gt_is_text_for_the_splitter_too: the two shapes listed under Security.
  • test_an_unescaped_redirect_operator_stays_one_segment: echo a 2>&1, echo a >&2, echo a &>out, echo a 2>/dev/null and echo a \\>&2 (an escaped backslash, then >&2) each stay one segment, with the same write verdict as before.
  • test_a_segment_is_read_where_it_is_cut: in echo 'x | cat > out' | cat > out and its double-quoted form, the second segment's text also sits inside the first one's quotes; it is read at its own offset, so its > is a write and the quoted one is not.
  • test_a_segment_not_cut_verbatim_reads_every_gt: a segment that is not a verbatim cut of the command counts every >.
  • test_a_redirect_inside_a_substitution_matches_no_grant, test_on_windows_every_gt_counts, test_a_quoted_gt_in_a_pattern_does_not_spell_a_write.

test/test_trust_timed_grants.py::TestTimedGrantDeadline: test_a_quoted_gt_is_covered_by_a_chat_long_base_grant (the deadline reads coverage the same way) and test_a_cut_inside_double_quotes_does_not_hide_a_redirect.

The tests that assert the POSIX reading pin platform_compat.IS_WINDOWS to False with patch.object inside the test, so they give the same verdict on the Windows runner; test_on_windows_every_gt_counts pins it to True. With IS_WINDOWS forced True around every test, the pinned tests pass in 3 of 3 runs.

Red on main (trust_patterns.py from origin/main, same tests, three runs):

22 failed, 74 passed

The cut-inside-quotes tests pass on main, which counts every >, and guard the reading this change adds. Green on the fix, three runs: 96 passed. Mutants, each restored afterwards, each caught: quote walk removed (the issue cases fail); quotes walked per segment, with or without the constructs searched in the whole command (the cut-inside-quotes tests); an escaped > left to the redirect mask, or counted as a write again before & (the escaped-operator test); an escaped > inside double quotes read as a redirect (echo "a\>&b"); each segment looked up from the start of the command (the repeated-segment test); the verbatim-cut check removed (its test); an open quote read as text (echo 'a > b, echo "a > b); backslash escape removed (echo a \> b, echo \"a > out\" and three more); backslash escaping inside single quotes (echo 'a\' 'b > c'); each of the <<, #, $' and ${ checks removed (its own row of the table); the Windows check removed (test_on_windows_every_gt_counts); the pattern side or the deadline left on the old rule (their own tests).

The new tests, repeated: 20 runs at -n0 and 10 at -n 4, every run green.

Neighbours, all green: at -n0, test/test_trust_patterns.py, test/test_trust_timed_grants.py, test/test_tool_permission.py, test/test_trust_reads.py, test/test_readonly_bash_assigning_expansions.py, test/test_readonly_bash_common_filters.py, test/test_security_gate_liveness.py, test/test_transport_permission_floor.py, test/test_chat_utils.py, test/test_chat_handlers_composition_contract.py, test/test_chat_runner_composition_contract.py, test/test_denied_commands_security.py; at -n 4, every other test file that names the module or its two entry points: test/test_acp_client.py, test/test_acp_runtime.py, test/test_chat_runner_coverage.py.

Manual verification

Every command in the table and in test_a_quoted_or_escaped_gt_stays_covered that can run locally was run with bash -c in an empty directory (GNU bash 5.2.15). The covered commands create no file. echo 'a' > out, echo "a > b" > out, echo 'a\' > out, echo "it's" > out, echo hi >| out and the heredoc, comment, $'...', ${x#...} and ${x:-...} rows create out; echo \"a > out\" creates out". Each command in the second list (echo "x\|ls '" > out '\' and its \;, \& and backslash-newline forms, echo a \>& touch out, echo a \>&touch out) creates out. Under bash -x, echo a \>&2, echo 1\>&2, echo a \>& touch out and echo a \>&touch out each run as two commands, cut at the &; echo a 2>&1, echo a >&2, echo a &>out, echo a 2>/dev/null and echo a \\>&2 each run one echo, and of these only echo a &>out creates a file. echo 'x | cat > out' | cat > out and its double-quoted form create out.

Screenshots / video

N/A: the diff touches no frontend surface.

Related Issues

Fixes #19319
Refs #19212

Pattern harvest

Rule candidate: review-prompt
Pattern: a shell operator test (>, |, ;, #) run over raw command text without tracking quotes and escapes, or with a quote walk applied where bash quotes differently (heredoc bodies, comments, $'...', ${...})

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

Contributed under the project's Apache-2.0 license.

A trusted program grant such as `git *` stops covering a command that
writes through a redirect. The check read every `>` as a redirect, so a
`>` inside a quoted argument (`git log --format='%h -> %s'`, a jq filter,
a grep pattern) also raised an approval card under a grant that covers
it.

The trusted-pattern tier now drops the `>` characters bash reads as text
(inside single or double quotes, or after a backslash outside single
quotes) before applying the read-only classifier's write rule. The same
reading applies to the segment check, to whether a pattern spells a
write redirect, and to the timed-grant deadline, so the three agree.

Every case it cannot follow keeps the old rule, with each `>` counted:
a quote left open, a command carrying a heredoc, a comment, ANSI-C
`$'...'` or `${...}`, and Windows, where the shell is PowerShell and a
backslash escapes nothing. The read-only tier is unchanged.

Fixes #19319
@javenciu
javenciu requested review from a team and KiroCrewCaptain as code owners October 13, 2026 21:59
@javenciu
javenciu requested a review from mbriones98 October 13, 2026 21:59
@javenciu

Copy link
Copy Markdown
Contributor Author

Closing and reopening right after opening so CI runs on hosted runners: same-repo runs from this account queue on the fleet label without a runner (details on #19683).

@javenciu javenciu closed this Oct 13, 2026
@javenciu javenciu reopened this Oct 13, 2026
@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ✅ PASS

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

UX-Verdict: PASS

Check that the attached screenshots belong to this PR: they show the Dispatch tree page and agent-name errors, and none of it is touched by this diff.

[UX-REVIEWED] 2e039a8

Description read

[DESCRIPTION-READ] 47281f8ecad1598c65a3ea7c81739950f39265691dcaf79396870a451fc27103

That sha256 names everything this verdict read: the PR description, plus the 17 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 13, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check one thing: masking escaped > in _mask_quoted_separators also changes how split_command_segments splits commands for grant matching, not only for redirect checks.

[DESIGN-REVIEWED] 2e039a8

Description read

[DESCRIPTION-READ] ccf4ec3a9f1faf2bbbe18d97fa9759c9e58db3cb5609f1a571614ac3d05662d2

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — ✅ PASS

Premise-level review of 2e039a80cb30f2c62b29c7dff196d9c6d9b58920 — 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

Check one thing: the splitter now masks every escaped >, whatever mask_escaped says, so all four split_command_segments callers see the new segmentation, plain pattern matching included.

What this change ships

Inventory (6 items) — 6 justified

Intent: a user who trusted git, gh or grep stops getting approval cards for commands whose only > is quoted text. This is a FIX for #19319.

  1. A program grant now covers a command whose every non-discard > is quoted or backslash-escaped — justified
  2. A saved pattern whose only > is quoted no longer counts as spelling a write, so jq '.a > 1' x > out now asks — justified
  3. An escaped > is text to the splitter, so a following & now splits commands for every split caller — justified
  4. Timed-grant deadlines use the same quote-aware reading as the approval decision — justified
  5. Any <<, #, $', ${, open quote, or a Windows host keeps every > counted — justified
  6. The security spec's redirect paragraph is rewritten to the quote-aware rule — justified

All three trust-tier callers of writes_through_redirect now go through _writes_through_redirect; I grepped writes_through_redirect\( across src and found none left outside it. The one sibling that also ignores quotes, _COMMAND_SUBSTITUTION_RE, is deferred under "Not a goal".

[FIRST-PRINCIPLES-REVIEWED] 2e039a8

Description read

[DESCRIPTION-READ] cde7550e96ccb75953427d16b8b437739a267f1b6168f32f27ecaa28aada8979

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

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

Not blocking: one advisory finding.

FINDING — src/kiro_crew/trust_patterns.py:302 — the PR adds from kiro_crew import platform_compat inside _literal_gt_offsets with no comment giving a reason. That breaks the advisory top-level-imports rule. platform_compat and the modules it imports do not import trust_patterns, so this is not a circular-import exception → Fix: move the import to the module's top-level imports. The tests patch platform_compat.IS_WINDOWS on the module object, so they keep working.

[OPUS-REVIEWED] 2e039a8

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

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

@github-actions

github-actions Bot commented Oct 13, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

GPT 6.1 completed its review of 2e039a80cb30f2c62b29c7dff196d9c6d9b58920 and found no blocking issues.

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] 2e039a8

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

@github-actions github-actions Bot added the readiness: action required A blocking check or review needs attention label Oct 13, 2026
The trusted-pattern redirect check walked each segment's quotes from an
unquoted start. The splitter also cuts at a separator escaped inside
double quotes, so a segment can start inside a quote an earlier one
opened, and the walk then took the `>` bash runs as a redirect for
quoted text. Under `echo *` and `ls *`, `echo "x\|ls '" > out '\'` was
covered while bash writes `out`; the same held for `\;`, `\&` and a
backslash-newline.

Quotes are read once over the whole command, and each segment leaves
out only the `>` characters that walk marks as text. An escaped `>` is
text for the splitter too, so the `&` after it separates commands. The
timed-grant deadline and the pattern side read the same way.

The tests that assert the POSIX reading pin `platform_compat.IS_WINDOWS`
to False, so they give the same verdict on the Windows runner.
@javenciu

Copy link
Copy Markdown
Contributor Author
  1. Opus 5.5, src/kiro_crew/trust_patterns.py:273 on c6d8b84: a > bash runs as a redirect was read as quoted text when the splitter cut at a separator escaped inside double quotes, so under echo * and ls *, echo "x\|ls '" > out '\' (and the \;, \& and backslash-newline forms) was covered while bash writes out. Fixed in 2e039a8. _literal_gt_offsets (src/kiro_crew/trust_patterns.py:292) walks quotes once over the whole command and returns the offsets of each > bash reads as text. _segment_writes (src/kiro_crew/trust_patterns.py:326) finds each segment at its offset in the command and drops only those > before applying the read-only classifier's rule. redirect_outside_grant, _covers_write_redirect and timed_grant_deadline all read through it. A segment that is not a verbatim cut of the command counts every >, and so does every segment after it. Reading the same walk for this class also found echo a \>& touch out, where the splitter read >& as one redirect while bash reads \> as text and & as a separator. An escaped > is now text for the splitter too, so the & after it separates commands (_mask_quoted_separators, src/kiro_crew/trust_patterns.py:154), and the command after it needs a grant of its own. Tests: test_a_cut_inside_double_quotes_does_not_hide_a_redirect (in test/test_trust_patterns.py and test/test_trust_timed_grants.py), test_an_escaped_gt_is_text_for_the_splitter_too, test_a_segment_is_read_where_it_is_cut and test_a_segment_not_cut_verbatim_reads_every_gt; test_an_unescaped_redirect_operator_stays_one_segment keeps 2>&1, >&2, &>out and 2>/dev/null reading as before. On TestQuotedRedirectIsText, TestRedirectOutsideGrant and TestTimedGrantDeadline, c6d8b84 gives 12 failed, 84 passed in 3 of 3 runs: the five cut-inside-quotes cases (assert False is True, and a None deadline), the four escaped-operator cases, and the three cases that import _segment_writes, which that revision lacks. 2e039a8 gives 96 passed in 3 of 3 runs. Run with bash -c in an empty directory, each of the six commands creates out. Walking quotes per segment again, with or without the constructs searched in the whole command, fails the cut-inside-quotes tests. Every command in the existing positive and negative sets reads as it did on c6d8b84, and the issue's three commands stay covered. docs/system-specs/modules/security.md adds that quote state is read over the whole command, not per segment, and that an escaped > is text for the splitter as well.
  2. GPT 6.1, test/test_trust_patterns.py:1584 on c6d8b84: the POSIX-reading tests failed on the Windows runner, where every > counts. Fixed in 2e039a8. test_a_quoted_or_escaped_gt_stays_covered, test_a_quoted_gt_in_a_pattern_does_not_spell_a_write and test/test_trust_timed_grants.py::TestTimedGrantDeadline::test_a_quoted_gt_is_covered_by_a_chat_long_base_grant pin platform_compat.IS_WINDOWS to False with patch.object inside the test body, as do the new POSIX-reading tests. test_on_windows_every_gt_counts still pins it to True. With IS_WINDOWS forced True around every test, the c6d8b84 versions fail (14 failed, 1 passed in 3 of 3 runs; the one that passes is the Windows test), and the fix's versions pass (33 passed in 3 of 3 runs, the same with no forcing). Both test files, run in one process at -n0 ahead of test/test_taskrunner_atomic_persistence.py, test/test_taskrunner_execution_capture_async.py, test/test_unattended_slot_guardrails.py and test/test_wheel_apply.py, pass. On the new head, black, isort, flake8 and mypy pass, as do scripts/check_agent_sdk_boundary.py and the comment-history gate.

@javenciu

Copy link
Copy Markdown
Contributor Author

span=de44d143bf45

fixed 2e039a8: quote state is read once over the whole command (_literal_gt_offsets, src/kiro_crew/trust_patterns.py:292), and _segment_writes (src/kiro_crew/trust_patterns.py:326) maps each segment to its offsets, so a segment cut at \|, \;, \& or a backslash-newline inside double quotes keeps the quote state bash gives it. redirect_outside_grant, _covers_write_redirect and timed_grant_deadline all read through it.
Reading the same walk for this class also found echo a \>& touch out, where the splitter read >& as one redirect while bash reads \> as text. An escaped > is now text for the splitter too, so the & after it separates commands (_mask_quoted_separators, src/kiro_crew/trust_patterns.py:154).
test_a_cut_inside_double_quotes_does_not_hide_a_redirect (both test files) and test_an_escaped_gt_is_text_for_the_splitter_too: red on c6d8b84 (9 failed, 3 of 3 runs), green on the fix (3 of 3). bash -c in an empty directory writes out for all six commands. Quotes walked per segment again: the cut-inside-quotes tests fail.

@javenciu

Copy link
Copy Markdown
Contributor Author

span=063869a5f101

fixed 2e039a8: test_a_quoted_or_escaped_gt_stays_covered, test_a_quoted_gt_in_a_pattern_does_not_spell_a_write (test/test_trust_patterns.py) and test_a_quoted_gt_is_covered_by_a_chat_long_base_grant (test/test_trust_timed_grants.py) pin platform_compat.IS_WINDOWS to False with patch.object inside the test body, as do the new POSIX-reading tests; test_on_windows_every_gt_counts still pins it to True.
With IS_WINDOWS forced True around every test: on c6d8b84, 14 failed and only the Windows test passed (3 of 3 runs); on the fix, all 33 selected tests pass (3 of 3), and the same 33 pass with no forcing.

@javenciu

Copy link
Copy Markdown
Contributor Author

Closing and reopening so CI runs on hosted runners: same-repo runs from this account queue on the fleet label without a runner (details on #19683).

@javenciu javenciu closed this Oct 14, 2026
@javenciu javenciu reopened this Oct 14, 2026
@github-actions github-actions Bot added readiness: checking Automated validation is still running readiness: passed Eligible automated validation passed for the current revision and removed readiness: action required A blocking check or review needs attention readiness: checking Automated validation is still running labels Oct 14, 2026
@javenciu
javenciu enabled auto-merge (squash) October 14, 2026 04:35

@bolichen97 bolichen97 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Readiness sweep: full diff read, PR Readiness success on this head, no live change requests.

Sensitive change review
Rule changed: trusted-pattern tier (redirect_outside_grant, _covers_write_redirect, timed_grant_deadline) now drops > that bash reads as literal text (inside '...'/"..." or backslash-escaped outside single quotes) before applying the unchanged readonly_bash.writes_through_redirect. Before: every non-discard > (quoted or not) required a grant spelling the redirect. After: quoted/escaped > no longer counts, so e.g. git log --format='%h -> %s' is auto-approved under git *. Fail-closed fallbacks: open quote, any <<, #, $', ${ anywhere in the command, Windows, or a segment not found verbatim in the command -> every > counts again. Quote state is computed once over the whole command (fixes the cut-inside-double-quotes bypass the Opus lane found on c6d8b84). Splitter change: escaped > is now masked in _mask_quoted_separators so \>& is no longer read as a >& redirect; this only produces more splits (more segments must match grants) -> stricter, not looser. Pattern side only loses coverage (quoted > in a pattern no longer spells a write). Worst case if wrong: a real file write via redirect auto-approved under a base program grant without a card. Evidence checked: read whole diff and the head's split_command_segments/_mask_quoted_separators; reasoned through word-boundary preservation (quotes/backslashes stay in place after removing literal >, so >/dev/null'>'x and 2>&1'>' still count as writes), segment offset lookup (find from running offset, falls back to count-all), substitution guard unchanged; tests cover the redirect table incl. heredoc/comment/ANSI-C/${} and escaped-separator shapes; all backend test shards (Linux/Windows/macOS) green on head. Read-only tier untouched. Undo: revert the squash commit.

Undo: revert the squash commit.

@javenciu
javenciu merged commit 7ae8d67 into main Oct 14, 2026
106 of 188 checks passed
@javenciu
javenciu deleted the fix/19319-quote-aware-redirect-detection branch October 14, 2026 09:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

readiness: passed Eligible automated validation passed for the current revision

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Make redirect detection in trusted patterns quote-aware

2 participants