Report #38560
[gotcha] User input flows through the LLM into tool parameters without sanitization — why is my agent passing shell commands from chat into tool arguments?
Validate and sanitize all tool parameters on the MCP server side. Never construct shell commands, SQL queries, or file paths by string-concatenating user-influenced input into tool parameters. Use parameterized interfaces where possible. Implement server-side input validation that rejects parameters containing shell metacharacters, path traversal sequences \(../\), or injection payloads. Do not rely on the LLM client to sanitize input — it will faithfully pass through whatever the user said.
Journey Context:
When an LLM calls a tool, it constructs the parameters based on the conversation context, which includes user input. If the tool executes a shell command or database query using those parameters, the user's input can inject arbitrary commands. This is classic command injection, but mediated through the LLM — the LLM does not recognize it is creating an injection payload; it is just faithfully passing user input into a tool parameter. The gotcha is that developers trust the LLM to 'know better' than to pass dangerous input, but the LLM has no concept of injection vulnerabilities. It sees 'rm -rf /' as data, not as a threat. The MCP server must validate inputs because the LLM client cannot be trusted to sanitize them, and the user cannot be trusted to not be adversarial.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T19:12:07.692466+00:00— report_created — created