Weakness · Critical
CWE-94: Improper Control of Generation of Code ('Code Injection')
What it is
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.
- Severity (our rating)
- Critical
- Likelihood of exploit
- Medium
- Introduced during
- Implementation
- Exploited in the wild
- 71 known exploited CVEs
What an attacker can do
- Bypass Protection Mechanism (Access Control)
- Gain Privileges or Assume Identity (Access Control)
- Execute Unauthorized Code or Commands (Integrity, Confidentiality, Availability)
- Hide Activities (Non-Repudiation)
How to prevent it
Architecture and Design
- Refactor your program so that you do not have to dynamically generate code.
- 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().
- 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, so the python documentation discourages use of ast.literal_eval() on untrusted data.
Testing
- Use automated static analysis tools that target this type of weakness. Many modern techniques use data flow analysis to minimize the number of false positives. This is not a perfect solution, since 100% accuracy and coverage are not feasible.
- 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).
- 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).
While the code is being fixed, a WAF in blocking mode stops PHP and Node.js code injection payloads at the edge.
How to find it
- 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.)
Exploited in the wild: 71 CVEs
Vulnerabilities caused by CWE-94 that attackers have used, from CISA's Known Exploited Vulnerabilities catalog, newest first.
- CVE-2026-65660Microsoft SharePoint Code Injection Vulnerability · added September 25, 2026
- CVE-2026-60004Gitea Code Injection Vulnerability · added August 25, 2026
- CVE-2026-72530TrueConf Server Code Injection Vulnerability · added August 20, 2026
- CVE-2025-62593Ray-Project Ray Code Injection Vulnerability · added August 17, 2026
- CVE-2026-9198IBM Langflow Code Injection Vulnerability · added August 4, 2026
- CVE-2026-15410 ransomwareSonicWall SMA1000 Appliances Code Injection Vulnerability · added July 14, 2026
- CVE-2025-67038Lantronix EDS5000 Code Injection Vulnerability · added June 23, 2026
- CVE-2008-4250Microsoft Windows Buffer Overflow Vulnerability · added May 20, 2026
- CVE-2026-34197Apache ActiveMQ Improper Input Validation Vulnerability · added April 16, 2026
- CVE-2009-0238Microsoft Office Remote Code Execution · added April 14, 2026
- CVE-2026-1340Ivanti Endpoint Manager Mobile (EPMM) Code Injection Vulnerability · added April 8, 2026
- CVE-2026-33017Langflow Code Injection Vulnerability · added March 25, 2026
- CVE-2025-54068Laravel Livewire Code Injection Vulnerability · added March 20, 2026
- CVE-2025-32432Craft CMS Code Injection Vulnerability · added March 20, 2026
- CVE-2026-1281Ivanti Endpoint Manager Mobile (EPMM) Code Injection Vulnerability · added January 29, 2026
- CVE-2026-20045Cisco Unified Communications Products Code Injection Vulnerability · added January 21, 2026
- CVE-2025-37164Hewlett Packard Enterprise (HPE) OneView Code Injection Vulnerability · added January 7, 2026
- CVE-2009-0556Microsoft Office PowerPoint Code Injection Vulnerability · added January 7, 2026
- CVE-2025-6204Dassault Systèmes DELMIA Apriso Code Injection Vulnerability · added October 28, 2025
- CVE-2025-49704 ransomwareMicrosoft SharePoint Code Injection Vulnerability · added July 22, 2025
- CVE-2024-56145Craft CMS Code Injection Vulnerability · added June 2, 2025
- CVE-2025-4428Ivanti Endpoint Manager Mobile (EPMM) Code Injection Vulnerability · added May 19, 2025
- CVE-2025-1976Broadcom Brocade Fabric OS Code Injection Vulnerability · added April 28, 2025
- CVE-2025-23209Craft CMS Code Injection Vulnerability · added February 20, 2025
- CVE-2022-24816OSGeo GeoServer JAI-EXT Code Injection Vulnerability · added June 26, 2024
- CVE-2024-20359Cisco ASA and FTD Privilege Escalation Vulnerability · added April 24, 2024
- CVE-2023-24955 ransomwareMicrosoft SharePoint Server Code Injection Vulnerability · added March 26, 2024
- CVE-2021-44529 ransomwareIvanti Endpoint Manager Cloud Service Appliance (EPM CSA) Code Injection Vulnerability · added March 25, 2024
- CVE-2024-21351Microsoft Windows SmartScreen Security Feature Bypass Vulnerability · added February 13, 2024
- CVE-2023-6548Citrix NetScaler ADC and NetScaler Gateway Code Injection Vulnerability · added January 17, 2024
- CVE-2018-14667Red Hat JBoss RichFaces Framework Expression Language Injection Vulnerability · added September 28, 2023
- CVE-2023-33246Apache RocketMQ Command Execution Vulnerability · added September 6, 2023
- CVE-2023-3519 ransomwareCitrix NetScaler ADC and NetScaler Gateway Code Injection Vulnerability · added July 19, 2023
- CVE-2023-25717Multiple Ruckus Wireless Products CSRF and RCE Vulnerability · added May 12, 2023
- CVE-2023-29492Novi Survey Insecure Deserialization Vulnerability · added April 13, 2023
- CVE-2017-7494 ransomwareSamba Remote Code Execution Vulnerability · added March 30, 2023
- CVE-2013-3163Microsoft Internet Explorer Memory Corruption Vulnerability · added March 30, 2023
- CVE-2021-39144XStream Remote Code Execution Vulnerability · added March 10, 2023
- CVE-2022-41223 ransomwareMitel MiVoice Connect Code Injection Vulnerability · added February 21, 2023
- CVE-2022-3236Sophos Firewall Code Injection Vulnerability · added September 23, 2022
- CVE-2022-22963VMware Tanzu Spring Cloud Function Remote Code Execution Vulnerability · added August 25, 2022
- CVE-2009-1862Adobe Acrobat and Reader, Flash Player Unspecified Vulnerability · added June 8, 2022
- CVE-2009-0557Microsoft Office Object Record Corruption Vulnerability · added June 8, 2022
- CVE-2014-4148Microsoft Windows Remote Code Execution Vulnerability · added May 25, 2022
- CVE-2022-22947VMware Spring Cloud Gateway Code Injection Vulnerability · added May 16, 2022
- CVE-2022-22954 ransomwareVMware Workspace ONE Access and Identity Manager Server-Side Template Injection Vulnerability · added April 14, 2022
- CVE-2022-22965Spring Framework JDK 9+ Remote Code Execution Vulnerability · added April 4, 2022
- CVE-2018-1273 ransomwareVMware Tanzu Spring Data Commons Property Binder Vulnerability · added March 25, 2022
- CVE-2014-6287Rejetto HTTP File Server (HFS) Remote Code Execution Vulnerability · added March 25, 2022
- CVE-2013-4810HP Multiple Products Remote Code Execution Vulnerability · added March 25, 2022
- CVE-2009-1151phpMyAdmin Remote Code Execution Vulnerability · added March 25, 2022
- CVE-2020-8218Pulse Connect Secure Code Injection Vulnerability · added March 7, 2022
- CVE-2013-1347Microsoft Internet Explorer Remote Code Execution Vulnerability · added March 3, 2022
- CVE-2012-1856Microsoft Office MSCOMCTL.OCX Remote Code Execution Vulnerability · added March 3, 2022
- CVE-2010-0188 ransomwareAdobe Reader and Acrobat Arbitrary Code Execution Vulnerability · added March 3, 2022
- CVE-2009-3129Microsoft Excel Featheader Record Memory Corruption Vulnerability · added March 3, 2022
- CVE-2014-6352Microsoft Windows Code Injection Vulnerability · added February 25, 2022
- CVE-2017-9841PHPUnit Command Injection Vulnerability · added February 15, 2022
- CVE-2013-3906Microsoft Graphics Component Memory Corruption Vulnerability · added February 15, 2022
- CVE-2015-1635Microsoft HTTP.sys Remote Code Execution Vulnerability · added February 10, 2022
- CVE-2019-7609Kibana Arbitrary Code Execution · added January 10, 2022
- CVE-2015-7450IBM WebSphere Application Server and Server Hypervisor Edition Code Injection. · added January 10, 2022
- CVE-2019-0193Apache Solr DataImportHandler Code Injection Vulnerability · added December 10, 2021
- CVE-2021-22900Ivanti Pulse Connect Secure Unrestricted File Upload Vulnerability · added November 3, 2021
- CVE-2021-22894Ivanti Pulse Connect Secure Collaboration Suite Buffer Overflow Vulnerability · added November 3, 2021
- CVE-2020-8644PlaySMS Server-Side Template Injection Vulnerability · added November 3, 2021
- CVE-2020-8243Ivanti Pulse Connect Secure Code Execution Vulnerability · added November 3, 2021
- CVE-2019-16759vBulletin PHP Module Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2019-9082ThinkPHP Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2019-4716IBM Planning Analytics Remote Code Execution Vulnerability · added November 3, 2021
- CVE-2012-0158 ransomwareMicrosoft MSCOMCTL.OCX Remote Code Execution Vulnerability · added November 3, 2021
The Dome
Block it at the edge while you fix it
The Dome's WAF runs the OWASP Core Rule Set in blocking mode and stops PHP and Node.js code injection payloads before they reach your application.
See the DomeT Academy
Stop writing it in the first place
Learn to build software and systems without weaknesses like this one, with practice on real hosts in your browser, every objective checked on the machine.
Start freeSource: MITRE Common Weakness Enumeration, CWE version 4.19.1. CWE is a trademark of The MITRE Corporation.