Repository navigation
fix(approvals): a program grant does not cover a write redirect - #19212
Conversation
UX Review (Opus 5.5) — ⏭️ skippedRevision |
Sensitive Change ReviewSensitive files changed:
|
Design Review (Opus 5.5) — ✅ PASSDesign-level review of Design-Verdict: PASS Check that unattended app worker slots granted wildcard patterns ( [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 |
First Principles Review (Opus 5.5) — 🟡 CONCERNSPremise-level review of First-Principles-Verdict: CONCERNS One other tier has the same root cause and this PR leaves it unfixed: operator Not justified as shipped
What this change shipsInventory (6 items) — 5 justifiedIntent: someone who trusts a program for a session gets asked before the agent uses that program to write a file through the shell. FIX.
[FIRST-PRINCIPLES-REVIEWED] ebac44d Description read[DESCRIPTION-READ] 48fb43f5aec18dfa3fb87c76f38142572d033f6d0f0a7bb6911c2f0f4d83f756 That sha256 names the PR description this verdict read. Recompute it with |
Sensitive change review
|
Opus 5.5 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: |
Security Scope Review -- 🟡 CONCERNSWhich legitimate operations does Verdict basis: the reviewer's own judgement; no confirmed regression. Security scope review -- adjudicated candidates
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: ADJUDICATED: 16 candidates, 0 confirmed newly-refused. No row was confirmed back to me. None of the three shell deny tiers ( PLATFORM COVERAGE:
UNADJUDICATED:
[SCOPE-REVIEWED] ebac44d |
GPT 6.1 Review — ✅ no blocking findingsGPT 6.1 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: |
Sensitive change review
|
|
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 ( |
8ec480e to
dc14490
Compare
Sensitive change review
|
|
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. |
dc14490 to
4e1530c
Compare
Sensitive change review
|
|
Maintainer decision (bolichen97): accepted. I read the gate changes and found no new false allow: Posted by an AI assistant at bolichen97's request, after a read-only review of this head. |
4e1530c to
75e34fd
Compare
|
@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:
Follow-ups you asked for, opened as issues:
|
Sensitive change review
|
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.
75e34fd to
ebac44d
Compare
Sensitive change review
|
|
@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 |
iamwhatever
left a comment
There was a problem hiding this comment.
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)
Problem / Motivation
Goal: A trusted base pattern such as
gh *auto-approves whatghdoes, not a file the shell writes for it through an output redirect.A base grant ("trust
gh") is stored as the patternsghandgh *, and a single shell segment is matched against them with plain fnmatch. A redirect is part of the segment text, sogh pr view 42 > /tmp/xmatchesgh *and auto-approves, writing/tmp/xwithout 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, sols >&2xopens the file2xandls >/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
>inside a quoted argument still counts as a write and costs one prompt.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.pytrusted-pattern tier: whenredirect_outside_grantis 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,\vor\fthat bash reads as part of a word.trust_baserow and a new paragraph state the contract.Alternatives considered and rejected:
ghwould keep meaning "letghwrite any file".matches_trusted_pattern: the caller could no longer say why a grant was withheld, so the decline would have no audit reason or notice.>: 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.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),\vor\fis matched with that character kept in the segment, so it can ask where it used to auto-approve.Reader:
dashboard/chat_runner.py:_run_chattrusted-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_bashand_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 redirectTests
test/test_trust_patterns.py::TestRedirectOutsideGrant:>,>>,&>,&>>,2>file,<>,>&2xand a write after2>&1undergh *are not covered; no redirect,> /dev/null,2>/dev/null,&>/dev/null,2>&1,1>&2and<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; lsis 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;lsand tab-separated2>\t/dev/nullstill are.test/test_chat_runner_coverage.py: the runner declinesgh pr view 42 > /tmp/xundergh *(no auto-approve, one audit row, the notice) and still auto-approvesgh 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 forwrites_through_redirectand 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_chatin 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
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
Contributions are accepted under the project's Apache-2.0 license; see the Licensing section of CONTRIBUTING.md.