ANSI Escape Injection Flaw Discovered in MCP Servers: New Attack Vector Hides Instructions From Humans While AI Reads Them
Key Takeaways
- ▸ANSI escape sequences create an asymmetric attack surface: invisible to rendered terminals but fully legible to AI models reading raw bytes
- ▸MCP servers that relay external content (URLs, API responses, databases) to agents without sanitizing ANSI codes allow attackers to hide instructions from human reviewers while model agents execute them
- ▸DAST scanners can automatically detect ANSI injection by testing live MCP servers with payloads and monitoring for escape sequences in agent-consumable response fields
Summary
Security researchers have identified ANSI escape sequence injection (AESI) as a critical vulnerability class in Model Context Protocol (MCP) servers—the infrastructure Anthropic built to connect AI agents with external tools and data sources. Unlike terminal-based ANSI attacks that are invisible to human eyes, these escape sequences remain fully legible to language models, creating a blindspot where attackers can inject hidden instructions that bypass human review but execute flawlessly in agent workflows.
The attack surfaces in two variants: direct-fetch AESI (where a model tool fetches compromised URLs) and stored AESI (where malicious data persists in server responses). The vulnerability echoes earlier output-neutralization failures in Kubernetes and Git, where terminal control codes spoofed legitimate output. Because MCP servers stream text directly into agent-consumable fields—tool results, resource reads, and prompt templates—every data source becomes a potential injection surface.
The research demonstrates that DAST (Dynamic Application Security Testing) scanners can reliably detect these vulnerabilities by exercising live MCP servers with crafted inputs and inspecting responses for evidence of ANSI sequences in model-facing fields. The black-box, runtime approach proves essential since exploitability depends entirely on how servers process and relay text in real deployment conditions.
- Similar vulnerabilities have precedent in Kubernetes (CVE-2021-25743) and Git (CVE-2024-52005), suggesting this class of flaw is widespread in systems that process untrusted data
Editorial Opinion
This research exposes a fundamental tension in AI agent design: the richer the information an agent consumes, the more invisible attack surfaces emerge. ANSI injection is particularly insidious because it exploits the one-way mirror between human observation and model comprehension—a gap that grows wider as agents gain access to more external tools and datasources. The fact that DAST can detect these vulnerabilities automatically is good news, but it also signals that ANSI sanitization should now be a standard defense layer in any MCP server, similar to how output encoding became mandatory after web injection vulnerabilities matured.



