Repository navigation
fix(governance): stop read-only pipelines costing an approval prompt - #385
Merged
Merged
Conversation
`ls crates | head` asked the user for permission to list a directory. `classify_readonly_pipeline` (was `classify_search_pipeline`) required the head of a pipeline to be a *search* command, so `ls`, `cat`, `head` and `git` reads piped into a limiter were never classified. Unclassified means the call stays `bash`, and `bash` is in `hitl_tools`, so a pure read reached the HITL prompt. Widen the head to any command this module already recognises as a read. Add `wc` as a read with no dedicated tool: it can never be rewritten, but it only ever reads, so it redirects onto workspace tools rather than prompting. The widening is bounded by two existing properties, not by new checks. `split_pipeline_segments` refuses `;`, `&`, `<`, `>`, backtick, `$`, newline and `||`, so nothing reaching this path can redirect, chain or substitute; and every segment after the first must still be a result limiter. `ls | tee out`, `ls | xargs rm` and `cat f | sh` stay gated, and there is now a test for each. Reverses a deliberate prior assertion: `search_pipelines_only_collapse_through_ result_limiters` pinned `ls | head` as unclassified. That is the behaviour being fixed, so the test is renamed and those two cases now assert the collapse.
mohitranka
added a commit
that referenced
this pull request
Aug 21, 2026
…385) `ls crates | head` asked the user for permission to list a directory. `classify_readonly_pipeline` (was `classify_search_pipeline`) required the head of a pipeline to be a *search* command, so `ls`, `cat`, `head` and `git` reads piped into a limiter were never classified. Unclassified means the call stays `bash`, and `bash` is in `hitl_tools`, so a pure read reached the HITL prompt. Widen the head to any command this module already recognises as a read. Add `wc` as a read with no dedicated tool: it can never be rewritten, but it only ever reads, so it redirects onto workspace tools rather than prompting. The widening is bounded by two existing properties, not by new checks. `split_pipeline_segments` refuses `;`, `&`, `<`, `>`, backtick, `$`, newline and `||`, so nothing reaching this path can redirect, chain or substitute; and every segment after the first must still be a result limiter. `ls | tee out`, `ls | xargs rm` and `cat f | sh` stay gated, and there is now a test for each. Reverses a deliberate prior assertion: `search_pipelines_only_collapse_through_ result_limiters` pinned `ls | head` as unclassified. That is the behaviour being fixed, so the test is renamed and those two cases now assert the collapse.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…385) `ls crates | head` asked the user for permission to list a directory. `classify_readonly_pipeline` (was `classify_search_pipeline`) required the head of a pipeline to be a *search* command, so `ls`, `cat`, `head` and `git` reads piped into a limiter were never classified. Unclassified means the call stays `bash`, and `bash` is in `hitl_tools`, so a pure read reached the HITL prompt. Widen the head to any command this module already recognises as a read. Add `wc` as a read with no dedicated tool: it can never be rewritten, but it only ever reads, so it redirects onto workspace tools rather than prompting. The widening is bounded by two existing properties, not by new checks. `split_pipeline_segments` refuses `;`, `&`, `<`, `>`, backtick, `$`, newline and `||`, so nothing reaching this path can redirect, chain or substitute; and every segment after the first must still be a result limiter. `ls | tee out`, `ls | xargs rm` and `cat f | sh` stay gated, and there is now a test for each. Reverses a deliberate prior assertion: `search_pipelines_only_collapse_through_ result_limiters` pinned `ls | head` as unclassified. That is the behaviour being fixed, so the test is renamed and those two cases now assert the collapse.
mohitranka
added a commit
that referenced
this pull request
Sep 11, 2026
…385) `ls crates | head` asked the user for permission to list a directory. `classify_readonly_pipeline` (was `classify_search_pipeline`) required the head of a pipeline to be a *search* command, so `ls`, `cat`, `head` and `git` reads piped into a limiter were never classified. Unclassified means the call stays `bash`, and `bash` is in `hitl_tools`, so a pure read reached the HITL prompt. Widen the head to any command this module already recognises as a read. Add `wc` as a read with no dedicated tool: it can never be rewritten, but it only ever reads, so it redirects onto workspace tools rather than prompting. The widening is bounded by two existing properties, not by new checks. `split_pipeline_segments` refuses `;`, `&`, `<`, `>`, backtick, `$`, newline and `||`, so nothing reaching this path can redirect, chain or substitute; and every segment after the first must still be a result limiter. `ls | tee out`, `ls | xargs rm` and `cat f | sh` stay gated, and there is now a test for each. Reverses a deliberate prior assertion: `search_pipelines_only_collapse_through_ result_limiters` pinned `ls | head` as unclassified. That is the behaviour being fixed, so the test is renamed and those two cases now assert the collapse.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
The bug
ls crates | headasked the user for permission to list a directory.classify_search_pipelinerequired the head of a pipeline to be a search command (rg/grep/egrep/fgrep/find/fd). Sols,cat,headandgitreads piped into a limiter were never classified. Unclassified means the call staysbash,bashis inhitl_tools, and approval gates on tool identity — so a pure read reached the HITL prompt.ls crates | headlsls crates | wc -llswc -l Cargo.tomlcat f | wc -lread_filegit log --oneline | headgitls | tee out.txtls | xargs rmcat f | shWhy the widening is safe
This module is a security boundary and must fail closed — a rewrite turns a call that would have prompted into one authorized outright. The change leans on two properties that already hold rather than adding new checks:
split_pipeline_segmentsrefuses;,&,<,>, backtick,$, newline and||. Nothing reaching this path can redirect, chain or command-substitute.head/tail/wc).Only which command may head a pipeline changed.
search_pipelines_only_collapse_through_result_limitersexplicitly assertedls | headandcat f | headmust stay unclassified. That assertion is the reported bug, so the test is renamed toreadonly_pipelines_only_collapse_through_result_limitersand those two cases now assert the collapse. Its real purpose — that non-limiter sinks never collapse — is unchanged and still covered.If that assertion was load-bearing for a reason not visible in the file, this PR is wrong and should be rejected.
Known gap
Commands mixing
;with|are still gated, e.g.ls … 2>/dev/null | head; find … 2>/dev/null | head. Two reasons:split_command_segmentsrefuses a bare|, andstrip_ignored_redirectsonly strips2>/dev/nullfrom the end of the whole string, not per segment. Fixing it means splitting on;/&&first and then per-segment on|, with per-segment redirect stripping — a real restructuring of a fail-closed boundary, deliberately not attempted here.Design note
Classifying command strings is the hardest of the three strategies in this space, and it degrades into false prompts (or, tuned the other way, false permits). Claude Code uses user-taught pattern allowlists; Codex sandboxes with Seatbelt on macOS and Landlock+seccomp on Linux so classification is not load-bearing. Worth considering whether the rewrite path should remain an output-quality optimisation with sandboxing as the actual boundary — cf.
docs/sandboxing-followup.md.Tests
readonly_commands_piped_into_a_limiter_are_not_gated— 8 read spellingswc_redirects_instead_of_promptinga_readonly_head_does_not_launder_a_writing_tail— 10 negative cases incl.tee,xargs rm,sh,curl -d @-,>redirection,&&chaining, backtick and$()substitutioncargo fmt --all -- --check,cargo clippy --all-targets,cargo test --workspaceall clean.Note:
forge-connect'srefresh_models_dev_registry_uses_override_urlfailed twice during this work and then passed 6 consecutive workspace runs (3 with this change, 3 without).forge-connecthas no dependency onforge-governance, so it is unrelated — but it looks genuinely flaky (mock_http+ env guard under parallel load) and may deserve its own issue.