Skip to content

AAK-SSRF-001: Unvalidated outbound HTTP in MCP tool handler

Severity
CRITICAL
Category
MCP Configuration (mcp-config)
Scanner
agent_audit_kit/scanners/ssrf_patterns.py
Auto-fixable
No.
SARIF name
SsrfUnvalidatedUrl

What it detects

An MCP or agent tool handler fetches a URL provided by the caller with no host/scheme validation. This is the classic SSRF shape (CWE-918). A smolagents forward or a LangChain _run counts the same as an MCP tool, since the model chooses the URL either way.

How to fix

Validate the scheme (https only), resolve the host, and reject private-range IPs (RFC 1918, 169.254.*, 127.*, ::1/128, fc00::/7).

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

agent-audit-kit scan . --rules AAK-SSRF-001

Limitations

Reads only files that contain @tool, createTool, McpServer, FastMCP, mcp.tool, Server.run_streamable_http, BaseTool or StructuredTool, or def forward and output_type with a class on a Tool base (a smolagents tool). In Python a fetch's URL counts as caller input only inside a function read as a tool the way AAK-TAINT-001 reads one (decorated @tool, @mcp.tool, @server.tool, @langchain.tools.tool, @crewai.tool or @autogen.tool, or a low-level @<server>.call_tool() handler), or decorated @function_tool, or passed to add_tool(...), as func= or to from_function(...), or the _run, _arun, run or arun method of a class whose bases reach BaseTool or StructuredTool in the same file (through the file's own classes, a name it imports or assigns the base as, or a subscripted base; a base another file defines is not followed), or the forward method of a class on a Tool or PipelineTool base, when the file imports from smolagents or the class sets inputs and output_type, or a function or method called call_tool or ending in _call_tool (where only arguments, args, params, input, tool_input, kwargs, payload, body, query, request, req and event count), when one of its parameters, or a local bound from one there, can set the URL's host. So a FastMCP instance under another name (@app.tool()) is skipped, a value handed to a helper that calls requests.get is not followed, nor is one a helper hands back (base = resolve_base(host)), and a caller's value after a host the code wrote out (f"https://api.example.com/{path}", or BASE + path with BASE read from the environment) is not reported. A += extends the value bound above it in source order, whatever branch either sits in, so url = "https://", then url += "eu.example.com/" under an if, then url += path reads the host as fixed, although when the if is not taken the caller's path names it. A built URL is read only to its 256th piece (an f-string's text or value, a + operand, an item of a list it joins or the separator between two), a list joined by name to its own 256th, URLs built one inside another (a list joined inside a list, or a + inside a call inside a +) 40 deep, and a % or .format template to its 16th field (an escaped %%, {{ or }} counting as one), so a host written after that is missed. Its text is read to the 512th character, so a template field after that is not filled, and a caller's value after an authority the code wrote out longer than that is taken for the host. A value is followed through four names (url = a, a = b, b = c, c = <value>), so one only a fifth name holds is not read, whether a base, a caller's value, or the template a %, .format or string.Template fills. A name is read in the scope that binds it, as Python reads it, for the bindings the rule reads (=, an augmented assignment (+=, -= and the rest), an annotated = with a value, for, a comprehension, :=, parameters, global and nonlocal); a name only an import, a def or class, a with ... as or except ... as target, a match capture, a del or a bare annotation binds is not taken as the scope's own, so the same name around it is read instead. "".join(d) is read as the keys of d only when the scope binds d once, to a dict literal, a dict comprehension or a dict(...) call; a d bound twice is read whole, values included, so d = {"u": "https://" + host} rebound under an if is reported although the join yields only the keys (a false finding, never a missed one, which AAK-SSRF-004 and -005 share). A fetch is requests.get/post/put/delete/head/request, httpx.get/post/put/delete/request/stream, urllib.request.urlopen, aiohttp.request, or get, post or request on something called session or client (and a client's stream), and its URL is the first argument, the second after the method for request and stream, or url=. So http.get(...) and requests.patch(...) are missed. A urlparse( call, a startswith("https, a scheme == "https or scheme != "https comparison or an allow-list name from AAK-SSRF-005 anywhere in the file counts as validation, although an https prefix still allows internal hosts, while urlsplit(...) with a hostname comparison and startswith on a variable do not, so a URL checked that way is still reported. In TypeScript only req.query, req.body, req.params, request.json, event.body, tool_input, arguments, input, and params[ or args[ directly followed by a letter, digit or underscore (args[key]), count as caller input, so fetch(args.url) and fetch(args["url"]) are missed.

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