fix(query): run provider tool calls through hooks#37
Open
BunsDev wants to merge 1 commit into
Open
Conversation
There was a problem hiding this comment.
Pull request overview
This PR closes a security gap in claurst-query where non-Anthropic provider responses that included reconstructed ToolUse blocks could trigger tool execution without going through PreToolUse policy checks (core hooks + plugin hooks) and PostToolUse hooks/events. It centralizes tool execution into a shared, hook-aware executor so Anthropic and non-Anthropic provider paths enforce the same policy and emit consistent ToolStart/ToolEnd events.
Changes:
- Routes non-Anthropic provider
ToolUseblock execution through a shared hook-aware executor instead of callingexecute_tooldirectly. - Replaces the inline streaming tool executor logic with a reusable
execute_tool_blocks_with_hookshelper (sequential pre-hooks, concurrent execution, sequential post-hooks + events). - Ensures both provider and Anthropic tool execution paths share consistent policy enforcement and event semantics.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1965
to
+1971
| /// Execute tool invocations through the common policy-aware tool path. | ||
| async fn execute_tool_blocks_with_hooks( | ||
| tool_blocks: Vec<(String, String, Value)>, | ||
| tools: &[Box<dyn Tool>], | ||
| tool_ctx: &ToolContext, | ||
| event_tx: Option<&mpsc::UnboundedSender<QueryEvent>>, | ||
| ) -> Vec<ContentBlock> { |
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.
Motivation
Non-Anthropic provider responses containing reconstructed ToolUse blocks were being executed directly, bypassing PreToolUse/plugin policy checks and PostToolUse hooks. This created a security bypass for attacker-controlled model output.
Description
Testing