CWEweakness

CWE-150 Improper Neutralization of Escape, Meta, or Control Sequences

Official page ↗
Alternate terms
ANSI injection
Abstraction
Variant
Structure
Simple
Status
Incomplete
Languages
Not Language-Specific
CWE version
5.0

Description

The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could be interpreted as escape, meta, or control character sequences when they are sent to a downstream component.

Common consequences

• Integrity: Execute Unauthorized Code or Commands, Hide Activities, Unexpected State — ANSI escape codes can be used for low-severity attacks such as changing the color of console output, but they can also be used to arbitrarily move the cursor, clear the screen, and make fake prompts inside the interactive CLI via malicious user input. In some contexts - depending on the functionality of the terminal in use - ANSI escape codes can be used to execute arbitrary code.

Potential mitigations

• Developers should anticipate that escape, meta and control characters/sequences will be injected/removed/manipulated in the input vectors of their product. Use an appropriate combination of denylists and allowlists to ensure only valid, expected and appropriate input is processed by the system. • [Implementation] Assume all input is malicious. Use an "accept known good" input validation strategy, i.e., use a list of acceptable inputs that strictly conform to specifications. Reject any input that does not strictly conform to specifications, or transform it into something that does. When performing input validation, consider all potentially relevant properties, including length, type of input, the full range of acceptable values, missing or extra inputs, syntax, consistency across related fields, and conformance to business rules. As an example of business rule logic, "boat" may be syntactically valid because it only contains alphanumeric characters, but it is not valid if the input is only expected to contain colors such as "red" or "blue." Do not rely exclusively on looking for malicious or malformed inputs. This is likely to miss at least one undesirable input, especially if the code's environment changes. This can give attackers enough room to bypass the intended validation. However, denylists can be useful for detecting potential attacks or determining which inputs are so malformed that they should be rejected outright. • [Implementation] While it is risky to use dynamically-generated query strings, code, or commands that mix control and data together, sometimes it may be unavoidable. Properly quote arguments and escape any special characters within those arguments. The most conservative approach is to escape or filter all characters that do not pass an extremely strict allowlist (such as everything that is not alphanumeric or white space). If some special characters are still needed, such as white space, wrap each argument in quotes after the escaping/filtering step. Be careful of argument injection (CWE-88). • [Implementation] Inputs should be decoded and canonicalized to the application's current internal representation before being validated (CWE-180). Make sure that the application does not decode the same input twice (CWE-174). Such errors could be used to bypass allowlist validation schemes by introducing dangerous inputs after they have been checked. • [Implementation] When using output from an LLM, neutralize or strip escape codes before redirecting output to the terminal or other rendering engine that would process the codes. The neutralization could require that the character be printable and/or allowable whitespace, such as a carriage return or newline. Be deliberate about what to allow. • [Build and Compilation] When using an LLM: during tokenizer training, suppress escape codes from the tokenizer's vocabulary. Depending on context, this could be accomplished by removing the codes from input to the tokenizer, or removing the map from the string to its token ID. It is generally unlikely that this removal would adversely affect the quality or correctness of what is generated, e.g. advice requests for terminal settings to change colors.

Detection methods

• Automated Static Analysis: Automated static analysis, commonly referred to as Static Application Security Testing (SAST), can find some instances of this weakness by analyzing source code (or binary/compiled code) without having to execute it. Typically, this is done by building a model of data flow and control flow, then searching for potentially-vulnerable patterns that connect "sources" (origins of input) with "sinks" (destinations where the data interacts with external components, a lower layer such as the OS, etc.)

Observed examples

• CVE-2024-27936: Chain: JavaScript-based application removes ANSI escape sequences in a dialog that asks permission for a particular file, causing the wrong filename to be visually presented for user approval (CWE-451), but the filename still contains the ANSI escape sequences (CWE-150), potentially causing the user to grant access to the wrong file. • CVE-2002-0542: The mail program processes special "~" escape sequence even when not in interactive mode. • CVE-2000-0703: Setuid program does not filter escape sequences before calling mail program. • CVE-2002-0986: Mail function does not filter control characters from arguments, allowing mail message content to be modified. • CVE-2003-0020: Multi-channel issue. Terminal escape sequences not filtered from log files. • CVE-2003-0083: Multi-channel issue. Terminal escape sequences not filtered from log files. • CVE-2003-0021: Terminal escape sequences not filtered by terminals when displaying files. • CVE-2003-0022: Terminal escape sequences not filtered by terminals when displaying files. • CVE-2003-0023: Terminal escape sequences not filtered by terminals when displaying files. • CVE-2003-0063: Terminal escape sequences not filtered by terminals when displaying files. • CVE-2000-0476: Terminal escape sequences not filtered by terminals when displaying files. • CVE-2001-1556: MFV. (multi-channel). Injection of control characters into log files that allow information hiding when using raw Unix programs to read the files.

Related

Attack pattern · CAPEC (4)

  • CAPEC-134 Email Injection attack pattern
  • CAPEC-41 Using Meta-characters in E-mail Headers to Inject Malicious Payloads attack pattern
  • CAPEC-81 Web Server Logs Tampering attack pattern
  • CAPEC-93 Log Injection-Tampering-Forging attack pattern

Observed example · CVE (12)

  • CVE-2024-27936 Deno is a JavaScript, TypeScript, and WebAssembly runtime with secure defaults. vulnerability
  • CVE-2003-0083 Apache 1.3 before 1.3.25 and Apache 2.0 before version 2.0.46 does not filter terminal escape sequences from its access logs, which could… vulnerability
  • CVE-2003-0020 Apache does not filter terminal escape sequences from its error logs, which could make it easier for attackers to insert those sequences… vulnerability
  • CVE-2003-0021 The "screen dump" feature in Eterm 0.9.1 and earlier allows attackers to overwrite arbitrary files via a certain character escape sequence… vulnerability
  • CVE-2003-0022 The "screen dump" feature in rxvt 2.7.8 allows attackers to overwrite arbitrary files via a certain character escape sequence when it is… vulnerability
  • CVE-2003-0023 The menuBar feature in rxvt 2.7.8 allows attackers to modify menu options and execute arbitrary commands via a certain character escape… vulnerability
  • CVE-2003-0063 The xterm terminal emulator in XFree86 4.2.0 and earlier allows attackers to modify the window title via a certain character escape… vulnerability
  • CVE-2002-0986 The mail function in PHP 4.x to 4.2.2 does not filter ASCII control characters from its arguments, which could allow remote attackers to… vulnerability
  • CVE-2002-0542 mail in OpenBSD 2.9 and 3.0 processes a tilde (~) escape character in a message even when it is not in interactive mode, which could allow… vulnerability
  • CVE-2001-1556 The log files in Apache web server contain information directly supplied by clients and does not filter or quote control characters, which… vulnerability
  • CVE-2000-0703 suidperl (aka sperl) does not properly cleanse the escape sequence "~!" before calling /bin/mail to send an error report, which allows… vulnerability
  • CVE-2000-0476 xterm, Eterm, and rxvt allow an attacker to cause a denial of service by embedding certain escape characters which force the window to be… vulnerability

Child of · CWE (1)

  • CWE-138 Improper Neutralization of Special Elements weakness

Referenced by CAPEC · weakness (4)

  • CAPEC-134 Email Injection attack pattern
  • CAPEC-41 Using Meta-characters in E-mail Headers to Inject Malicious Payloads attack pattern
  • CAPEC-81 Web Server Logs Tampering attack pattern
  • CAPEC-93 Log Injection-Tampering-Forging attack pattern

Referenced by CVE · weakness (91)

  • CVE-2026-54162 Ember is a real-time terminal dashboard for Caddy servers with FrankenPHP support. vulnerability
  • CVE-2026-55467 OpenPrinting CUPS is an open source printing system for Linux and other Unix-like operating systems. vulnerability
  • CVE-2026-81856 Improper Neutralization of Escape, Meta, or Control Sequences vulnerability in hexpm hex allows a malicious package publisher or a hostile… vulnerability
  • CVE-2026-105801 openapi-python-client generates Python clients from OpenAPI documents. vulnerability
  • CVE-2026-104026 In Sapling SCM prior to v0.2.20260929-102736, control characters were allowed to be embedded in Git subtree URLs. vulnerability
  • CVE-2026-103431 colmux in collectl before 4.3.20.2 does not sanitize ANSI/VT100 terminal escape sequences in data received from remote collectl instances… vulnerability
  • CVE-2026-102601 Flysystem is an open source file storage library for PHP. vulnerability
  • CVE-2026-100866 onefetch through 2.28.1 writes repository information field values to the terminal without removing control characters, allowing terminal… vulnerability
  • CVE-2026-100867 spaceship-prompt through 4.22.5 fails to sanitize control characters from project manifest version fields before rendering them in the zsh… vulnerability
  • CVE-2026-93421 Mesop is a Python-based UI framework that allows users to build web applications. vulnerability
  • CVE-2026-90895 Affected versions of MISP’s interactive CLI shell implement access control independently from the normal web application, causing several… vulnerability
  • CVE-2026-90773 procs through 0.14.12 fails to sanitize escape sequences in process command lines before displaying them in the Command column. vulnerability
  • CVE-2026-82710 Improper Neutralization of Escape, Meta, or Control Sequences vulnerability in ash-project usage_rules allows a malicious package publisher… vulnerability
  • CVE-2026-82584 Improper Neutralization of Escape, Meta, or Control Sequences vulnerability in ash-project igniter allows a malicious package publisher to… vulnerability
  • CVE-2026-19591 OpenAI Codex CLI for Windows, macOS, and Linux and Codex Desktop for Windows and macOS misclassified certain PowerShell commands as safe… vulnerability
  • CVE-2026-72847 broot renders each file and directory name in its interactive tree view exactly as read from the filesystem. vulnerability
  • CVE-2026-75483 powerlevel10k fails to neutralize control characters in the package.json version field when rendering the package prompt segment. vulnerability
  • CVE-2026-73506 Oh My Posh is the most customisable and low-latency cross platform/shell prompt renderer. vulnerability
  • CVE-2026-73414 Shescape is a simple shell escape library for JavaScript. vulnerability
  • CVE-2026-73036 Bash-it 3.2.0 contains a terminal escape sequence injection vulnerability in the barbuk theme's Python virtualenv prompt segment that… vulnerability
  • CVE-2026-72913 Kitty is a cross-platform GPU based terminal. vulnerability
  • CVE-2026-73035 npm-check-updates through 23.0.2, fixed in commit b554b84, contains a terminal escape sequence injection vulnerability that allows an… vulnerability
  • CVE-2026-64654 GitHub CLI (gh) is GitHub's official command line tool. vulnerability
  • CVE-2026-39879 Due to a missing sanitization call in… vulnerability
  • CVE-2026-62948 OpenWrt is a Linux operating system targeting embedded devices. vulnerability
  • CVE-2026-49147 App::Ack versions through 3.10.0 for Perl print unsanitised terminal escape sequences from filenames in several output modes. vulnerability
  • CVE-2026-11373 Net::Statsite::Client versions through 1.1.0 for Perl allow metric injections. vulnerability
  • CVE-2026-54057 Kitty is a cross-platform GPU based terminal. vulnerability
  • CVE-2026-50637 Metrics::Any::Adapter::Statsd versions before 0.04 for Perl does not protect against metric injections. vulnerability
  • CVE-2026-50638 Metrics::Any::Adapter::DogStatsd versions before 0.04 for Perl does not protect against metric injections. vulnerability
Show all 91 ›