Skip to content

AAK-MCP-TOOL-UNSAFE-EVAL-001: Unsafe eval()/exec()/compile() inside @mcp.tool handler (CVE-2026-44717 class)

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

What it detects

An MCP tool handler routes a tool-parameter value through eval(), exec(), compile(), __import__(), or SymPy parse_expr() without local_dict/global_dict pinning. This is the architectural class behind CVE-2026-44717 (mcp-calculate-server, v0.3.18 named-pin row AAK-MCPCALC-CVE-2026-44717-PIN-001) and generalizes to any single-author MCP server with the same shape — independent of upstream package identity. The Python AST visitor matches functions decorated with @mcp.tool / @server.tool / @app.tool / @fastmcp.tool / @tool whose body contains an eval / exec / compile / __import__ / unsafe parse_expr call with an argument bound to the function's parameter set.

How to fix

Replace eval(expr) with ast.literal_eval(expr) for trusted-literal inputs, or with SymPy parse_expr(expr, local_dict={}, global_dict={}, evaluate=True) plus a strict symbol allow-list for math. Validate input length + char-set before evaluation. The mcp-calculate-server 0.1.1 fix is one canonical example of the safer shape.

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

agent-audit-kit scan . --rules AAK-MCP-TOOL-UNSAFE-EVAL-001

Limitations

Looks inside the body of the decorated function only, at calls to eval, exec, compile, __import__ or parse_expr whose argument is a parameter's bare name. A helper that does the eval (return _evaluate(expression)) and a transformed argument (eval(expression.strip())) are not reported. A Python file over 512 KB is not read.

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-UNSAFE-EVAL-001.md: the page then shows that text, with the registry reference appended under it.