---
title: "CWE-138: Improper Neutralization of Special Elements"
url: https://radicalnotion.ai/cwe/cwe-138
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 control elements or syntactic markers 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-138: Improper Neutralization of Special Elements

- **Abstraction:** Class
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 20
- **Of those, in CISA KEV:** 0
- **New in 2026:** 6
- **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 control elements or syntactic markers when they are sent to a downstream component.

Most languages and protocols have their own special elements such as characters and reserved words. These special elements can carry control implications. If product does not prevent external control or influence over the inclusion of such special elements, the control flow of the program may be altered from what was intended. For example, both Unix and Windows interpret the symbol \< ("less than") as meaning "read input from a file".

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Confidentiality, Integrity, Availability, Other | Execute Unauthorized Code or Commands, Alter Execution Logic, DoS: Crash, Exit, or Restart | - |

## Potential mitigations

### Implementation

Developers should anticipate that special elements (e.g. delimiters, symbols) will be injected into input vectors of their product. One defense is to create an allowlist (e.g. a regular expression) that defines valid input according to the requirements specifications. Strictly filter any input that does not match against the allowlist. Properly encode your output, and quote any elements that have special meaning to the component with which you are communicating.

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

Use and specify an appropriate output encoding to ensure that the special elements are well-defined. A normal byte sequence in one encoding could be a special element in another.

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

## Demonstrative examples

### Example 1

The following code takes untrusted input and uses a regular expression to filter "../" from the input. It then appends this result to the /home/user/ directory and attempts to read the file in the final resulting path.

Bad code:

```perl
my $Username = GetUntrustedInput();
$Username =~ s/\.\.\///;
my $filename = "/home/user/" . $Username;
ReadAndSendFile($filename);
```

Attack code:

```
../../../etc/passwd
```

Result code:

```
../../etc/passwd
```

Result code:

```
/home/user/../../etc/passwd
```

### Example 2

The following example assigns some character values to a list of characters and prints them each individually, and then as a string. The third character value is intended to be an integer taken from user input and converted to an int. The first print statement will print each character separated by a space.

Bad code:

```c
char *foo;
foo=malloc(sizeof(char)*5);
foo[0]='a';
foo[1]='a';
foo[2]=fgetc(stdin);
foo[3]='c';
foo[4]='\0';
printf("%c %c %c %c %c \n",foo[0],foo[1],foo[2],foo[3],foo[4]);
printf("%s\n",foo);
```

However, if a NULL byte is read from stdin by fgetc, then it will return 0. When foo is printed as a string, the 0 at character foo\[2\] will act as a NULL terminator, and the second printf() statement will not print foo\[3\].

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2001-0677 | Read arbitrary files from mail client by providing a special MIME header that is internally used to store pathnames for attachments. |
| CVE-2000-0703 | Setuid program does not cleanse special escape sequence before sending data to a mail program, causing the mail program to process those sequences. |
| 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. |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2023-24531 | Output of "go env" does not sanitize values in cmd/go | critical | 9.8 | - | No | 2024-07-02 |
| CVE-2023-42117 | Exim Improper Neutralization of Special Elements Remote Code Execution Vulnerability | critical | 9.8 | - | No | 2024-05-03 |
| CVE-2017-10906 | Fluentd Escape Sequence Injection Vulnerability | critical | 9.8 | - | No | 2017-12-08 |
| CVE-2016-0750 | Infinispan: Deserialization of untrusted data in the Hot Rod Java client via automatic byte-array deserialization | high | 8.8 | - | No | 2018-09-11 |
| CVE-2026-130737 | Grav 2.0.0 before 2.2.18 Privilege Escalation via YAML Merge Key | high | 8.6 | - | No | 2026-11-18 |
| CVE-2022-2429 | Ultimate SMS Notifications for WooCommerce \<= 1.4.1 - CSV Injection | high | 8.0 | - | No | 2022-09-06 |
| CVE-2024-38133 | Windows Kernel Elevation of Privilege Vulnerability | high | 7.8 | - | No | 2024-08-13 |
| CVE-2026-55841 | Graylog: Fortigate syslog message parser can be exploited to modify or delete fields from the original message | high | 7.5 | - | No | 2026-08-28 |
| CVE-2026-26129 | M365 Copilot Information Disclosure Vulnerability | high | 7.5 | - | No | 2026-05-07 |
| CVE-2026-32178 | .NET Spoofing Vulnerability | high | 7.5 | - | No | 2026-04-14 |
| CVE-2024-51500 | Failure to check for packets from the broadcast address allows potential DDoS amplification attack in Meshtastic firmware | high | 7.5 | - | No | 2024-11-04 |
| CVE-2017-1000361 | OpenDaylight Controller DoS | high | 7.5 | - | No | 2017-04-24 |

## Related attack patterns (CAPEC)

- [CAPEC-105](https://radicalnotion.ai/capec/capec-105): HTTP Request Splitting
- [CAPEC-15](https://radicalnotion.ai/capec/capec-15): Command Delimiters
- [CAPEC-34](https://radicalnotion.ai/capec/capec-34): HTTP Response Splitting

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-707](https://radicalnotion.ai/cwe/cwe-707) | Improper Neutralization |
| Child | [CWE-140](https://radicalnotion.ai/cwe/cwe-140) | Improper Neutralization of Delimiters |
| Child | [CWE-147](https://radicalnotion.ai/cwe/cwe-147) | Improper Neutralization of Input Terminators |
| Child | [CWE-148](https://radicalnotion.ai/cwe/cwe-148) | Improper Neutralization of Input Leaders |
| Child | [CWE-149](https://radicalnotion.ai/cwe/cwe-149) | Improper Neutralization of Quoting Syntax |
| Child | [CWE-150](https://radicalnotion.ai/cwe/cwe-150) | Improper Neutralization of Escape, Meta, or Control Sequences |
| Child | [CWE-151](https://radicalnotion.ai/cwe/cwe-151) | Improper Neutralization of Comment Delimiters |
| Child | [CWE-152](https://radicalnotion.ai/cwe/cwe-152) | Improper Neutralization of Macro Symbols |
| Child | [CWE-153](https://radicalnotion.ai/cwe/cwe-153) | Improper Neutralization of Substitution Characters |
| Child | [CWE-154](https://radicalnotion.ai/cwe/cwe-154) | Improper Neutralization of Variable Name Delimiters |
| Child | [CWE-155](https://radicalnotion.ai/cwe/cwe-155) | Improper Neutralization of Wildcards or Matching Symbols |
| Child | [CWE-156](https://radicalnotion.ai/cwe/cwe-156) | Improper Neutralization of Whitespace |
| Child | [CWE-157](https://radicalnotion.ai/cwe/cwe-157) | Failure to Sanitize Paired Delimiters |
| Child | [CWE-158](https://radicalnotion.ai/cwe/cwe-158) | Improper Neutralization of Null Byte or NUL Character |
| Child | [CWE-159](https://radicalnotion.ai/cwe/cwe-159) | Improper Handling of Invalid Use of Special Elements |
| Child | [CWE-160](https://radicalnotion.ai/cwe/cwe-160) | Improper Neutralization of Leading Special Elements |
| Child | [CWE-162](https://radicalnotion.ai/cwe/cwe-162) | Improper Neutralization of Trailing Special Elements |
| Child | [CWE-164](https://radicalnotion.ai/cwe/cwe-164) | Improper Neutralization of Internal Special Elements |
| Child | [CWE-464](https://radicalnotion.ai/cwe/cwe-464) | Addition of Data Structure Sentinel |
| Child | [CWE-790](https://radicalnotion.ai/cwe/cwe-790) | Improper Filtering of Special Elements |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Special Elements (Characters or Reserved Words) | - | - |
| PLOVER | Custom Special Character Injection | - | - |
| Software Fault Patterns | Tainted input to command | SFP24 | - |

## Frequently asked questions

### What is CWE-138?

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

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

20 recorded CVEs are attributed to CWE-138, including CVE-2023-24531, CVE-2023-42117 and CVE-2017-10906.

### How do you prevent CWE-138?

Developers should anticipate that special elements (e.g. delimiters, symbols) will be injected into input vectors of their product. One defense is to create an allowlist (e.g. a regular expression) that defines valid input according to the requirements specifications. Strictly filter any input that does not match against the allowlist. Properly encode your output, and quote any elements that have special meaning to the component with which you are communicating.

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

Exploiting CWE-138 can lead to: Execute Unauthorized Code or Commands, Alter Execution Logic, DoS: Crash, Exit, or Restart.

### Is CWE-138 actively exploited?

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

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

---

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