AAK-MCP-ERROR-LEAK-001: Raw exception text reaches an MCP client or a remote A2A peer
- Severity
- MEDIUM
- Category
- MCP Configuration (
mcp-config) - Scanner
agent_audit_kit/scanners/mcp_server_code.py- Auto-fixable
- No.
- SARIF name
McpErrorExceptionLeak
What it detects
An except block puts the exception's own text in a client-facing error (CWE-209): ToolError(f"...{e}"), McpError(str(e)), a JSON-RPC error message built from str(exc) or repr(exc), or traceback.format_exc() sent to a client or a remote A2A peer. A pydantic validation error, for one, shows input values, the backend's types and its version. A fixed message beside logger.exception loses nothing for the operator and does not fire.
How to fix
Send the client a fixed message, and log the detail on the server with logger.exception. JSON-RPC 2.0 says the message should be a concise single sentence, and its data member may be omitted.
To confirm the finding is gone, report only this rule:
agent-audit-kit scan . --rules AAK-MCP-ERROR-LEAK-001
Limitations
Python: an except body that passes str(e), repr(e), an f-string of e, % or .format formatting of e, or traceback.format_exc() to ToolError, McpError, ErrorData, JSONRPCError, ResourceError or PromptError in a file importing mcp or fastmcp, or builds {"error": {"message": ...}} from it there; or to new_agent_text_message, TaskStatusUpdateEvent, failed or update_status in a file importing a2a or google.adk.a2a. A tool handler that returns str(e) as its result is not reported, since a tool's result is how the model is told a call failed; a returned traceback.format_exc() is. A local holding the text first is not followed. TypeScript and JavaScript: new McpError(...) holding err.message, err.stack, String(err) or an interpolated err, for the names err, error, e, ex and exc, by pattern on one line. A source file over 512 KB is not read.
References
- OWASP MCP Top 10: MCP10:2025 (Context Injection & Over-Sharing)
- OWASP Agentic Top 10: ASI07 (Insecure Inter-Agent Communication)
- Adversa AI MCP Top 25 (AAK-defined ids): ADV-AUTH-01 (Missing Authentication)
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-ERROR-LEAK-001.md: the page then shows that text, with the registry reference appended under it.