Skip to content

AAK-MCP-016: Unbounded prompt/argument size on MCP endpoint

Severity
MEDIUM
Category
MCP Configuration (mcp-config)
Scanner
agent_audit_kit/scanners/transport_limits.py
Auto-fixable
No.
SARIF name
McpUnboundedPayload

What it detects

An MCP endpoint written in Go (net/http, gin, echo, chi) or Python (FastAPI/Starlette, Flask) reads the whole request body (io.ReadAll(r.Body), json.NewDecoder(r.Body), gin's ShouldBindJSON, echo's Bind, await request.json(), request.get_json()) and nothing in the server limits its size. None of these frameworks sets a limit of its own, so one request can hold as much memory as it likes, and the prompt or tool arguments it carries reach the model at any length (token-cost denial of service).

How to fix

Bound the body before reading it. In Go, r.Body = http.MaxBytesReader(w, r.Body, 1<<20) in the handler or http.MaxBytesHandler(mux, 1<<20) where the server is built (echo: middleware.BodyLimit("1M"); chi: middleware.RequestSize(1<<20)). In Flask, set app.config["MAX_CONTENT_LENGTH"]. Starlette and FastAPI have no setting: add a middleware that answers 413 when Content-Length is over the limit and counts the bytes of a chunked body. A limit set only in a reverse proxy (nginx client_max_body_size) covers only traffic that passes through it; if that is where yours lives, accept the finding under exclude-rules in .agent-audit-kit.yml.

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

agent-audit-kit scan . --rules AAK-MCP-016

Limitations

Reads Go handlers (a function taking *http.Request, *gin.Context or echo.Context) and Python functions registered as FastAPI, Starlette or Flask routes, and only those that serve MCP: registered in the same file on a route whose path ends in an mcp segment (/mcp, /api/v1/mcp, /mcp/message, /mcp/tools/call) with no settings segment before it (/admin/mcp and /api/config/mcp, under admin, config, configs, configuration, settings, setting or preferences, are taken for a settings API and not read), or dispatching on a method only MCP has (case "tools/call":, method == "resources/read"; in a Go case list the method's string must start within 160 characters of case). A handler that dispatches only on initialize or notifications/initialized, which a language server's handshake shares, counts only in a file that names one of those methods too, so a bridge that answers the handshake and forwards every other method is missed. It is silent when the handler tests Content-Length or calls a helper named for a body limit, when a Python handler tests the length of what it read (a Go handler that compares len(body) after reading the whole body is still reported), and when the project's non-test code sets a limit anywhere (http.MaxBytesReader, http.MaxBytesHandler, echo BodyLimit, chi RequestSize, gin's RequestSizeLimiter, a .Body = reassignment through io.LimitReader, a Go ContentLength > test whose { opens on the comparison's own line within 80 characters and answers 413 within 300 characters after it with no } between, so a 413 written after a map literal (writeJSON(w, map[string]string{...}, 413)) does not count, Flask MAX_CONTENT_LENGTH, a Starlette middleware that answers 413 or compares Content-Length), so a limit on another route, or in another project of a monorepo, silences it too. Not read: TypeScript and JavaScript servers (Express and Fastify parse bodies with a default limit; Hono and Next.js depend on the runtime), a Python file that imports aiohttp, Django, Tornado, Quart, Sanic, Litestar, Falcon or Bottle, even one that uses it only as a client (a FastAPI server that calls an API through aiohttp), a body read in a helper the handler calls, a server that hands the request to a library that reads it whole (mark3labs/mcp-go's StreamableHTTPServer reads it with io.ReadAll and no limit), test files and mock or fake servers, files over 1,000,000 bytes, and a limit enforced only by a reverse proxy or the hosting platform (nginx client_max_body_size, an ingress annotation).

References

  • OWASP Agentic Top 10: ASI02 (Tool Misuse and Exploitation)
  • Adversa AI MCP Top 25 (AAK-defined ids): ADV-DOS-01

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