CWE-95: Improper Neutralization of Directives in Skip to content

Security weakness

CWE-95 Improper Neutralization of Directives in Dynamically Evaluated Code

A variant-level weakness that can lead to private data exposed, data, pages or code changed and downtime and lost sales. Here is what it is, what it can cost you and how to close it.

  • Senior security engineers
  • 540+ projects delivered
  • Reply within one business day

Quick answer

What is CWE-95?

Improper Neutralization of Directives in Dynamically Evaluated Code: 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”).

Business impact

What CWE-95 could cost your business

MITRE documents what this weakness can do. Here is what that means for a website, store or app.

Confidentiality

Private data exposed

Customer records, credentials, orders or internal files can be read by people who should never see them.

  • Read Files or Directories
  • Read Application Data
  • Execute Unauthorized Code or Commands

Integrity

Data, pages or code changed

Prices, orders, content or the code your site runs can be altered without your approval.

  • Execute Unauthorized Code or Commands

Availability

Downtime and lost sales

Crashes, slowdowns or exhausted resources can take your site, store or app offline.

  • Execute Unauthorized Code or Commands

Access Control

Accounts and admin areas exposed

Logins and permission checks can be bypassed, putting admin and customer accounts at risk.

  • Bypass Protection Mechanism
  • Gain Privileges or Assume Identity

Non-Repudiation

Actions you cannot trace

Changes can happen without a reliable record, which slows incident response and compliance work.

  • Hide Activities

Free security check

Is CWE-95 hiding in your site?

A senior engineer checks your site, store or app for this weakness and the rest of the CWE Top 25, then sends a prioritized fix plan within one business day. No obligation.

Official definition

How MITRE defines CWE-95

Improper Neutralization of Directives in Dynamically Evaluated Code

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

Also known as: Eval Injection

Weakness ID
CWE-95
Type
Variant
Status
Incomplete
Likelihood of exploit
Medium
Applies to
Java, JavaScript, Python, Perl, PHP, Ruby
Introduced during
Implementation

Prevention

How to fix CWE-95, phase by phase

Every mitigation from the CWE entry, in the order a project runs: plan, build, test, operate.

  1. 01

    Architecture and Design

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

    Implementation

    • 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.
    • 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.
    • 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].

Detection and evidence

How CWE-95 is found, and where it has hit

The testing methods MITRE recommends, and real vulnerabilities this weakness has caused.

How it is detected

  • Automated Static AnalysisAutomated 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.

Real vulnerabilities it caused

  • CVE-2024-4181Framework for LLM applications allows eval injection via a crafted response from a hosting provider.
  • CVE-2022-2054Python compiler uses eval() to execute malicious strings as Python code.
  • CVE-2021-22204Chain: 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-22205Chain: 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-5071Eval injection in PHP program.
  • CVE-2002-1750Eval injection in Perl program.

How we fix it

From finding to fixed: how Codefreex closes CWE-95

  1. Scan and confirm

    We test your site, store or app for this weakness and the rest of the CWE Top 25 with automated scanning and manual review, and confirm what is actually exploitable.

  2. Fix at the source

    We change the code, configuration or dependency that causes it, not just the symptom, and plan the changes to avoid downtime.

  3. Verify the fix

    We retest every finding, check that nothing else broke and hand you a short report you can share with your team, client or auditor.

  4. Keep it fixed

    Updates, monitoring and maintenance so the weakness does not return with the next plugin, theme, app or code change.

Related weaknesses

FAQ

CWE-95: FAQs

Short answers for owners and developers. Not sure whether your site is affected? Ask us to check.

What is CWE-95?

CWE-95, “Improper Neutralization of Directives in Dynamically Evaluated Code”, is a software weakness catalogued by MITRE in the Common Weakness Enumeration. 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”).

How serious is CWE-95?

MITRE rates the likelihood of exploit as Medium. It can affect confidentiality, access control, integrity, availability, with impacts such as read files or directories, read application data, bypass protection mechanism. The real risk depends on where the weakness sits and what data or functions it exposes.

How do you prevent CWE-95?

If possible, refactor your code so that it does not need to use eval() at all. 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.

Can Codefreex check my site for CWE-95?

Yes. A senior engineer reviews your site, store or app for CWE-95 and the rest of the CWE Top 25, confirms what is exploitable and sends a prioritized fix plan within one business day. Start with the free security check form on this page.

Which technologies does CWE-95 affect?

MITRE lists it as applicable to Java, JavaScript, Python, Perl, PHP, Ruby. In practice any software that matches the weakness description can be affected, including custom code, plugins, themes and third-party libraries.

Free security check

Find out if CWE-95 affects your site

Send your URL. A senior engineer checks for this weakness and the rest of the CWE Top 25, and replies within one business day with what to fix first.

  • A senior strategist reviews your request, not a sales bot
  • Clear scope, timeline and estimate within one business day
  • Free 30-minute discovery call, no obligation
  • NDA available on request

Weakness data from the Common Weakness Enumeration (CWE®) version 5.0, Copyright © 2006–2026, The MITRE Corporation. CWE is free to use by any organization or individual for any research, development, and/or commercial purposes under the CWE Terms of Use. CWE is a registered trademark of The MITRE Corporation. The business impact, risk profile and plain-English guidance on this page are written by Codefreex and are general information, not a security assessment of your system.