Skip to content

fix(governance): stop read-only pipelines costing an approval prompt - #385

Merged
github-actions[bot] merged 1 commit into
mainfrom
fix/readonly-pipelines-do-not-prompt
Aug 17, 2026
Merged

github-actions[bot] merged 1 commit into
mainfrom
fix/readonly-pipelines-do-not-prompt

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

The bug

ls crates | head asked the user for permission to list a directory.

classify_search_pipeline required the head of a pipeline to be a search command (rg/grep/egrep/fgrep/find/fd). So ls, cat, head and git reads piped into a limiter were never classified. Unclassified means the call stays bash, bash is in hitl_tools, and approval gates on tool identity — so a pure read reached the HITL prompt.

command before after
ls crates | head prompts rewritten → dedicated ls
ls crates | wc -l prompts rewritten → dedicated ls
wc -l Cargo.toml prompts redirected to workspace tools
cat f | wc -l prompts rewritten → read_file
git log --oneline | head prompts rewritten → dedicated git
ls | tee out.txt gated still gated
ls | xargs rm gated still gated
cat f | sh gated still gated

Why 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:

  1. split_pipeline_segments refuses ;, &, <, >, backtick, $, newline and ||. Nothing reaching this path can redirect, chain or command-substitute.
  2. Every segment after the first must still be a result limiter (head/tail/wc).

Only which command may head a pipeline changed.

⚠️ This reverses a deliberate decision

search_pipelines_only_collapse_through_result_limiters explicitly asserted ls | head and cat f | head must stay unclassified. That assertion is the reported bug, so the test is renamed to readonly_pipelines_only_collapse_through_result_limiters and 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_segments refuses a bare |, and strip_ignored_redirects only strips 2>/dev/null from 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 spellings
  • wc_redirects_instead_of_prompting
  • a_readonly_head_does_not_launder_a_writing_tail — 10 negative cases incl. tee, xargs rm, sh, curl -d @-, > redirection, && chaining, backtick and $() substitution

cargo fmt --all -- --check, cargo clippy --all-targets, cargo test --workspace all clean.

Note: forge-connect's refresh_models_dev_registry_uses_override_url failed twice during this work and then passed 6 consecutive workspace runs (3 with this change, 3 without). forge-connect has no dependency on forge-governance, so it is unrelated — but it looks genuinely flaky (mock_http + env guard under parallel load) and may deserve its own issue.

`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.
@github-actions
github-actions Bot enabled auto-merge (squash) August 17, 2026 11:17
@github-actions
github-actions Bot merged commit d4a5464 into main Aug 17, 2026
7 checks passed
@mohitranka
mohitranka deleted the fix/readonly-pipelines-do-not-prompt branch August 17, 2026 11:32
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.
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.

1 participant