CWE-138: Improper Neutralization of Special Elements
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.
Last updated
Overview
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".
Real-world CVEs
12 recorded CVEs are caused by CWE-138 (Improper Neutralization of Special Elements). The highest-severity and most recent are shown first. 4 new CWE-138 CVEs have been recorded so far in 2026 (1 in 2025).
- CVE-2023-42117Critical · CVSS 9.8 · EPSS 92th2024-05-03
- CVE-2023-7012Critical · CVSS 9.6 · EPSS 24th2024-07-16
- CVE-2016-0750High · CVSS 8.8 · EPSS 83th2018-09-11
- CVE-2022-2429High · CVSS 8.0 · EPSS 51th2022-09-06
- CVE-2024-38133High · CVSS 7.8 · EPSS 52th2024-08-13
- CVE-2026-55841
Graylog: Fortigate syslog message parser can be exploited to modify or delete fields from the original message
High · CVSS 7.5 · EPSS 28th2026-08-28 - CVE-2026-26129
M365 Copilot Information Disclosure Vulnerability
High · CVSS 7.5 · EPSS 64th2026-05-07 - CVE-2026-32178
.NET Spoofing Vulnerability
High · CVSS 7.5 · EPSS 82th2026-04-14 - CVE-2022-0024High · CVSS 7.2 · EPSS 73th2022-05-11
- CVE-2023-22288Medium · CVSS 6.8 · EPSS 33th2023-03-20
- CVE-2026-20009
Cisco Secure Firewall Adaptive Security Appliance SSH Partial Private Key Authentication Bypass Vulnerability
Medium · CVSS 5.3 · EPSS 31th2026-03-04 - CVE-2025-48939
tarteaucitron.js vulnerable to DOM Clobbering via document.currentScript
Medium · CVSS 4.2 · EPSS 7th2025-07-03
Common consequences
What can happen when CWE-138 is exploited.
Execute Unauthorized Code or Commands, Alter Execution Logic, DoS: Crash, Exit, or Restart
Affects: Confidentiality, Integrity, Availability, Other
How it happens
When it is introduced
Typically introduced during these phases of the software lifecycle.
How to prevent it
Practical mitigations for CWE-138, grouped by where in the lifecycle they apply.
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.
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.
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.
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.
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).
Code examples
Illustrative examples from MITRE showing how the weakness appears in code.
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.
Vulnerable example
my $Username = GetUntrustedInput();Attack input
../../../etc/passwdResulting query
../../etc/passwdResulting query
/home/user/../../etc/passwdThe 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.
Vulnerable example
char *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].
Illustrative examples
Real CVEs that MITRE cites as examples of this weakness.
- 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.
Terminology & mappings
Mapped taxonomies
- PLOVER: Special Elements (Characters or Reserved Words)
- PLOVER: Custom Special Character Injection
- Software Fault Patterns: Tainted input to command (SFP24)
Attack patterns
CAPEC attack patterns that exploit this weakness.
Frequently asked questions
Common questions about CWE-138.
- 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?
- 12 recorded CVEs are attributed to CWE-138, including CVE-2023-42117, CVE-2023-7012, CVE-2016-0750.
- 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?
- 12 recorded CVEs are caused by CWE-138; none are currently in CISA's KEV catalog of actively exploited flaws.
References
- MITRE CWE definition (CWE-138) (opens in a new tab)
- CWE-138 vulnerabilities on NVD (opens in a new tab)
- Learn: What is a CWE?
Weakness data is sourced from the MITRE CWE catalog (v4.20). CVE associations are aggregated and kept current by RadicalNotion.AI.
Stay ahead of CWE-138
Get alerted the moment a new CWE-138 vulnerability affects your stack, with AI-written analysis, severity context, and remediation guidance.