Tool arguments are validated against inputSchema before execution
Why it matters
Tool arguments come from AI model output, which can be manipulated via prompt injection (OWASP LLM01). An MCP tool that executes a shell command, writes a file, or queries a database using arguments it hasn't validated is wide open to CWE-78 (OS command injection) and CWE-22 (path traversal). Even without a malicious actor, an AI model generating plausible-but-wrong parameter values (wrong types, out-of-range numbers) will hit unvalidated code paths and produce crashes or corrupted state. Input schema validation is the gating control before any side effect executes.
Severity rationale
Critical because unvalidated tool inputs enable injection attacks (CWE-78, CWE-22) and prompt injection exploitation (OWASP LLM01) that can execute arbitrary commands or access unauthorized files.
Remediation
Use Zod schemas in the SDK — validation happens automatically before the handler runs. Add security-specific refinements for file paths and sensitive inputs.
// src/tools/files.ts — validated file write
server.tool('write_file', 'Write content to a file within the project', {
path: z.string()
.refine(p => !p.includes('..'), 'Path traversal not allowed')
.refine(p => p.startsWith('/workspace/'), 'Must be within /workspace'),
content: z.string().max(1_000_000, 'Content exceeds 1MB limit'),
}, async ({ path, content }) => {
// path and content are validated before this line executes
await fs.writeFile(path, content)
return { content: [{ type: 'text', text: `Wrote ${content.length} bytes` }] }
})
For Python, use Pydantic model validation on the function arguments decorated with @mcp.tool().
DetectionPro
The detection method for this pattern is part of AuditBuffet Pro.
The full method (what to look for, pass and fail conditions, and how results get reported) ships inside the MCP Server Audit. The pattern definition, severity rationale, and remediation remain openly licensed under CC-BY-4.0.
External references
- cwe · CWE-20 — Improper Input Validation
- cwe · CWE-78 — Improper Neutralization of Special Elements used in an OS Command (shell injection via unvalidated tool args)
- owasp:2021 · A03
- owasp-llm:2025 · LLM01 — Prompt Injection (AI-supplied args reaching shell/SQL without validation)
- external · mcp-spec-tool-inputschema — MCP Specification — Tool inputSchema validation
- cwe · CWE-22 — Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal')
Taxons
History
- 2026-04-18·v1.0.0·Initial import from mcp-server·automated