Repository navigation
fix(agent): close three permission leaks (early read, race key, patch targets) - #481
Merged
Merged
Conversation
… targets)
- Speculative read: a `read` started while the reply streamed ran
before every gate, and its result stood in for the call, so
`read: deny`, `read(secrets/**): deny`, `read: ask`, the intent check
and restored secret placeholders were skipped. The early result is
now used only when no gate would refuse or ask. In a sequential batch
a call that can change files drops the pending early reads, so a
`read` after an `edit` no longer returns the old content.
- Model race: a partner on another provider was sent the turn's API
key. Side requests now share `side_request_key` (the title refine
already did this): the same provider gets the turn's key, another its
own `{PROVIDER}_API_KEY` or none.
- apply_patch: `+++` / `diff --git` header targets override `path`, but
path rules and the outside-workspace check judged `path` only (and
nothing when it was absent). They now judge every target
(`patch_targets`): any deny refuses, any ask asks, allow only when
all are allowed. The headless subagent gate does the same.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Linux CI never ran an early read under a turn intent, leaving the intent closure of read_runs_ungated uncovered there. Co-Authored-By: Claude Opus 5.5 <[email protected]>
mrnasil
enabled auto-merge (squash)
November 25, 2026 13:27
A multi-line matches! left its never-taken arm as an uncovered line on Linux; authorize_tool == Allow is the same check without one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Merged
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.
Three findings from the code audit, each a way past the permission / key boundaries.
1. Speculative read skipped every gate
While the model's reply streams, a
readwhose path is complete starts early (speculative_read). When the final call matched, that result was returned instead of runningexecute_with_permission, so tool rules (read: deny/ask), path rules (read(secrets/**): deny), the agent's tool allow-list, the intent check and secret-placeholder restoration never ran. Only hooks were honoured.Fix:
read_runs_ungated— the early result is used only when every gate would let this read through without asking; otherwise the call goes through the gates as usual. Also, in a sequential batch, a call that is not parallel-safe (edit, write, bash…) now aborts pending early reads, so[edit a.rs, read a.rs]returns the edited file, not the content read before the edit.2. Model race sent the turn's API key to another provider
race_partnercan pick another provider (model_race = "openai/…"while on anthropic), but the race target reused the turn'sapi_key: the Anthropic key went to the OpenAI endpoint on every step. The title-refine path already avoided this; the race path never got the fix.Fix: shared
side_request_key(target, provider, key): the same provider gets the turn's key, another gets its own{PROVIDER}_API_KEYor none (a keyless local provider still works). Title refine uses it too.3. apply_patch header targets bypassed path rules
+++ b/<file>/diff --githeaders overridepath, but path rules and the outside-workspace (important-mode) check looked atpathonly — and at nothing whenpathwas omitted.{path: "src/a.rs", patch: "+++ b/.env …"}wrote.envpastedit(.env): deny.Fix:
whycodes_tools::apply_patch::patch_targetslists every target;file_tool_pathsfeeds them topaths_rule_gate(any deny → refuse, any ask → ask, allow only if all are allowed), to the outside-workspace check, and to the headless subagent gate.Tests
speculative_read_does_not_skip_read_rules(path deny, tool deny, tool ask) andspeculative_read_is_dropped_after_a_write_in_the_same_batch— both fail on the old gate and pass now.side_requests_never_send_the_turn_key_to_another_provider.path_rules_see_apply_patch_header_targets(with and withoutpath),paths_rule_gate_needs_every_path_allowed,patch_targets_name_every_header_over_path.🤖 Generated with Claude Code