CWEweakness

CWE-94 Improper Control of Generation of Code

Medium Official page ↗
Alternate terms
Code Injection
Abstraction
Base
Structure
Simple
Status
Draft
Likelihood of exploit
Medium
Languages
Interpreted, Python
CWE version
5.0

Description

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.

Common consequences

• 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: Execute Unauthorized Code or Commands — 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. • Non-Repudiation: Hide Activities — Often the actions performed by injected control code are unlogged.

Potential mitigations

• [Architecture and Design] Refactor your program so that you do not have to dynamically generate code. • [Architecture and Design] Run your code in a "jail" or similar sandbox environment that enforces strict boundaries between the process and the operating system. This may effectively restrict which code can be executed by your product. Examples include the Unix chroot jail and AppArmor. In general, managed code may provide some protection. This may not be a feasible solution, and it only limits the impact to the operating system; the rest of your application may still be subject to compromise. Be careful to avoid CWE-243 and other weaknesses related to jails. • [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, 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. To reduce the likelihood of code injection, use stringent allowlists that limit which constructs are allowed. If you are dynamically constructing code that invokes a function, then verifying that the input is alphanumeric might be insufficient. An attacker might still be able to reference a dangerous function that you did not intend to allow, such as system(), exec(), or exit(). • [Testing] Use dynamic tools and techniques that interact with the product using large test suites with many diverse inputs, such as fuzz testing (fuzzing), robustness testing, and fault injection. The product's operation may slow down, but it should not become unstable, crash, or generate incorrect results. • [Operation] Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184). • [Operation] Run the code in an environment that performs automatic taint propagation and prevents any command execution that uses tainted variables, such as Perl's "-T" switch. This will force the program to perform validation steps that remove the taint, although you must be careful to correctly validate your inputs so that you do not accidentally mark dangerous inputs as untainted (see CWE-183 and CWE-184). • [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].

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

Observed examples

• CVE-2023-29374: Math component in an LLM framework translates user input into a Python expression that is input into the Python exec() method, allowing code execution - one variant of a "prompt injection" attack. • CVE-2024-5565: Python-based library uses an LLM prompt containing user input to dynamically generate code that is then fed as input into the Python exec() method, allowing code execution - one variant of a "prompt injection" attack. • 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-2020-8218: "Code injection" in VPN product, 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. • 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.

Related

Attack pattern · CAPEC (3)

  • CAPEC-242 Code Injection attack pattern
  • CAPEC-35 Leverage Executable Code in Non-Executable Files attack pattern
  • CAPEC-77 Manipulating User-Controlled Variables attack pattern

Observed example · CVE (22)

  • CVE-2024-5565 The Vanna library uses a prompt function to present the user with visualized results, it is possible to alter the prompt using prompt… vulnerability
  • CVE-2024-4181 A command injection vulnerability exists in the RunGptLLM class of the llama_index library, version 0.9.47, used by the RunGpt framework… vulnerability
  • CVE-2023-29374 In LangChain through 0.0.131, the LLMMathChain chain allows prompt injection attacks that can execute arbitrary code via the Python exec… vulnerability
  • CVE-2022-2054 Code Injection in GitHub repository nuitka/nuitka prior to 0.9. vulnerability
  • CVE-2021-22204 Improper neutralization of user data in the DjVu file format in ExifTool versions 7.44 and up allows arbitrary code execution when parsing… vulnerability
  • CVE-2020-8218 A code injection vulnerability exists in Pulse Connect Secure <9.1R8 that allows an attacker to crafted a URI to perform an arbitrary code… vulnerability
  • CVE-2008-5305 Eval injection vulnerability in TWiki before 4.2.4 allows remote attackers to execute arbitrary Perl code via the %SEARCH{}% variable. vulnerability
  • CVE-2008-5071 Multiple eval injection vulnerabilities in itpm_estimate.php in Yoxel 1.23beta and earlier allow remote authenticated users to execute… vulnerability
  • CVE-2007-1253 Eval injection vulnerability in the (a) kmz_ImportWithMesh.py Script for Blender 0.1.9h, as used in (b) Blender before 2.43, allows… vulnerability
  • CVE-2005-3302 Eval injection vulnerability in bvh_import.py in Blender 2.36 allows attackers to execute arbitrary Python code via a hierarchy element in… vulnerability
  • CVE-2005-2837 Multiple eval injection vulnerabilities in PlainBlack Software WebGUI before 6.7.3 allow remote attackers to execute arbitrary Perl code… vulnerability
  • CVE-2005-1527 Eval injection vulnerability in awstats.pl in AWStats 6.4 and earlier, when a URLPlugin is enabled, allows remote attackers to execute… vulnerability
  • CVE-2005-2498 Eval injection vulnerability in PHPXMLRPC 1.1.1 and earlier (PEAR XML-RPC for PHP), as used in multiple products including (1) Drupal, (2)… vulnerability
  • CVE-2005-1921 Eval injection vulnerability in PEAR XML_RPC 1.3.0 and earlier (aka XML-RPC or xmlrpc) and PHPXMLRPC (aka XML-RPC For PHP or php-xmlrpc)… vulnerability
  • CVE-2005-1876 Direct code injection vulnerability in CuteNews 1.3.6 and earlier allows remote attackers with administrative privileges to execute… vulnerability
  • CVE-2005-1894 Direct code injection vulnerability in FlatNuke 2.5.3 allows remote attackers to execute arbitrary PHP code by placing the code into the… vulnerability
  • CVE-2003-0395 Ultimate PHP Board (UPB) 1.9 allows remote attackers to execute arbitrary PHP code with UPB administrator privileges via an HTTP request… vulnerability
  • CVE-2002-1750 csGuestbook.cgi in CGISCRIPT.NET csGuestbook 1.0 allows remote attackers to execute arbitrary Perl code via the setup parameter, which is… vulnerability
  • CVE-2002-1752 csChatRBox.cgi in CGIScript.net csChat-R-Box allows remote attackers to execute arbitrary Perl code via the setup parameter, which is… vulnerability
  • CVE-2002-1753 csNewsPro.cgi in CGIScript.net csNews Professional (csNewsPro) allows remote attackers to execute arbitrary Perl code via the setup… vulnerability
  • CVE-2002-0495 csSearch.cgi in csSearch 2.3 and earlier allows remote attackers to execute arbitrary Perl code via the savesetup command and the setup… vulnerability
  • CVE-2001-1471 prefs.php in phpBB 1.4.0 and earlier allows remote authenticated users to execute arbitrary PHP code via an invalid language value, which… vulnerability

Child of · CWE (2)

  • CWE-74 Improper Neutralization of Special Elements in Output Used by a Downstream Component weakness
  • CWE-913 Improper Control of Dynamically-Managed Code Resources weakness

Referenced by CAPEC · weakness (3)

  • CAPEC-242 Code Injection attack pattern
  • CAPEC-35 Leverage Executable Code in Non-Executable Files attack pattern
  • CAPEC-77 Manipulating User-Controlled Variables attack pattern

Referenced by CVE · weakness (7,573)

  • CVE-2026-101288 IBM Langflow OSS 1.0.0 through 1.12.3 could allow a remote authenticated attacker to execute arbitrary code due to improper neutralization… vulnerability
  • CVE-2026-104328 IBM Langflow OSS 1.0.0 through 1.12.3 could allow a remote authenticated attacker to execute arbitrary code due to improper neutralization… vulnerability
  • CVE-2026-104339 IBM Langflow OSS 1.0.0 through 1.12.3 could allow a remote attacker to execute arbitrary code due to improper neutralization of special… vulnerability
  • CVE-2026-107328 IBM Langflow OSS 1.0.0 through 1.12.4 could allow a remote authenticated attacker to execute arbitrary code due to improper neutralization… vulnerability
  • CVE-2026-107329 IBM Langflow OSS 1.0.0 through 1.12.4 could allow a remote authenticated attacker to execute arbitrary code due to improper control of code… vulnerability
  • CVE-2026-110186 IBM Langflow OSS 1.0.0 through 1.12.8 could allow a remote attacker to execute arbitrary code due to improper control of code generation. vulnerability
  • CVE-2026-110193 IBM Langflow OSS 1.0.0 through 1.12.8 could allow a remote attacker with a low-privileged authenticated account to cause the Agentic… vulnerability
  • CVE-2026-110309 IBM Langflow OSS 1.0.0 through 1.12.4 could allow a remote authenticated attacker to execute arbitrary commands due to improper control of… vulnerability
  • CVE-2026-115301 The Contact Form by Supsystic WordPress plugin before 1.11.1 does not sandbox the template engine used to render its forms and allows… vulnerability
  • CVE-2026-118585 A vulnerability was identified in configuroweb inventariobasico… vulnerability
  • CVE-2026-118905 Node Version Manager (nvm) is a POSIX-compliant shell function for managing multiple node.js versions. vulnerability
  • CVE-2026-119027 oapi-codegen 2.5.0 before 2.8.1 contains a code injection vulnerability that allows attackers to inject Go code by supplying a crafted… vulnerability
  • CVE-2026-119028 oapi-codegen 2.0.0 before 2.8.1 contains a code injection vulnerability that allows attackers to inject Go code by supplying non-literal… vulnerability
  • CVE-2026-18894 IBM Langflow OSS 1.0.0 through 1.12.4 could allow a remote attacker to trigger pre-existing stored Python component code in a public… vulnerability
  • CVE-2026-61991 Unauthenticated Remote Code Execution (RCE) in AjaxLoadMore Cache <= 3.1.1 versions. vulnerability
  • CVE-2026-90872 Improper neutralization of directives in dynamically evaluated code in the Manager web console of Progress Software WS_FTP Server versions… vulnerability
  • CVE-2026-104383 Improper Control of Generation of Code in Pigeon MFA service in EagleCloud Aquila versions through 2.6.7.2 on on-premises platforms allows… vulnerability
  • CVE-2026-118614 Ultralytics check_det_dataset Code Injection Remote Code Execution Vulnerability. vulnerability
  • CVE-2026-118616 Ultralytics parse_model Code Injection Remote Code Execution Vulnerability. vulnerability
  • CVE-2026-118618 Ultralytics parse_model Code Injection Remote Code Execution Vulnerability. vulnerability
  • CVE-2026-118683 MONAI from 1.2.0 before 1.6.1 contains a remote code execution vulnerability in ConfigWorkflow.__init__, which passes a bundle's… vulnerability
  • CVE-2026-54453 OpenCATS is an open-source applicant tracking system and recruitment CRM for staffing agencies and hiring teams. vulnerability
  • CVE-2026-61564 AVideo is a video-sharing Platform. vulnerability
  • CVE-2026-67074 HCL BigFix AEX is affected by a Remote Code Execution Vulnerability . vulnerability
  • CVE-2026-81472 Dell iDRAC Service Module (iSM) for Windows, Dell iDRAC Service Module (iSM) for Linux, and Dell iDRAC Service Module (iSM) for ESXi,… vulnerability
  • CVE-2026-104351 Adobe Campaign Classic (ACC) is affected by an Improper Control of Generation of Code ('Code Injection') vulnerability that could result in… vulnerability
  • CVE-2026-116639 A vulnerability was detected in MD-MAFUJUL-HASAN Online-Payroll-Management-System up to a8902bf64575e325f6d6bf93a55f7bd273ec58cd. vulnerability
  • CVE-2026-116640 A flaw has been found in Saruf-Ratul HR-Payroll-Management-System… vulnerability
  • CVE-2026-116692 MLflow is an open source AI engineering platform for agents, large language models, and machine learning models. vulnerability
  • CVE-2026-116811 OpenPanel before 3.0.0 contains a sandbox escape vulnerability in the js-runtime validator that allows a project member to bypass the AST… vulnerability
Show all 7,573 ›

Referenced by CWE · can precede (1)

  • CWE-98 Improper Control of Filename for Include/Require Statement in PHP Program weakness

Referenced by CWE · child of (3)

  • CWE-1336 Improper Neutralization of Special Elements Used in a Template Engine weakness
  • CWE-95 Improper Neutralization of Directives in Dynamically Evaluated Code weakness
  • CWE-96 Improper Neutralization of Directives in Statically Saved Code weakness

Referenced by CWE · has member (8)

  • CWE-1200 Weaknesses in the 2019 CWE Top 25 Most Dangerous Software Errors view
  • CWE-1350 Weaknesses in the 2020 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1387 Weaknesses in the 2022 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1425 Weaknesses in the 2023 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1430 Weaknesses in the 2024 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-1435 Weaknesses in the 2025 CWE Top 25 Most Dangerous Software Weaknesses view
  • CWE-635 Weaknesses Originally Used by NVD from 2008 to 2016 view
  • CWE-884 CWE Cross-section view

Referenced by OWASP · mapped cwe (3)