The mistake
An MCP tool that runs subprocess.run(..., shell=True) / exec with a tool argument, opens a model-supplied path without containment, builds SQL with f-strings or template literals, fetches any URL the model gives it, or evaluates tool input.
Why it is dangerous
Tool arguments are written by the model, and the model follows instructions it reads in web pages, files, issues and emails. A shell call lets a prompt injection run any command as the user running the server. An uncontained path can be pointed at ../../.ssh/id_rsa or ~/.aws/credentials. A fetch tool can be steered to cloud metadata (http://169.254.169.254/ returns instance credentials) and localhost admin ports.
How to fix it
Do not use a shell: run a fixed program with an argument list, and validate input. Resolve paths and check they stay inside an allowed root:
subprocess.run(["git", "log", "--", ref], shell=False, check=True,
capture_output=True, timeout=30)
ROOT = Path(ALLOWED_DIR).resolve()
target = (ROOT / path).resolve()
if not target.is_relative_to(ROOT):
raise ValueError("path outside allowed directory")If a command must be chosen by the model, map an allowlisted name to a fixed argv. Use query placeholders for SQL, and annotate destructive tools so clients ask before running them.
What this checker looks for
This page runs mcp-audit, which reads
mcp.json / .mcp.json / claude_desktop_config.json and MCP server source (Python, JS/TS). The rules most relevant to this page:
| Rule | What it finds |
|---|---|
MCP101 | Shell command built from tool input |
MCP102 | File access without path containment |
MCP103 | SQL built from tool input |
MCP104 | Tool fetches arbitrary URLs (SSRF) |
MCP105 | Raw web content returned to the model |
MCP106 | Destructive tool without annotations |
MCP107 | Secret from environment returned in tool result |
MCP108 | Code evaluation of tool input |
Every finding has a rule id, a severity, file:line, the offending line (secrets masked),
why it matters and how to fix it. Run mcp-audit rules for the full list.