---
title: "CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code"
url: https://radicalnotion.ai/cwe/cwe-95
type: cwe
description: "The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before using the input in a dynamic evaluation call (e.g. \"eval\")."
updated: 2026-11-10
source: RadicalNotion.AI
license: CC BY-NC 4.0 (https://creativecommons.org/licenses/by-nc/4.0/)
---

# CWE-95: Improper Neutralization of Directives in Dynamically Evaluated Code

- **Abstraction:** Variant
- **Structure:** Simple
- **Status:** Incomplete
- **Likelihood of exploit:** Medium
- **CVEs with this as primary weakness:** 208
- **Of those, in CISA KEV:** 3
- **New in 2026:** 114
- **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 using the input in a dynamic evaluation call (e.g. "eval").

## Alternate terms

- Eval Injection

## Modes of introduction

| Phase | Note |
| --- | --- |
| Implementation | REALIZATION: This weakness is caused during implementation of an architectural security tactic. |
| Implementation | This weakness is prevalent in handler/dispatch procedures that might want to invoke a large number of functions, or set a large number of variables. |

## Applicable platforms

**Languages:** Java (Undetermined), JavaScript (Undetermined), Python (Undetermined), Perl (Undetermined), PHP (Undetermined), Ruby (Undetermined), Interpreted (Undetermined)

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

## 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 or at least modify what code can be executed. |
| Non-Repudiation | Hide Activities | Often the actions performed by injected control code are unlogged. |

## Potential mitigations

### Architecture and Design, Implementation (Refactoring)

If possible, refactor your code so that it does not need to use eval() at all.

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

Inputs should be decoded and canonicalized to the application's current internal representation before being validated (CWE-180, CWE-181). Make sure that your application does not inadvertently decode the same input twice (CWE-174). Such errors could be used to bypass allowlist schemes by introducing dangerous inputs after they have been checked. Use libraries such as the OWASP ESAPI Canonicalization control.

Consider performing repeated canonicalization until your input does not change any more. This will avoid double-decoding and similar scenarios, but it might inadvertently modify inputs that are allowed to contain properly-encoded dangerous content.

### Implementation

For Python programs, it is frequently encouraged to use the ast.literal\_eval() function instead of eval, since it is intentionally designed to avoid executing code. However, an adversary could still cause excessive memory or stack consumption via deeply nested structures \[REF-1372\], so the python documentation discourages use of ast.literal\_eval() on untrusted data \[REF-1373\].

Effectiveness: Discouraged Common Practice

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

edit-config.pl: This CGI script is used to modify settings in a configuration file.

Bad code:

```perl
use CGI qw(:standard);

sub config_file_add_key {
    my ($fname, $key, $arg) = @_;
    # code to add a field/key to a file goes here
}

sub config_file_set_key {
    my ($fname, $key, $arg) = @_;
    # code to set key to a particular file goes here
}

sub config_file_delete_key {
    my ($fname, $key, $arg) = @_;
    # code to delete key from a particular file goes here
}

sub handleConfigAction {
    my ($fname, $action) = @_;
    my $key = param('key');
    my $val = param('val');
    # this is super-efficient code, especially if you have to invoke
    # any one of dozens of different functions!

    my $code = "config_file_$action_key(\$fname, \$key, \$val);";
    eval($code);
}

$configfile = "/home/cwe/config.txt";
print header;
if (defined(param('action'))) {
    handleConfigAction($configfile, param('action'));
}
else {
    print "No action specified!\n";
}
```

Attack code:

```
add_key(",","); system("/bin/ls");
```

Result code:

```
config_file_add_key(",","); system("/bin/ls");
```

### Example 2

This simple python3 script asks a user to supply a comma-separated list of numbers as input and adds them together.

Bad code:

```python
def main():
    sum = 0
    try:
        numbers = eval(input("Enter a comma-separated list of numbers: "))
    except SyntaxError:
        print("Error: invalid input")
        return
    for num in numbers:
        sum = sum + num
    print(f"Sum of {numbers} = {sum}")
main()
```

Attack code:

```
__import__('subprocess').getoutput('rm -r *')
```

Good code:

```python
def main():
    sum = 0
    numbers = input("Enter a comma-separated list of numbers: ").split(",")
    try:
        for num in numbers:
            sum = sum + int(num)
        print(f"Sum of {numbers} = {sum}")
    except ValueError:
        print("Error: invalid input")
main()
```

## Observed examples

| CVE | Description |
| --- | --- |
| CVE-2024-4181 | Framework for LLM applications allows eval injection via a crafted response from a hosting provider. |
| CVE-2022-2054 | Python compiler uses eval() to execute malicious strings as Python code. |
| CVE-2021-22204 | Chain: regex in EXIF processor code does not correctly determine where a string ends (CWE-625), enabling eval injection (CWE-95), as exploited in the wild per CISA KEV. |
| CVE-2021-22205 | Chain: backslash followed by a newline can bypass a validation step (CWE-20), leading to eval injection (CWE-95), as exploited in the wild per CISA KEV. |
| CVE-2008-5071 | Eval injection in PHP program. |
| CVE-2002-1750 | Eval injection in Perl program. |
| CVE-2008-5305 | Eval injection in Perl program using an ID that should only contain hyphens and numbers. |
| CVE-2002-1752 | Direct code injection into Perl eval function. |
| CVE-2002-1753 | Eval injection in Perl program. |
| CVE-2005-1527 | Direct code injection into Perl eval function. |
| CVE-2005-2837 | Direct code injection into Perl eval function. |
| CVE-2005-1921 | MFV. code injection into PHP eval statement using nested constructs that should not be nested. |
| CVE-2005-2498 | MFV. code injection into PHP eval statement using nested constructs that should not be nested. |
| CVE-2005-3302 | Code injection into Python eval statement from a field in a formatted file. |
| CVE-2007-1253 | Eval injection in Python program. |
| CVE-2001-1471 | Chain: Resultant eval injection. An invalid value prevents initialization of variables, which can be modified by attacker and later injected into PHP eval statement. |

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

| CVE | Title | Severity | CVSS | EPSS | CISA KEV | Published |
| --- | --- | --- | --- | --- | --- | --- |
| CVE-2025-24893 | Remote code execution as guest via SolrSearchMacros request in xwiki | critical | 9.8 | - | Yes | 2025-02-20 |
| CVE-2024-36401 | Remote Code Execution (RCE) vulnerability in evaluating property name expressions in Geoserver | critical | 9.3 | - | Yes | 2024-07-01 |
| CVE-2023-7101 | Arbitrary Code Execution (ACE) Vulnerability | high | 8.4 | - | Yes | 2023-12-24 |
| CVE-2026-61539 | Xinference: Remote code execution via unsafe \`eval()\` in Llama3 tool-call parsing | critical | 10.0 | - | No | 2026-08-21 |
| CVE-2025-68271 | Unauthenticated Remote Code Execution in openc3-api | critical | 10.0 | - | No | 2026-01-13 |
| CVE-2025-54322 | - | critical | 10.0 | - | No | 2025-12-27 |
| CVE-2025-55728 | XWiki Remote Macros vulnerable to remote code execution using the panel macro | critical | 10.0 | - | No | 2025-09-09 |
| CVE-2025-55727 | XWiki Remote Macros vulnerable to remote code execution from width parameter in the column macro | critical | 10.0 | - | No | 2025-09-09 |
| CVE-2013-10070 | PHP-Charts v1.0 PHP Code Execution | critical | 10.0 | - | No | 2025-08-05 |
| CVE-2024-31996 | XWiki Commons missing escaping of \`{\` in Velocity escapetool allows remote code execution | critical | 10.0 | - | No | 2024-04-10 |
| CVE-2024-31984 | XWiki Platform: Remote code execution through space title and Solr space facet | critical | 10.0 | - | No | 2024-04-10 |
| CVE-2024-31982 | XWiki Platform: Remote code execution as guest via DatabaseSearch | critical | 10.0 | - | No | 2024-04-10 |

## Related attack patterns (CAPEC)

- [CAPEC-35](https://radicalnotion.ai/capec/capec-35): Leverage Executable Code in Non-Executable Files

## Related weaknesses

| Relationship | CWE | Name |
| --- | --- | --- |
| Parent | [CWE-94](https://radicalnotion.ai/cwe/cwe-94) | Improper Control of Generation of Code |

## Taxonomy mappings

| Taxonomy | Entry | Id | Fit |
| --- | --- | --- | --- |
| PLOVER | Direct Dynamic Code Evaluation ('Eval Injection') | - | - |
| OWASP Top Ten 2007 | Malicious File Execution | A3 | CWE More Specific |
| OWASP Top Ten 2004 | Injection Flaws | A6 | CWE More Specific |
| Software Fault Patterns | Tainted input to command | SFP24 | - |
| SEI CERT Perl Coding Standard | Do not invoke the eval form with a string argument | IDS35-PL | Exact |

## Frequently asked questions

### What is CWE-95?

The product receives input from an upstream component, but it does not neutralize or incorrectly neutralizes code syntax before using the input in a dynamic evaluation call (e.g. "eval").

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

208 recorded CVEs are attributed to CWE-95, including CVE-2025-24893, CVE-2024-36401 and CVE-2023-7101. 3 are listed in CISA's Known Exploited Vulnerabilities (KEV) catalog.

### Is CWE-95 part of the OWASP Top 10?

CWE-95 maps to OWASP Top Ten 2007: Malicious File Execution (A3) in the OWASP security taxonomy.

### How do you prevent CWE-95?

If possible, refactor your code so that it does not need to use eval() at all.

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

Exploiting CWE-95 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-95 actively exploited?

Yes. 3 CWE-95 vulnerabilities are in CISA's KEV catalog of actively exploited flaws, out of 208 recorded CVEs.

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

---

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