MCPSafe.io
RegistryThreatsMethodologyDocsPricingScanSign in
MCPSafe.io

Security checks for MCP servers — public packages and private repos, fast or deep.

Legal

Privacy PolicyCookie PolicyTerms of ServiceSecurity disclosure

Resources

State of MCP SecuritySupportSystem statusMade in Germany 🇩🇪

© 2026 MCPSafe. All rights reserved.

GDPR — Privacy Policy
← Threat Catalog

Interaction & Data Flow

ANSI escape injection in tool output

MEDIUMAIVSS 5.0CWE: CWE-150OWASP: LLM05Agentic: T10Rule: MCP-083

Tool output contains ANSI control sequences (`\x1b[...`) that re-colour, clear the screen, or remap keys when the client renders output to a terminal — used to hide instructions or spoof authoritative UI.

What it is

ANSI escape codes are in-band control signals the terminal interprets — cursor movement, colour, screen clearing, and even keyboard remapping (some terminals). When tool output is rendered in a TTY-like view (Claude Code, terminal-based MCP clients), an escape sequence embedded in the response can rewrite what the user sees, hide adjacent tool output, or overwrite a prompt to mislead the next keystroke.

Why it matters for MCP

Many MCP clients render tool output to terminals. A tool that forwards attacker-supplied text (from a webpage, file, or API response) can smuggle in escape sequences the user never notices. The defence is simple: strip or escape control characters before returning.

Vulnerable example

example.py
1
@server.tool()
2
def show_log(log_text: str) -> str:
3
    # Attacker-controlled log line can contain \x1b[2J (clear screen)
4
    # or reposition the cursor to hide other tool output.
5
    return log_text

Secure example

example.py
1
import re
2
3
_CTRL = re.compile(r"[\x00-\x08\x0b\x0c\x0e-\x1f\x7f\x1b]")
4
5
@server.tool()
6
def show_log(log_text: str) -> str:
7
    return _CTRL.sub("", log_text)

How MCPSafe detects this

We flag tool-handler return paths that emit strings containing literal ANSI escape patterns (`\x1b[`, `\033[`, `\u001b[`) or that pass through external content without a control-character stripper.

See the full threat catalog for every documented detection.

Framework alignment

OWASP LLM Top-10 (2025)
LLM05 — Improper Output Handling
OWASP Agentic AI Top-10
T10 — Overwhelming Human-in-the-Loop
AIVSS v0.5
5.0 (MEDIUM)AIVSS:1.0/S:MEDIUM/AV:N/AU:H/BR:M/CD:I

Further reading

  • CWE-150: Improper Neutralization of Escape Sequences
  • ANSI terminal injection overview (Adam Chester)

Scan an MCP server for this issue

MCPSafe runs this check — and every other rule in the catalog — on any MCP server you paste in.

Scan now