Back to Labs
Weakness (CWE)

CWE-95

Improper Neutralization of Directives in Dynamically Evaluated Code ('Eval Injection')

About

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

Common consequences

  • Confidentiality → Read Files or Directories, Read Application Data
  • Access Control → Bypass Protection Mechanism
  • Access Control → Gain Privileges or Assume Identity
  • Integrity, Confidentiality, Availability, Other → Execute Unauthorized Code or Commands
  • Non-Repudiation → Hide Activities

Mitigations

  • Architecture and Design, Implementation: If possible, refactor your code so that it does not need to use eval() at all.
  • 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 input
  • 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 ESA
  • 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].

CVEs with this weakness

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

How likely is CWE-95 to be exploited?

MITRE rates the likelihood of exploit for CWE-95 as medium.

Which platforms does CWE-95 affect?

CWE-95 has been observed on: Java, JavaScript, Python, Perl, PHP, Ruby, Interpreted, AI/ML.

How many CVEs does Rainforest track for CWE-95?

Rainforest Labs currently tracks 3 published CVEs mapped to CWE-95. They are listed on this page.

Empower Your Security Strategy with Rainforest

Discover vulnerabilities early, prioritize critical threats, and protect what truly matters. Rainforest streamlines your security operations, saving you time and reducing costs, so you can focus on what drives your business forward.