---
title: "CWE-96: Improper Neutralization of Directives in Statically Saved Code"
url: https://radicalnotion.ai/cwe/cwe-96
type: cwe
description: "The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before inserting the input into an executable resource, such as a library, configuration file, or template."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-96: Improper Neutralization of Directives in Statically Saved Code

- **Abstraction:** Base
- **Structure:** Simple
- **Status:** Draft
- **CVEs with this as primary weakness:** 35
- **Of those, in CISA KEV:** 1
- **New in 2026:** 8
- **CWE catalog version:** 4.21

## Description

The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before inserting the input into an executable resource, such as a library, configuration file, or template.

## Alternate terms

- Static Code Injection

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |
| Implementation | This issue is frequently found in PHP applications that allow users to set configuration variables that are stored within executable PHP files. Technically, this could also be performed in some compiled code (e.g., by byte-patching an executable), although it is highly unlikely. |

## Applicable platforms

**Languages:** PHP (Undetermined), Perl (Undetermined), Interpreted (Undetermined)

## Common consequences

| Scope | Impact | Note |
| --- | --- | --- |
| Confidentiality | Read Files or Directories, Read Application Data | The injected code could access restricted data / files. |
| Access Control | Bypass Protection Mechanism | In some cases, injectable code controls authentication; this may lead to a remote vulnerability. |
| Access Control | Gain Privileges or Assume Identity | Injected code can access resources that the attacker is directly prevented from accessing. |
| Integrity, Confidentiality, Availability, Other | Execute Unauthorized Code or Commands | Code injection attacks can lead to loss of data integrity in nearly all cases as the control-plane data injected is always incidental to data recall or writing. Additionally, code injection can often result in the execution of arbitrary code. |
| Non-Repudiation | Hide Activities | Often the actions performed by injected control code are unlogged. |

## Potential mitigations

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

Perform proper output validation and escaping to neutralize all code syntax from data written to code files.

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

## Demonstrative examples

### Example 1

This example attempts to write user messages to a message file and allow users to view them.

Bad code:

```php
$MessageFile = "messages.out";
if ($_GET["action"] == "NewMessage") {
    $name = $_GET["name"];
    $message = $_GET["message"];
    $handle = fopen($MessageFile, "a+");
    fwrite($handle, "<b>$name</b> says '$message'<hr>\n");
    fclose($handle);
    echo "Message Saved!<p>\n";
}
else if ($_GET["action"] == "ViewMessages") {
    include($MessageFile);
}
```

Attack code:

```
name=h4x0r
message=%3C?php%20system(%22/bin/ls%20-l%22);?%3E
```

Attack code:

```
<?php system("/bin/ls -l");?>
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2002-0495 | Perl code directly injected into CGI library file from parameters to another CGI program. |
| CVE-2005-1876 | Direct PHP code injection into supporting template file. |
| CVE-2005-1894 | Direct code injection into PHP script that can be accessed by attacker. |
| CVE-2003-0395 | PHP code from User-Agent HTTP header directly inserted into log file implemented as PHP script. |
| CVE-2007-6652 | Chain: execution after redirect allows non-administrator to perform static code injection. |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2026-86218 | pre-authentication remote code execution | critical | 10.0 | - | Yes | 2026-09-06 |
| CVE-2024-55877 | XWiki allows remote code execution from account through macro descriptions and XWiki.XWikiSyntaxMacrosList | critical | 10.0 | - | No | 2024-12-12 |
| CVE-2024-55662 | XWiki allows remote code execution through the extension sheet | critical | 10.0 | - | No | 2024-12-12 |
| CVE-2015-2079 | - | critical | 9.9 | - | No | 2025-04-28 |
| CVE-2024-13264 | Opigno module - Critical - Arbitrary PHP code execution - SA-CONTRIB-2024-028 | critical | 9.8 | - | No | 2025-01-09 |
| CVE-2023-39726 | - | critical | 9.8 | - | No | 2023-10-26 |
| CVE-2023-40397 | iOS and iPadOS: WebKit - A remote attacker may be able to cause arbitrary javascript code execution | critical | 9.8 | - | No | 2023-09-06 |
| CVE-2022-0895 | Static Code Injection in microweber/microweber | critical | 9.8 | - | No | 2022-03-10 |
| CVE-2020-6144 | OS4Ed openSIS install remote code execution vulnerability | critical | 9.8 | - | No | 2020-09-01 |
| CVE-2020-6143 | OS4Ed openSIS install remote code execution vulnerability | critical | 9.8 | - | No | 2020-09-01 |
| CVE-2025-30091 | - | critical | 9.4 | - | No | 2025-03-25 |
| CVE-2024-43400 | XWiki Platform allows XSS through XClass name in string properties | critical | 9.4 | - | No | 2024-08-19 |

## Related attack patterns (CAPEC)

- [CAPEC-35](https://radicalnotion.ai/capec/capec-35): Leverage Executable Code in Non-Executable Files
- [CAPEC-73](https://radicalnotion.ai/capec/capec-73): User-Controlled Filename
- [CAPEC-77](https://radicalnotion.ai/capec/capec-77): Manipulating User-Controlled Variables
- [CAPEC-81](https://radicalnotion.ai/capec/capec-81): Web Server Logs Tampering
- [CAPEC-85](https://radicalnotion.ai/capec/capec-85): AJAX Footprinting

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-94](https://radicalnotion.ai/cwe/cwe-94) | Improper Control of Generation of Code |
| Child | [CWE-97](https://radicalnotion.ai/cwe/cwe-97) | Improper Neutralization of Server-Side Includes (SSI) Within a Web Page |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Direct Static Code Injection | - | - |
| Software Fault Patterns | Tainted Input to Command | SFP24 | - |

## Frequently asked questions

### What is CWE-96?

The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before inserting the input into an executable resource, such as a library, configuration file, or template.

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

35 recorded CVEs are attributed to CWE-96, including CVE-2026-86218, CVE-2024-55877 and CVE-2024-55662. 1 is listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### How do you prevent CWE-96?

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.

### How is CWE-96 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-96?

Exploiting CWE-96 can lead to: Read Files or Directories, Read Application Data, Bypass Protection Mechanism, Gain Privileges or Assume Identity, Execute Unauthorized Code or Commands, Hide Activities.

### Is CWE-96 actively exploited?

Yes. 1 CWE-96 vulnerability is in CISA's KEV catalog of actively exploited flaws, out of 35 recorded CVEs.

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

---

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