What is CWE-94?
The product uses externally influenced input to construct part or all of a code segment without properly neutralizing syntax or other elements that can change the intended code's behavior.
The product uses externally influenced input to construct part or all of a code segment without properly neutralizing syntax or other elements that can change the intended code's behavior.
The product constructs all or part of a code segment using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the syntax or behavior of the intended code segment.
This weakness occurs when data from an upstream component is incorporated into dynamically generated code and remains able to influence its syntax, control flow, or executable operations. The resulting code may perform actions beyond the product's intended behavior, particularly when input reaches an evaluation or execution mechanism without strict restrictions on permitted constructs. The record identifies implementation as the phase in which this weakness is realized and lists interpreted languages and AI/ML technologies as applicable contexts, with platform prevalence recorded as sometimes or undetermined.
This is a base-level, simple weakness involving an externally influenced value flowing into generated code. Its defining behavior is the failure to constrain or correctly neutralize special syntax, allowing input to alter intended control flow or invoke operations that were not meant to be available. The record also identifies the related term "Code Injection" and associates the weakness with interpreted environments and AI/ML applications.
Possible consequences include bypassing authentication or another protection mechanism when injected code controls access decisions, gaining privileges or assuming another identity, and executing unauthorized code or commands. The latter can affect confidentiality, integrity, and availability, including arbitrary code execution and loss of data integrity. Injected actions may also be unlogged, allowing activity to be hidden and weakening non-repudiation.
| Impact | Scope | Explanation |
|---|---|---|
| Bypass Protection Mechanism | Access Control | In some cases, injectable code controls authentication; this may lead to a remote vulnerability. |
| Gain Privileges or Assume Identity | Access Control | Injected code can access resources that the attacker is directly prevented from accessing. |
| Execute Unauthorized Code or Commands | Integrity, Confidentiality, Availability | When a product allows a user's input to contain code syntax, it might be possible for an attacker to craft the code in such a way that it will alter the intended control flow of the product. As a result, code injection can often result in the execution of arbitrary code. Code injection attacks can also lead to loss of data integrity in nearly all cases, since the control-plane data injected is always incidental to data recall or writing. |
| Hide Activities | Non-Repudiation | Often the actions performed by injected control code are unlogged. |
Architecture and design: Refactor the product so it does not need to generate code dynamically. If dynamic generation cannot be avoided, run the code in a strictly bounded jail or sandbox, such as an environment using chroot or AppArmor; this only limits impact on the operating system, may not be feasible, and must not introduce jail-related weaknesses such as CWE-243.
Implementation: Treat all input as malicious and apply strict allowlist validation that accepts only values conforming to the required length, type, range, syntax, consistency, and business rules. Do not rely only on denylists or searches for malformed input. Limit permitted code constructs, since checking that a value is alphanumeric may still allow references to dangerous functions such as system, exec, or exit. For Python, the record notes ast.literal_eval as an alternative to eval because it is designed not to execute code, but marks this practice as discouraged because deeply nested input can still cause excessive memory or stack consumption.
Testing and operation: Use fuzzing, robustness testing, and fault injection with diverse inputs, checking that the product does not become unstable, crash, or produce incorrect results. Use an environment with automatic taint propagation that prevents command execution with tainted variables, such as Perl's -T switch, while carefully validating data before it is treated as untainted. The same taint-based control is listed under both compilation or build hardening and environment hardening.
Automated static analysis, commonly implemented as SAST, can detect some instances without executing the product. It can model data flow and control flow and look for paths from input sources to sinks where data reaches external components or lower layers such as the operating system. Its coverage is limited to patterns that the analysis can model, so it does not establish that every instance has been found.
| Method | Approach | Effectiveness |
|---|---|---|
| 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.) | High |
The official record provides representative examples, not an exhaustive list. Examples include LLM and AI application frameworks that pass user input or a provider-crafted response into Python exec or eval, including CVE-2023-29374, CVE-2024-5565, and CVE-2024-4181. Other examples involve Python, PHP, and Perl evaluation or direct code injection, such as CVE-2022-2054, CVE-2008-5071, CVE-2002-1750, CVE-2008-5305, CVE-2002-1752, CVE-2002-1753, CVE-2005-1527, CVE-2005-2837, CVE-2005-1921, CVE-2005-2498, CVE-2005-3302, CVE-2007-1253, CVE-2001-1471, CVE-2002-0495, CVE-2005-1876, CVE-2005-1894, and CVE-2003-0395. The set also includes CVE-2021-22204, where an upstream string-boundary issue enabled evaluation injection, and CVE-2020-8218, described as code injection in a VPN product; both are noted as exploited in the wild in the supplied record.
Below are representative vulnerabilities related to this CWE, prioritized by severity.
CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.
CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.
Explore CyStack VulnScanen