fix(hooks): require all segments to match allow rules (#1213)#1214
Merged
FlorianBruniaux merged 1 commit intodevelopfrom Apr 13, 2026
Merged
fix(hooks): require all segments to match allow rules (#1213)#1214FlorianBruniaux merged 1 commit intodevelopfrom
FlorianBruniaux merged 1 commit intodevelopfrom
Conversation
Compound commands (`&&`, `||`, `|`, `;`) previously received PermissionVerdict::Allow when *any single segment* matched an allow rule. This allowed a permission escalation where an LLM agent could chain an allowed command with an unapproved one (e.g. `git status && git add .`) to bypass user confirmation. Replace the `any_allow` flag with `all_segments_allowed` logic: every non-empty segment must independently match an allow rule for the chain to receive Allow. If any segment fails to match, the verdict demotes to Default (ask). Deny still short-circuits on any match, and Ask still wins over a partial Allow. Also add a `saw_segment` guard and a `!allow_rules.is_empty()` check to prevent a vacuous Allow on empty commands or empty rule sets. Add 6 regression tests covering the reproduction case from #1213, all four compound separators, and ask-wins-over-partial-allow precedence. Fixes #1213 Signed-off-by: Patrick szymkowiak <patrick.szymkowiak@innovtech.eu>
FlorianBruniaux
approved these changes
Apr 13, 2026
Collaborator
FlorianBruniaux
left a comment
There was a problem hiding this comment.
LGTM — security fix, reviewed diff, tests pass.
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.
Summary
Fixes #1213 — a compound command permission escalation where a single allowed segment granted auto-allow to the entire chain.
Before (broken):
After (fixed):
Root cause
check_command_with_rulesused anany_allowflag that was set by the first matching segment and never unset. Once set, subsequent segments skipped the allow check entirely, escalating the whole chain.Fix
Replace
any_allowwithall_segments_allowedlogic. Every non-empty segment must independently match an allow rule — otherwise the chain demotes toDefault(ask). Also add:saw_segmentguard to prevent vacuous Allow on empty commands!allow_rules.is_empty()check in the final verdictPrecedence is unchanged: Deny > Ask > Allow > Default.
Impact
Closes a permission escalation vector: an LLM agent could construct
<allowed_cmd> && <unapproved_cmd>to bypass user confirmation on the second command.Test plan
git status && git add .)&&,||,|,;cargo fmtcleanRelated