---
title: "CWE-150: Improper Neutralization of Escape, Meta, or Control Sequences"
url: https://radicalnotion.ai/cwe/cwe-150
type: cwe
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."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

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

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Incomplete
- **CVEs with this as primary weakness:** 73
- **Of those, in CISA KEV:** 0
- **New in 2026:** 39
- **CWE catalog version:** 4.21

## 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.

## Alternate terms

- **ANSI injection:** injection of ANSI escape sequences.

## Modes of introduction

| Phase | Note |
| --- | --- |
| Build and Compilation | During LLM training, escape sequences may be assigned within token entry values. |
| Implementation | Interactive command line interfaces have become more commonplace with growing system administration needs and human-friendly TUIs (text-based user interfaces); logging user-generated values into the terminal into one of these sessions is no longer safe. |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |

## Applicable platforms

**Technologies:** AI/ML (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| 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

### Mitigation

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 (Input Validation)

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 (Output Encoding)

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 (Input Validation)

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.

Effectiveness: High. By restricting output to only printable characters, this effectively removes any escape codes.

### 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.

Effectiveness: Limited. This could raise the exploitation effort for an adversary, but the adversary might still be able to get string together multiple tokens in order to form the escape code.

## 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.)

Effectiveness: High

## Demonstrative examples

### Example 1

Consider a situation in which an AI agent uses LLM output based on training data from untrusted sources.

Suppose an attacker is able to inject input into the training data that is used by the LLM. If a person is using a terminal emulator to interact with the LLM on the command line, if the output contains escape codes, then the emulator might act on those codes, e.g., to change color, flash text, or (in some cases) leak sensitive information or execute code. In one documented case, a terminal would handle an OSC (Operating System Command) for setting the working directory by processing a file:// URL in a way that could perform a DNS lookup for an adversary-controlled domain, leading to an information leak \[REF-1526\].

## Observed examples

| CVE | Description |
| --- | --- |
| 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. |

## Real CVEs with this weakness (sample of 12 of 73)

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2023-26055 | XWiki Commons may allow privilege escalation to programming rights via user's first name | critical | 10.0 | - | No | 2023-03-02 |
| CVE-2022-30123 | Possible shell escape sequence injection vulnerability in Rack | critical | 10.0 | - | No | 2022-12-05 |
| CVE-2020-6932 | - | critical | 10.0 | - | No | 2020-08-12 |
| CVE-2025-47284 | Gardener vulnerable to metadata injection for a project secret that can lead to privilege escalation | critical | 9.9 | - | No | 2025-05-19 |
| CVE-2025-25286 | Crayfish allows Remote Code Execution via Homarus Authorization header | critical | 9.8 | - | No | 2025-02-13 |
| CVE-2023-3265 | - | critical | 9.8 | - | No | 2023-08-14 |
| CVE-2017-0899 | RubyGems Code Injection vulnerability | critical | 9.8 | - | No | 2017-08-31 |
| CVE-2007-3845 | Mozilla: Unescaped URIs passed to external programs | critical | 9.3 | - | No | 2007-08-08 |
| CVE-2026-26149 | Microsoft Power Apps Desktop Client Spoofing Vulnerability | critical | 9.0 | - | No | 2026-04-14 |
| CVE-2026-19591 | OpenAI Codex Improper Neutralization of Control Sequences Remote Code Execution Vulnerability | high | 8.8 | - | No | 2026-09-01 |
| CVE-2026-3108 | Terminal Escape Injection in mmctl Report Posts Command | high | 8.8 | - | No | 2026-03-26 |
| CVE-2025-0975 | IBM MQ code execution | high | 8.8 | - | No | 2025-02-28 |

## Related attack patterns (CAPEC)

- [CAPEC-134](https://radicalnotion.ai/capec/capec-134): Email Injection
- [CAPEC-41](https://radicalnotion.ai/capec/capec-41): Using Meta-characters in E-mail Headers to Inject Malicious Payloads
- [CAPEC-81](https://radicalnotion.ai/capec/capec-81): Web Server Logs Tampering
- [CAPEC-93](https://radicalnotion.ai/capec/capec-93): Log Injection-Tampering-Forging

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-138](https://radicalnotion.ai/cwe/cwe-138) | Improper Neutralization of Special Elements |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Escape, Meta, or Control Character / Sequence | - | - |
| The CERT Oracle Secure Coding Standard for Java (2011) | Do not log unsanitized user input | IDS03-J | - |
| Software Fault Patterns | Tainted input to command | SFP24 | - |

## Frequently asked questions

### What is CWE-150?

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.

### What CVEs are caused by CWE-150?

73 recorded CVEs are attributed to CWE-150, including CVE-2023-26055, CVE-2022-30123 and CVE-2020-6932.

### How do you prevent CWE-150?

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.

### How is CWE-150 detected?

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.)

### What are the consequences of CWE-150?

Exploiting CWE-150 can lead to: Execute Unauthorized Code or Commands, Hide Activities, Unexpected State.

### Is CWE-150 actively exploited?

73 recorded CVEs are caused by CWE-150; none are currently in CISA's KEV catalog of actively exploited flaws.

Primary source: [MITRE CWE](https://cwe.mitre.org/data/definitions/150.html)

---

Source: [RadicalNotion.AI](https://radicalnotion.ai/cwe/cwe-150). Licensed CC BY-NC 4.0; attribute RadicalNotion.AI and link the source page when you reuse this data.
