Skip to content

AAK-MCP-020: MCP handler shares routing with an unauthenticated path

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

What it detects

Two HTTP routes registered in the same Go or TypeScript/JavaScript file reach the same MCP handler, and only one of them applies authentication: an auth middleware on the route, or the handler wrapped in an auth function. The other route serves every tool the first one protects, with no credential. This is the CVE-2026-33032 bypass: nginx-ui's /mcp_message ran the same mcp.ServeHTTP as /mcp, behind an IP allowlist that was empty by default and nothing else.

How to fix

Put the authentication where no route can miss it: on the router or group every MCP route is registered on (r.Use(AuthRequired()), a gin group made with the middleware, app.use("/mcp", requireAuth)), or inside the shared handler. If another route has to stay open, such as a health check, give it a handler of its own that reaches no tool.

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

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

Limitations

Reads gin, echo, chi and net/http routes in Go, and Express-style route calls (app.post(path, ...middleware, handler) and its get, put, patch, delete and all siblings, as Express, Hono and Koa Router write them) in TypeScript and JavaScript; Python servers are not read. Two routes are paired only when they sit in the same file and the same block, have different methods or paths, run the same handler value (or inline functions whose only statement is the same call handing on the request), and one path is an MCP endpoint (/mcp, /api/v1/mcp, /mcp/message) or an SSE or message path in a file that builds an MCP server. So routes registered in two files or two functions are not paired, a path held in a constant (app.get(MCP_PATH, h)) is not read, and inline handlers that do more than delegate are not compared. An unauthenticated route that carries a middleware the check cannot name (auth, a body parser, CORS, logging, rate limiting or an IP allowlist) is skipped, since that middleware may be the authentication, and auth on a whole router anywhere in the file (app.use(auth), r.Use(auth), a group made with auth, the mux handed to an auth wrapper) covers every route on it, whatever the registration order. Test files and mock servers are not read. A route AAK-MCPWN-001 reports is left to that rule, so a scan restricted to AAK-MCP-020 does not list it. Bounds that keep it linear: files over 512,000 bytes are not read; a middleware argument is read for its first 200 characters (an auth word further in is not seen), a handler argument longer than 200 characters that is not an inline function is not compared, and an inline function counts only when its => or { comes within 200 characters of its parameter list; a Go group counts only when it is assigned (g := r.Group(...)) within 200 characters before the call; and in TypeScript and JavaScript a regex literal must close within 512 characters of its /, or it is read as division and a backtick in it can hide the routes after it.

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