Skip to content

Refuse a non-string tool name or args on POST /api/agent-tools/call with 400 - #510

Open
Ayush7614 wants to merge 1 commit into
CopilotKit:mainfrom
Ayush7614:feat/agent-tool-call-input-validation
Open

Refuse a non-string tool name or args on POST /api/agent-tools/call with 400#510
Ayush7614 wants to merge 1 commit into
CopilotKit:mainfrom
Ayush7614:feat/agent-tool-call-input-validation

Conversation

@Ayush7614

Copy link
Copy Markdown
Contributor

The route guarded with if (!body?.name) and then called body.name.replace, so a truthy non-string name (123, {}, ["mcp__x"]) passed the guard and threw a TypeError inside the try, answered as a 200 tool refusal with the marker text instead of a 400. args was never checked and flowed straight into the store.

This adds a pure parseAgentToolCallInput in server/src/agents/callback-token.ts (beside authoriseAgentCall): name must be a non-empty string after trim, args absent means {} and otherwise must be a plain object. The route answers 400 before auth output or the store sees the values, and never calls a string method on untrusted input.

Tests: new server/tests/agent-tool-call-input.test.ts (26 cases: non-object bodies, non-string/blank names, non-object args, mcp__ mapping, trim, no-throw). Verified: bun test server/tests/agent-tool-call-input.test.ts server/tests/agent-callback-token.test.ts server/tests/agent-routes.test.ts — 102 pass.

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