AAK-LOGINJ-001: MCP tool logs caller-controlled input without CRLF/ANSI sanitization
- Severity
- MEDIUM
- Category
- Taint Analysis (
taint-analysis) - Scanner
agent_audit_kit/scanners/log_injection.py- Auto-fixable
- No.
- SARIF name
McpLogInjection
What it detects
A @tool-decorated function parameter flows into logger.info / print / sys.stdout.write / console.log without stripping control characters (\r, \n, \x1b) first. CVE-2026-6494 (AAP MCP, CVSS 5.3 MEDIUM, CWE-117) lets an attacker forge log entries and inject ANSI escape sequences to socially engineer an operator. A write to stdout (print without file=, sys.stdout, console.log) does more harm in a STDIO server: stdout carries the JSON-RPC stream, which the MCP stdio transport says must hold nothing but valid MCP messages, so caller input written there corrupts it and a whole JSON-RPC line can inject a message. Stripping control characters does not stop that; diagnostics belong on stderr.
How to fix
Write diagnostics to stderr (print(..., file=sys.stderr) or a logger that writes there), never to stdout: stdout carries the protocol in a STDIO server, so caller input there can inject messages. Strip \r\n\x1b (or accept only printable ASCII) before logging anything derived from tool input. Prefer structured logging (JSON/logfmt) so log consumers aren't confused by forged lines.
To confirm the finding is gone, report only this rule:
agent-audit-kit scan . --rules AAK-LOGINJ-001
Limitations
Reads the arguments of print (to stdout, or with file= set to sys.stdout, sys.stderr, a bare stdout or stderr or None), of a level method (info, exception and the rest) of logger, log or the logging module, of any sys.stdout or sys.stderr method and of console.<log|info|warn|error>, in functions whose decorator name ends in tool and the functions nested in them. A call inside a tool function nested in another is read for the innermost one only, with its parameters, so a nested tool that logs a parameter of the tool around it is not reported. A logger held as an attribute (self.logger.info(...)) is not read: measured on 9,137 Python files from GitHub code searches for MCP servers, it would add 69 findings, only 44 of them (64%) a raw string parameter. Nor is a logger under another name (_logger.info(...)). A call to a function whose name contains sanitize, strip_control or escape_controls anywhere in the function clears it, whichever value that touches, and so does sanitising code written anywhere in it, a comment included: .replace("\r" or .replace("\n", .encode("ascii", "ignore"), or an re.sub( whose pattern begins with an escape such as \r or \x1b. The word sanitize in a docstring, a comment or a name that is not called does not.
References
- CVE: CVE-2026-6494
- OWASP MCP Top 10: MCP08:2025 (Lack of Audit and Telemetry)
- OWASP Agentic Top 10: ASI09 (Human-Agent Trust Exploitation)
- Adversa AI MCP Top 25 (AAK-defined ids): ADV-LOG-01
- CSA AI Controls Matrix (AICM): LOG-06
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-LOGINJ-001.md: the page then shows that text, with the registry reference appended under it.