Skip to content

AAK-MCP-019: MCP auth check runs after a resource lookup

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

What it detects

A Go MCP HTTP handler looks a resource up by something the caller sent (a path, query or form parameter), answers a miss with "not found" straight away, and checks the caller's credential only after that, answering 401 or 403. A caller with no credential tells the two answers apart and learns which resources exist, and the lookup runs for every caller.

How to fix

Check the caller's credential before the handler looks up anything the request names. Where the credential to check depends on that resource (a per-adapter auth setting), answer an unknown name and a refused credential the same way, with one status and body, so the response does not reveal which names exist.

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

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

Limitations

Reads Go handlers only (net/http, gin, echo); TypeScript, JavaScript and Python handlers are not read. It reports one form of the claim: a lookup on a receiver (store.Get, db.QueryRow, repo.FindByID) among the handler's own statements, whose argument is a path, query or form parameter the handler read from the request (seen in the argument's first 200 characters), answered "not found", with a return, by the if that holds it or the if on the next line, before one of the handler's top-level if statements calls a function named for authentication with the request and answers 401 or 403; the call may sit in an if nested inside it. Each if is read for its first 1,000 characters, so a not-found answer, a return, an auth call or a 401 or 403 further into one is not seen. Other work before the check (dispatching the MCP request, an outbound call, a write) is not reported, nor is a miss answered with another status, a key taken from the request body, a lookup inside a nested block or a helper, a gate that is not a top-level if (one inside a for, switch or plain else block, or in a helper), or a credential compared inline rather than through a function. An if counts only when its keyword starts the line that holds its { within 400 characters before it, and the if on the next line answers the miss only when the lookup starts within 200 characters of its line's start, only blanks follow it on its line and that line ends within 200 characters of its ), and the if starts within 200 characters after that line ends. The handler must be registered in the same file, on a route with no auth middleware or wrapper and no group or router-wide auth, so one registered in another file is not read, and the handler's name or body must mention MCP: mcp in any case, or tools/call or tools/list (a JSON-RPC handler that does neither is not read). A route's middleware and handler arguments are read for their first 200 characters; an inline handler that only calls a named handler is matched to it only when its { opens within 200 characters of its parameter list, while one that does the lookup itself is read wherever its { opens on its line; a Go group counts only when it is assigned (g := r.Group(...)) within 200 characters before the call, and files over 512,000 bytes are not read.

References

  • OWASP MCP Top 10: MCP07:2025 (Insufficient Authentication & Authorization)
  • OWASP Agentic Top 10: ASI03 (Identity and Privilege Abuse)
  • Adversa AI MCP Top 25 (AAK-defined ids): ADV-AUTH-05

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