Skip to content

fix(approvals): a program grant does not cover a write redirect - #19212

Merged
cruisercohen merged 2 commits into
mainfrom
fix/5341-base-trust-redirects
Oct 12, 2026
Merged

cruisercohen merged 2 commits into
mainfrom
fix/5341-base-trust-redirects

Conversation

@cruisercohen

@cruisercohen cruisercohen commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Problem / Motivation

Goal: A trusted base pattern such as gh * auto-approves what gh does, not a file the shell writes for it through an output redirect.

A base grant ("trust gh") is stored as the patterns gh and gh *, and a single shell segment is matched against them with plain fnmatch. A redirect is part of the segment text, so gh pr view 42 > /tmp/x matches gh * and auto-approves, writing /tmp/x without a prompt. The read-only (trust-reads) tier already treats that same redirect as a write and asks; the two auto-approve tiers disagree about the same command line.

Separately, the read-only tier's discard-redirect scrub (2>&1, >/dev/null) ends each idiom with a negative character class. bash keeps reading the word after it, so ls >&2x opens the file 2x and ls >/dev/null"x" opens /dev/nullx, while the scrub removes the redirect and the command reads as read-only.

Why it matters

Someone who trusts a program for a session expects to be asked before an agent writes arbitrary files with it. Today any program grant silently covers writes to any path the shell can open, and the read-only tier covers a narrow set of word-continuation writes.

Not a goal

  • Changing what a refused command offers the person at the card (the existing approval card and its Allow once / Reject actions stay as they are).
  • Quote-aware redirect parsing: a > inside a quoted argument still counts as a write and costs one prompt.
  • The channel tier: its base grants already refuse any command carrying a redirect.
  • Blocking anything: a declined command goes to the approval card as before.

What changed (motivation → approach → change)

Symptom: a base grant auto-approves a command that writes a file through a redirect. Root cause: the trusted-pattern tier matches the whole segment, redirect included, against <program> *, and never asks whether the segment writes. Change:

  • trust_patterns.redirect_outside_grant(command, patterns): for each segment that writes through a redirect, a matching pattern must itself spell a write redirect (the exact-command grant for that line, or a pattern written with one), or the broad * grant must be present. Otherwise the grant does not cover it.
  • readonly_bash.writes_through_redirect(cmd): the classifier's own redirect rule, exposed on its own, so both tiers use one definition of "write redirect". The discard idioms are not writes; every other > is.
  • dashboard/chat_runner.py trusted-pattern tier: when redirect_outside_grant is true, the tier declines. The command goes to the approval card with a one-line notice, and the decline is SEL-audited (outcome=auto_approve_declined, reason=redirect_outside_grant, tier=trusted_pattern). The program-name check that follows is unchanged.
  • readonly_bash._DEVNULL_REDIR_RE: each discard idiom must end its shell word (a space, tab or newline, an operator, or the end of the line), and descriptors are ASCII digits only, so >&2x, >/dev/null"x" and a non-breaking space or other non-bash blank after the idiom are writes.
  • trust_patterns._COMMAND_SPLIT_RE: the blanks dropped around a separator are space and tab only, so a segment keeps a non-breaking space, \r, \v or \f that bash reads as part of a word.
  • Security spec: the trust_base row and a new paragraph state the contract.

Alternatives considered and rejected:

  • Keep "any arguments" and document the redirect as granted: a grant for gh would keep meaning "let gh write any file".
  • Fold the check into matches_trusted_pattern: the caller could no longer say why a grant was withheld, so the decline would have no audit reason or notice.
  • Quote-aware detection of live >: telling a quoted > from a live one needs the shell's full quoting rules, and a mistake lets a write through; the cost of the conservative rule is one prompt.
  • Refuse the command outright: the person can still approve a specific write at the card, so asking is enough.

Backwards compatibility

Compatible: nothing is rejected. A command that writes through a redirect, matched only by a wildcard grant, asks once at the approval card instead of auto-approving; exact grants and the broad * grant behave as before. A multi-segment command whose separator sits next to a non-breaking space, \r (a CRLF line ending), \v or \f is matched with that character kept in the segment, so it can ask where it used to auto-approve.

Reader: dashboard/chat_runner.py:_run_chat trusted-pattern tier -- chat -- declines to the card and audits (test_a_base_grant_is_not_applied_to_a_write_redirect); discards still auto-approve (test_a_base_grant_still_covers_a_discard_redirect)
Reader: apps/worker_slots.py:_grant_trust -- app -- app-supplied patterns reach the same tier; a pattern that spells its redirect keeps matching (test_a_pattern_that_spells_the_redirect_covers_it)
Reader: security/readonly_bash.py:_classify_bash and _side_effect_reason -- chat (trust-reads) -- a discard idiom that ends its word still scrubs (test_devnull_redirects_allowed, test_a_discard_idiom_continued_by_more_word_is_a_write)
Reader: channel.py:_match_trusted_channel_command -- channel -- unchanged; base grants there already refuse any redirect

Tests

  • test/test_trust_patterns.py::TestRedirectOutsideGrant: >, >>, &>, &>>, 2>file, <>, >&2x and a write after 2>&1 under gh * are not covered; no redirect, > /dev/null, 2>/dev/null, &>/dev/null, 2>&1, 1>&2 and < input stay covered; an exact grant covers its own line only; a pattern that spells the redirect covers exactly that redirect; a discard-only pattern does not cover a write; * covers everything; segments are judged one by one; a segment keeps a non-bash blank next to a separator (ls >&2 + U+00A0 ; ls is a write); an unsegmentable command is left to the matcher.
  • test_redirect_append_both_not_split: &>> still stays in one segment, and that segment is now reported as a write the grant does not cover.
  • test/test_trust_reads.py::test_a_discard_idiom_continued_by_more_word_is_a_write: >&2x, 2>&1x, >&2"x", >/dev/null"x", >/dev/null'x', >/dev/null\x, and U+00A0, CR, VT, FF or U+2003 after >&2 / 2>/dev/null (or between > and /dev/null), and a non-ASCII digit as the descriptor, are not read-only; >&2, 2>&1|head, 2>/dev/null;ls and tab-separated 2>\t/dev/null still are.
  • test/test_chat_runner_coverage.py: the runner declines gh pr view 42 > /tmp/x under gh * (no auto-approve, one audit row, the notice) and still auto-approves gh pr view 42 2>/dev/null.

The new runner test, the word-continuation test and the segment test fail with the source changes reverted.

  • test/test_security_gate_liveness.py: the security package's line budget goes from 28,844 to 28,857 for writes_through_redirect and the regex's comment, with the reason recorded beside the number as the file requires.

Manual verification

N/A — unit coverage sufficient: the change is a pure decision on the command text plus one branch in the runner tier, both exercised end to end through _run_chat in the coverage tests.

Related Issues

N/A

Pattern harvest

Rule candidate: review-prompt
Pattern: a regex that scrubs a shell token as harmless must end where the shell word ends, not at a negative character class, or the rest of the word changes what the token means.

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

Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.

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

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

UX Review (Opus 5.5) — ⏭️ skipped

Revision ebac44d825704f76631b027708b1ea50c1c0cc1a 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 commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Sensitive Change Review

Sensitive files changed:

  • src/kiro_crew/security/readonly_bash.py

  • @cruisercohen posted a complete reasoning template for ebac44d.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Design Review (Opus 5.5) — ✅ PASS

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

Design-Verdict: PASS

Check that unattended app worker slots granted wildcard patterns (worker_slots._grant_trust) can wait at the approval card when a command writes through a redirect.

[DESIGN-REVIEWED] ebac44d

Description read

[DESCRIPTION-READ] e56bdedb92a66f1574f6936a643bc689f1031592a5856238a54071dc0b0ea608

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

Copy link
Copy Markdown
Contributor

First Principles Review (Opus 5.5) — 🟡 CONCERNS

Premise-level review of ebac44d825704f76631b027708b1ea50c1c0cc1a — 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: CONCERNS

One other tier has the same root cause and this PR leaves it unfixed: operator auto_approve_tools globs still treat a write redirect as just another argument.

Not justified as shipped

  • Item 1 — symptom-level (point patch, 1 unfixed sibling): the root cause is that a program glob gets fnmatched against the whole segment text, redirect included. _tier_operator_grants (hook_runtime/gate_tiers.py:941-943) still does _tool_matches(pattern, target) over (call.title, facts.normalized). So an operator pattern Running: gh * still auto-approves gh pr view 42 > /tmp/x. I grepped _tool_matches\( across src/kiro_crew: one tier matches grants against shell text, and this PR does not gate it. The description lists only the channel tier as out of scope.
    Clears when: the description says this fix covers the session-grant tier and names _tier_operator_grants as the tier left open, or that tier calls redirect_outside_grant too.

What this change ships

Inventory (6 items) — 5 justified

Intent: someone who trusts a program for a session gets asked before the agent uses that program to write a file through the shell. FIX.

  1. A session base grant (gh *) no longer auto-approves a command that writes through a redirect. It goes to the approval card instead — symptom-level
  2. A one-line chat notice and an SEL auto_approve_declined row when that happens — justified
  3. Trust-reads now counts >&2x, >/dev/null"x" and non-bash blanks after a discard idiom as writes — justified
  4. Command segmenting keeps NBSP, \r, \v and \f next to separators — justified
  5. New writes_through_redirect / redirect_outside_grant helpers, one definition shared by both tiers — justified
  6. Security spec: the trust_base row and a new contract paragraph — justified

[FIRST-PRINCIPLES-REVIEWED] ebac44d

Description read

[DESCRIPTION-READ] 48fb43f5aec18dfa3fb87c76f38142572d033f6d0f0a7bb6911c2f0f4d83f756

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.

@cruisercohen

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: a5f2b04
  • What rule changed: the read-only classifier's discard-redirect scrub (2>&1, >/dev/null and friends) now matches an idiom only when it ends its shell word (whitespace, an operator, or end of line). The new writes_through_redirect helper exposes the same rule for the trusted-pattern tier.
  • Before -> after (what was allowed/blocked, now): before, ls >&2x and ls >/dev/null"x" were classified read-only (bash opens the files 2x and /dev/nullx). After, both are writes and go to the approval card. ls >&2, ls 2>&1|head, ls 2>/dev/null;ls and every other discard that ends its word stay read-only. Nothing that was asking before is auto-approved now.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a read-only command whose discard redirect is glued to more text (for example a quoted "2>&1" inside an argument) asks once at the card instead of auto-approving. Nothing is blocked; no command stops working.
  • Evidence checked (which sandbox result proves it): test/test_trust_reads.py::test_a_discard_idiom_continued_by_more_word_is_a_write fails with the source change reverted and passes with it; a local bash run confirmed echo hi >&2x creates the file 2x.
  • No regression:
    • Tools still work (which tools/commands were run, result): test_devnull_redirects_allowed (the existing discard cases) and the full trust-reads, read-only-bash, denied-commands, name-grant, auto-approve and tool-gate suites pass locally on this head.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data or signature changes; _classify_bash, is_read_only_bash and unsafe_bash_reason keep their signatures and callers; checked with the suites above.
    • Existing tests (which suites passed on this head): test_trust_reads.py, test_trust_patterns.py, test_readonly_bash_*.py, test_denied_commands_security.py, test_llm_helpers_tool_gate.py, test_acp_tool_gate.py, test_auto_approve.py, test_name_grant*.py, test_channel_trusted_patterns.py, test_dashboard_approval.py, test_chat_runner_composition_contract.py, test_apps_worker_slots.py (2,700+ tests, all passed).
  • How to undo: revert this PR's commit; the regex returns to its earlier form and the trusted-pattern tier stops consulting the helper.

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Opus 5.5 Review — ✅ no blocking findings

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

Review details

No findings.

[OPUS-REVIEWED] ebac44d

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

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

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

Security Scope Review -- 🟡 CONCERNS

Which legitimate operations does ebac44d825704f76631b027708b1ea50c1c0cc1a newly refuse? Updated in place on each push. A script-confirmed regression blocks; the model proposes candidates and never decides a refusal.

Verdict basis: the reviewer's own judgement; no confirmed regression.

Security scope review -- adjudicated candidates

  • macos-latest (platform posix): 12 classified, 0 newly refused, 12 still allowed.
  • ubuntu-latest (platform posix): 12 classified, 0 newly refused, 12 still allowed.
  • windows-latest (platform windows): 7 classified, 0 newly refused, 7 still allowed.

No candidate flipped from allowed to refused.

Scope-Verdict: CONCERNS

TIGHTENING: Two auto-approve tiers got stricter, and the deny composite did not change. (1) The trusted-pattern tier now declines a base grant on a segment that writes through a redirect: redirect_outside_grant in trust_patterns.py, wired in at chat_runner.py with if (matched and event.is_shell and _tp_command and _redirect_outside_grant(_tp_command, slot._trusted_patterns)): ... matched = None. (2) The read-only bash classifier's discard scrub now stops where the shell word ends: _DEVNULL_REDIR_RE = re.compile(r"(?:(?:[0-9]*>>?|&>)[ \t]*/dev/null|[0-9]*>&[0-9]+)(?=$|[ \t\n;&|()<>])"), plus _COMMAND_SPLIT_RE going from \s* to [ \t]*. -- The one threat refused: a program grant such as gh * being used to write any file the shell opens, e.g. gh pr view 42 > /tmp/x, or >&2x / >/dev/null"x" passing as a discard.

ADJUDICATED: 16 candidates, 0 confirmed newly-refused. No row was confirmed back to me. None of the three shell deny tiers (is_sensitive_bash_command, audit_bash_exfiltration, is_denied) imports readonly_bash or trust_patterns segmentation. The only importers are chat_runner.py, chat_handlers.py, hook_runtime/gate_tiers.py (the read-only auto-approve tier) and hooks.py (a re-export). So these rows check that the deny composite stayed the same. They do not measure this tightening.

PLATFORM COVERAGE:

  • posix: rows probe the new word-end lookahead at end of line, before ;, before a space and pipe, and with a trailing \r. They also cover real-file redirects (>, >>, > f 2>&1) and a quoted > inside git commit -m, jq, awk and grep arguments.
  • windows: rows cover 2>NUL (cmd.exe), 2>$null (PowerShell), > NUL with a drive-letter path, and 2>&1 with a C:\ path. The diff only recognises the discard device /dev/null, so the Windows discard spellings are exactly the assumption it makes.
  • any: the quoted-> rows, which are platform-neutral strings.

UNADJUDICATED:

  • Guard 1: trusted-pattern tier.
    • Call path: ACP permission event → _run_chat → _matches_trusted_pattern(_tp_command, slot._trusted_patterns) → new _redirect_outside_grant → readonly_bash.writes_through_redirect(segment) (">" in _DEVNULL_REDIR_RE.sub(" ", cmd)) → matched = None → interactive approval card. The command is not blocked, but the user has to approve it again by hand.
    • The classifier never sees this path. A narrowing I can argue but not confirm: writes_through_redirect treats every > as a write, "quoted or not", by its own docstring. So a granted program with a > only inside a quoted argument now gets a prompt under its base grant:
      • git commit -m "route trust -> redirect check" under git *
      • gh pr create --body "a -> b" under gh *
      • jq '.items[] | select(.count > 3)' report.json under jq *
      • awk '$3 > 100 {print $1}' access.log under awk *
      • grep -rn '=>' src under grep *
    • These are the maintainers' daily commit, PR, jq and awk operations.
    • Narrow it: decide redirects on the shlex-resolved token stream (a > outside quotes) rather than on the raw string. The quoted-> case can then stay covered while > /tmp/x keeps being declined.
    • Windows discard spellings also stop being covered by a base grant: gh pr view 42 2>NUL, gh pr view 42 2>$null, dir C:\Users\dev\project > NUL. _DEVNULL_REDIR_RE only recognises /dev/null.
  • Guard 2: read-only classifier.
    • Call path: gate_tiers read-only tier (call.command and is_read_only_bash(call.command)) and chat_runner trust-reads (is_read_only_bash(cmd)).
    • Inputs that were read-only before and now prompt:
      • ls -la 2>/dev/null followed by a trailing \r: a CRLF paste, because \r is no longer a word end.
      • A discard idiom followed by a closing quote inside a wrapper.
    • No verdict exists for either one.

[SCOPE-REVIEWED] ebac44d

@github-actions

github-actions Bot commented Oct 12, 2026 •

Copy link
Copy Markdown
Contributor

GPT 6.1 Review — ✅ no blocking findings

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

This comment is updated in place on each push.

Review details

No findings.
[GPT-REVIEWED] ebac44d

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

@cruisercohen

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 8ec480e
  • What rule changed: the read-only classifier's discard-redirect scrub (2>&1, >/dev/null and friends) now matches an idiom only when it ends its shell word (a space, tab or newline, an operator, or end of line), and reads descriptors as ASCII digits only. The new writes_through_redirect helper exposes the same rule for the trusted-pattern tier.
  • Before -> after (what was allowed/blocked, now): before, ls >&2x, ls >/dev/null"x" and ls >&2 followed by a non-breaking space and more text were classified read-only (bash opens a file for each). After, all are writes and go to the approval card. ls >&2, ls 2>&1|head, ls 2>/dev/null;ls, tab-separated 2> + tab + /dev/null, and every other discard that ends its word stay read-only. Nothing that was asking before is auto-approved now.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a read-only command whose discard redirect is glued to more text (for example a quoted "2>&1" inside an argument) asks once at the card instead of auto-approving. Nothing is blocked; no command stops working.
  • Evidence checked (which sandbox result proves it): test/test_trust_reads.py::test_a_discard_idiom_continued_by_more_word_is_a_write fails on the previous head (the U+00A0 case) and on main (the >&2x case), and passes on this head; a local bash run confirmed echo hi >&2x creates the file 2x.
  • No regression:
    • Tools still work (which tools/commands were run, result): test_devnull_redirects_allowed (the existing discard cases) and the trust-reads, read-only-bash, denied-commands, trust-patterns and tool-gate suites pass locally on this head (1,695 passed).
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data or signature changes; _classify_bash, is_read_only_bash and unsafe_bash_reason keep their signatures and callers; checked with the suites above.
    • Existing tests (which suites passed on this head): test_trust_reads.py, test_trust_patterns.py, test_readonly_bash_assigning_expansions.py, test_readonly_bash_common_filters.py, test_denied_commands_security.py, test_llm_helpers_tool_gate.py.
  • How to undo: revert this PR's commits; the regex returns to its earlier form and the trusted-pattern tier stops consulting the helper.

@cruisercohen

Copy link
Copy Markdown
Contributor Author

GPT 6.1 finding on a5f2b04 (non-bash whitespace after a discard idiom) is fixed at root in 8ec480e: the scrub now ends an idiom only at a space, tab, newline, an operator or end of line, and reads descriptors as ASCII digits only ([ \t]* / [0-9] instead of \s / \d). test_a_discard_idiom_continued_by_more_word_is_a_write covers U+00A0, CR, VT, FF and U+2003 after >&2 and 2>/dev/null and between > and /dev/null, plus a non-ASCII digit descriptor; it fails on a5f2b04 at the U+00A0 case and passes on 8ec480e.

@cruisercohen
cruisercohen force-pushed the fix/5341-base-trust-redirects branch from 8ec480e to dc14490 Compare October 12, 2026 00:31
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: dc14490
  • What rule changed: the read-only classifier's discard-redirect scrub (2>&1, >/dev/null and friends) now matches an idiom only when it ends its shell word (a space, tab or newline, an operator, or end of line), and reads descriptors as ASCII digits only. The new writes_through_redirect helper exposes the same rule for the trusted-pattern tier, whose segment splitter now drops only space and tab around a separator.
  • Before -> after (what was allowed/blocked, now): before, ls >&2x, ls >/dev/null"x" and ls >&2 followed by a non-breaking space and more text were classified read-only (bash opens a file for each). After, all are writes and go to the approval card. ls >&2, ls 2>&1|head, ls 2>/dev/null;ls, tab-separated 2> + tab + /dev/null, and every other discard that ends its word stay read-only. Nothing that was asking before is auto-approved now.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a read-only command whose discard redirect is glued to more text (for example a quoted "2>&1" inside an argument) asks once at the card instead of auto-approving. Nothing is blocked; no command stops working.
  • Evidence checked (which sandbox result proves it): test/test_trust_reads.py::test_a_discard_idiom_continued_by_more_word_is_a_write fails on the first head (the U+00A0 case) and on main (the >&2x case), and test_trust_patterns.py::TestRedirectOutsideGrant::test_a_segment_keeps_what_bash_reads_as_part_of_a_word fails with the splitter change reverted; both pass on this head. A local bash run confirmed echo hi >&2x creates the file 2x.
  • No regression:
    • Tools still work (which tools/commands were run, result): test_devnull_redirects_allowed (the existing discard cases) and the trust-reads, read-only-bash, denied-commands, trust-patterns and tool-gate suites pass locally on this head (1,695 passed).
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data or signature changes; _classify_bash, is_read_only_bash and unsafe_bash_reason keep their signatures and callers; checked with the suites above.
    • Existing tests (which suites passed on this head): test_trust_reads.py, test_trust_patterns.py, test_chat_runner_coverage.py, test_channel_trusted_patterns.py, test_dashboard_approval.py, test_apps_worker_slots.py, test_session_control.py (1,067 passed), plus test_readonly_bash_assigning_expansions.py, test_readonly_bash_common_filters.py, test_denied_commands_security.py, test_llm_helpers_tool_gate.py on the regex change.
  • How to undo: revert this PR's commits; the regex returns to its earlier form and the trusted-pattern tier stops consulting the helper.

@cruisercohen

Copy link
Copy Markdown
Contributor Author

GPT 6.1 finding on 8ec480e (the segment splitter dropping U+00A0 beside a separator) is fixed at root in dc14490: the splitter now drops only space and tab around a separator, so a segment keeps every character bash reads as part of a word. TestRedirectOutsideGrant::test_a_segment_keeps_what_bash_reads_as_part_of_a_word covers U+00A0, CR, VT, FF and U+2003 in ls >&2<char>; ls under an ls grant; it fails with the splitter change reverted and passes on dc14490.

@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 12, 2026
@cruisercohen
cruisercohen force-pushed the fix/5341-base-trust-redirects branch from dc14490 to 4e1530c Compare October 12, 2026 00:55
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 4e1530c
  • What rule changed: the read-only classifier's discard-redirect scrub (2>&1, >/dev/null and friends) now matches an idiom only when it ends its shell word (a space, tab or newline, an operator, or end of line), and reads descriptors as ASCII digits only. The new writes_through_redirect helper exposes the same rule for the trusted-pattern tier, whose segment splitter now drops only space and tab around a separator.
  • Before -> after (what was allowed/blocked, now): before, ls >&2x, ls >/dev/null"x" and ls >&2 followed by a non-breaking space and more text were classified read-only (bash opens a file for each). After, all are writes and go to the approval card. ls >&2, ls 2>&1|head, ls 2>/dev/null;ls, tab-separated 2> + tab + /dev/null, and every other discard that ends its word stay read-only. Nothing that was asking before is auto-approved now.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a read-only command whose discard redirect is glued to more text (for example a quoted "2>&1" inside an argument) asks once at the card instead of auto-approving. Nothing is blocked; no command stops working.
  • Evidence checked (which sandbox result proves it): test/test_trust_reads.py::test_a_discard_idiom_continued_by_more_word_is_a_write fails on the first head (the U+00A0 case) and on main (the >&2x case), and test_trust_patterns.py::TestRedirectOutsideGrant::test_a_segment_keeps_what_bash_reads_as_part_of_a_word fails with the splitter change reverted; both pass on this head. A local bash run confirmed echo hi >&2x creates the file 2x.
  • No regression:
    • Tools still work (which tools/commands were run, result): test_devnull_redirects_allowed (the existing discard cases) and the trust-reads, read-only-bash, denied-commands, trust-patterns and tool-gate suites pass locally on this head (1,695 passed).
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data or signature changes; _classify_bash, is_read_only_bash and unsafe_bash_reason keep their signatures and callers; checked with the suites above.
    • Existing tests (which suites passed on this head): test_trust_reads.py, test_trust_patterns.py, test_chat_runner_coverage.py, test_channel_trusted_patterns.py, test_dashboard_approval.py, test_apps_worker_slots.py, test_session_control.py (1,067 passed), plus test_security_gate_liveness.py (package line budget, raised by 13 lines with its reason), test_readonly_bash_assigning_expansions.py, test_readonly_bash_common_filters.py, test_denied_commands_security.py, test_llm_helpers_tool_gate.py (1,710 passed on this head).
  • How to undo: revert this PR's commits; the regex returns to its earlier form and the trusted-pattern tier stops consulting the helper.

@github-actions github-actions Bot added readiness: checking Automated validation is still running and removed readiness: action required A blocking check or review needs attention labels Oct 12, 2026
@cruisercohen
cruisercohen marked this pull request as ready for review October 12, 2026 01:24
@cruisercohen
cruisercohen requested review from a team and KiroCrewCaptain as code owners October 12, 2026 01:24
@cruisercohen
cruisercohen enabled auto-merge (squash) October 12, 2026 01:24
@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 12, 2026
@bolichen97

Copy link
Copy Markdown
Contributor

Maintainer decision (bolichen97): accepted. I read the gate changes and found no new false allow: split_command_segments restores the 2>&1/&> placeholders, so &>, >|, <> and >& file all still count as writes, and writes_through_redirect(pattern) cannot vouch for a real redirect. The cost is a real one: a quoted > under a program grant (for example git log --format='%h -> %s', gh api --jq 'select(.n > 1)') now raises an approval card. I accept that trade-off, since it only adds a card and blocks nothing. Please rebase (main changed chat_runner.py and security.md), then I will approve. Follow-ups, as issues: quote-aware redirect detection, and change the card text from "writes to a file" to "may write through a redirect".

Posted by an AI assistant at bolichen97's request, after a read-only review of this head.

@cruisercohen
cruisercohen force-pushed the fix/5341-base-trust-redirects branch from 4e1530c to 75e34fd Compare October 12, 2026 07:06
@github-actions github-actions Bot removed the readiness: passed Eligible automated validation passed for the current revision label Oct 12, 2026
@cruisercohen

Copy link
Copy Markdown
Contributor Author

@bolichen97 thanks for the review. Rebased onto current main; the new head is 75e34fd. Both commits replayed without conflicts, and the PR's own diff is unchanged (same 8 files, +312/-9).

Re-run locally on the rebased head:

  • test_trust_patterns.py, test_trust_reads.py, test_security_gate_liveness.py, test_chat_runner_coverage.py: 680 passed
  • black, isort, flake8 on the touched files and mypy on the three touched modules: clean
  • comment-history gate: passed

Follow-ups you asked for, opened as issues:

@cruisercohen

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: 75e34fd
  • What rule changed: unchanged from the previous head (4e1530c); this head is a rebase onto current main with no conflicts and an identical PR diff. A trusted program grant is not applied to a shell command that writes through a redirect the grant never spelled; the command goes to the approval card instead. The read-only classifier's discard-redirect scrub (2>&1, >/dev/null and friends) matches an idiom only when it ends its shell word, and reads descriptors as ASCII digits only; writes_through_redirect exposes the same rule for the trusted-pattern tier.
  • Before -> after (what was allowed/blocked, now): before, a program grant auto-approved its command with any output redirect, and ls >&2x / ls >/dev/null"x" were classified read-only. After, those go to the approval card. Discards that end their word (ls >&2, ls 2>&1|head, ls 2>/dev/null;ls), exact grants and the broad grant are unchanged. Nothing that was asking before is auto-approved now.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a command with a > inside a quoted argument under a program grant (for example git log --format='%h -> %s') asks once at the card instead of auto-approving. Nothing is blocked; no command stops working. Follow-ups Make redirect detection in trusted patterns quote-aware #19319 and Clarify the notice text when a trusted pattern is not applied for a redirect #19320 track reducing those cards and the notice wording.
  • Evidence checked (which sandbox result proves it): test_trust_patterns.py::TestRedirectOutsideGrant and test_trust_reads.py::test_a_discard_idiom_continued_by_more_word_is_a_write pass on this head and fail with the change reverted (checked on the previous head; the rebase did not touch these files' PR hunks).
  • No regression:
    • Tools still work (which tools/commands were run, result): trust-reads, read-only-bash, denied-commands, trust-patterns and tool-gate suites pass locally on this head.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data or signature changes; _classify_bash, is_read_only_bash and unsafe_bash_reason keep their signatures and callers; checked with the suites below.
    • Existing tests (which suites passed on this head): test_trust_reads.py, test_trust_patterns.py, test_chat_runner_coverage.py, test_channel_trusted_patterns.py, test_dashboard_approval.py, test_apps_worker_slots.py, test_session_control.py, test_security_gate_liveness.py, test_readonly_bash_assigning_expansions.py, test_readonly_bash_common_filters.py, test_denied_commands_security.py, test_llm_helpers_tool_gate.py (2,482 passed, 1 skipped on this head); black, isort, flake8 and mypy clean on the touched files.
  • How to undo: revert this PR's commits; the trusted-pattern tier stops consulting the helper and the regex returns to its earlier form.

@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 12, 2026
A trusted base pattern such as 'gh *' now declines to the approval card
when the command writes through an output redirect the pattern never
spelled. Discard redirects (2>/dev/null, 2>&1) stay covered, as do exact
grants for the line and the broad '*' grant. The decline is audited.

The read-only classifier's discard idioms now end where their shell word
ends, so '>&2x' (a write to file '2x') and '>/dev/null"x"' are writes.
bash splits words on space, tab and newline only and reads only ASCII
digits as a descriptor, so U+00A0, CR, VT, FF or a non-ASCII digit after
'>&2' or '/dev/null' continue the word and name a file. The discard scrub
and the trusted-pattern segment splitter both use bash's own blanks.
@cruisercohen
cruisercohen force-pushed the fix/5341-base-trust-redirects branch from 75e34fd to ebac44d Compare October 12, 2026 08:00
@cruisercohen

Copy link
Copy Markdown
Contributor Author

Sensitive change review

  • Head commit: ebac44d
  • What rule changed: unchanged from the earlier heads (4e1530c, 75e34fd); this head is a rebase onto current main with no conflicts and an identical PR diff. A trusted program grant is not applied to a shell command that writes through a redirect the grant never spelled; the command goes to the approval card instead. The read-only classifier's discard-redirect scrub (2>&1, >/dev/null and friends) matches an idiom only when it ends its shell word, and reads descriptors as ASCII digits only; writes_through_redirect exposes the same rule for the trusted-pattern tier.
  • Before -> after (what was allowed/blocked, now): before, a program grant auto-approved its command with any output redirect, and ls >&2x / ls >/dev/null"x" were classified read-only. After, those go to the approval card. Discards that end their word (ls >&2, ls 2>&1|head, ls 2>/dev/null;ls), exact grants and the broad grant are unchanged. Nothing that was asking before is auto-approved now.
  • Worst case if wrong (breaks commands / leaks secret / locks user out): a command with a > inside a quoted argument under a program grant (for example git log --format='%h -> %s') asks once at the card instead of auto-approving. Nothing is blocked; no command stops working. Follow-ups Make redirect detection in trusted patterns quote-aware #19319 and Clarify the notice text when a trusted pattern is not applied for a redirect #19320 track reducing those cards and the notice wording.
  • Evidence checked (which sandbox result proves it): test_trust_patterns.py::TestRedirectOutsideGrant and test_trust_reads.py::test_a_discard_idiom_continued_by_more_word_is_a_write pass on this head and fail with the change reverted (checked on the previous head; the rebase did not touch these files' PR hunks).
  • No regression:
    • Tools still work (which tools/commands were run, result): trust-reads, read-only-bash, denied-commands, trust-patterns and tool-gate suites pass locally on this head.
    • Backward compatible (old config / old data / old callers still work, how checked): no config, data or signature changes; _classify_bash, is_read_only_bash and unsafe_bash_reason keep their signatures and callers; checked with the suites below.
    • Existing tests (which suites passed on this head): test_trust_reads.py, test_trust_patterns.py, test_chat_runner_coverage.py, test_channel_trusted_patterns.py, test_dashboard_approval.py, test_apps_worker_slots.py, test_session_control.py, test_security_gate_liveness.py, test_readonly_bash_assigning_expansions.py, test_readonly_bash_common_filters.py, test_denied_commands_security.py, test_llm_helpers_tool_gate.py plus test_wait_discipline_ratchet.py (2,521 passed, 1 skipped on this head); black, isort, flake8 and mypy clean on the touched files.
  • How to undo: revert this PR's commits; the trusted-pattern tier stops consulting the helper and the regex returns to its earlier form.

@cruisercohen

Copy link
Copy Markdown
Contributor Author

@bolichen97 rebased once more so CI picks up the wait-discipline baseline fix (#19329) and the FilePathMenu test fix (#19288) that just landed on main. New head: ebac44d. No conflicts and the PR diff is unchanged. Locally on this head the same suites plus test_wait_discipline_ratchet.py pass (2,521 passed), and black, isort, flake8, mypy and the comment-history gate are clean. Follow-ups #19319 and #19320 are unchanged.

@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 12, 2026

@iamwhatever iamwhatever 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.

This PR stops a session program grant such as gh * from auto-approving a command that writes a file through an output redirect. It also fixes the read-only tier's discard scrub, which ended at a negative class, so >&2x and >/dev/null"x" (real file writes in bash) were treated as sinks. The root cause is fixed: redirect_outside_grant judges each segment with the same writes_through_redirect rule the read-only classifier uses. A write is covered only by * or by a matching pattern that spells the redirect itself. I tried to break it. &>, >|, <> and >& file still count as writes after split_command_segments restores its redirect placeholders. 2>&- and 1>/dev/null"x" fall through as writes. A pattern that only spells a discard (gh * 2>/dev/null) cannot vouch for a real write. Process substitution makes the command unsegmentable, so it matches no grant. A U+00A0 or CR beside a separator now stays in the segment. Every case I tried ends at the approval card, and none auto-approves. The change only adds declines, and the cost (a quoted > such as --jq 'select(.n > 1)' now asks once) was accepted explicitly by bolichen97, with follow-ups #19319 and #19320 filed. First Principles points out that operator auto_approve_tools globs (hook_runtime/gate_tiers.py _tier_operator_grants) have the same shape. That is operator-written config and a fair follow-up issue, not a defect in this diff. Base is main, it is mergeable, and checks are green. — crew-pr-reviewer (deep re-check)

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.

3 participants