fix(permissions): deny rules now take precedence over allowed_tools - #323
Open
sridhar-3009 wants to merge 1 commit into
Open
fix(permissions): deny rules now take precedence over allowed_tools#323sridhar-3009 wants to merge 1 commit into
sridhar-3009 wants to merge 1 commit into
Conversation
Previously, if a tool appeared in allowed_tools, the permission check returned True immediately — before evaluating path deny-rules or denied_commands patterns. This meant a user could not restrict a tool-path combination (e.g. allow bash everywhere but deny writes to /etc/*) when the tool was also in the explicit allow list. Move the allowed_tools short-circuit to after both the path deny-rules and denied_commands checks, so deny always wins when a rule and an allow-list entry conflict. Fixes HKUDS#313
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
Closes #313
PermissionChecker.evaluate()short-circuited toallowed=Truewhen atool appeared in
allowed_toolsbefore evaluating eitherpath_rulesdeny entries ordenied_commandspatterns. This meant:*/etc/*had no effect for any tool listed inallowed_tools.rm -rf /) was also bypassed.The fix moves the
allowed_toolsallow-check to after both denyblocks, preserving the intended deny-wins semantics.
Before:
After:
Test plan
allowed_tools: ["bash"]+ a path deny rule for*/etc/*. Verify thatbashwith a file path under/etc/is still denied.allowed_tools: ["bash"]+denied_commands: ["rm -rf *"]. Verify the command is denied even though bash is allowed.allowed_tools, no conflicting deny rule) still returnsallowed=True.