CWE-94: Improper Control of Generation of Code ('Code Injection')

BaseDraftExploit Likelihood: Medium🏆 #18 in Top 25 (2024)

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.

View on MITRE
436Related CVEs
11.72Severity Score
Back to CWE Lookup

Technical Details

Structure
Simple

Applicable To

Languages
Interpreted
Platforms

🏆 CWE Top 25 Historical Ranking

2023:#23
Score: 3.30
401 CVEs
2024:#18↑5
Score: 11.72
436 CVEs
Trend:Worsening (moved down 5 ranks)

Source-backed guidance

Additional facts reviewed against primary or authoritative security sources.

Combine review and analysis around the CWE-94 trust boundary

MITRE identifies automated static analysis as applicable detection approaches. Use them to trace externally influenced values into eval-style functions, dynamic templates, expression languages, plugin loaders, and generated source before compilation or execution. Require a reproducible source-to-sink or policy-to-enforcement trace, record coverage gaps, and confirm suspected findings dynamically where safe; no single scanner can establish complete coverage for this weakness.

CWE-94: detection methods and operational guidanceMITRE CWE

Keep untrusted data out of executable language contexts

Avoid eval-style functions and dynamic generation of source, expressions, or templates from untrusted values. Prefer APIs that keep instructions separate from data; when dynamic selection is unavoidable, map input to a small allowlist of server-defined operations or tokens. Run the resulting component with minimum privileges and use isolation only as defense in depth, not as a substitute for removing the injection path.

Injection Prevention Cheat SheetOWASP Foundation

Apply lessons from CVE-2025-32432 in Craft CMS

NVD maps CVE-2025-32432 to CWE-94; a remotely reachable code-injection weakness allowed an attacker to execute arbitrary code. Use the case to audit framework object creation and configuration paths, constrain dynamic behavior before authentication, and regression-test known gadget and expression inputs at the application boundary.

CVE-2025-32432 DetailNIST National Vulnerability Database

Prioritize CWE-94 using its 2025 CWE Top 25 evidence

CWE-94 ranked #10 in the 2025 CWE Top 25 with a score of 7.57. The ranking table recorded 7 mapped vulnerabilities in CISA KEV for this measurement window. Use the rank to prioritize systemic prevention, detection coverage, and recurring-root-cause metrics across the portfolio, while retaining asset exposure and business impact for individual finding severity decisions.

2025 CWE Top 25 Most Dangerous Software WeaknessesMITRE CWE

Probe every dynamic code-generation boundary

Inventory eval-style APIs, expression engines, dynamic templates, plugin loaders, and generated source. Insert harmless language-specific expressions and syntax breakers to determine whether data becomes executable structure, then test encoded and second-order variants. Confirm remediation replaces dynamic evaluation with fixed operations or an explicit allowlist and that isolation is retained only as defense in depth.

Testing for Code InjectionOWASP Foundation

Frequently Asked Questions

What is CWE-94: Improper Control of Generation of Code ('Code Injection')?+

CWE-94: Improper Control of Generation of Code ('Code Injection') is a Common Weakness Enumeration (CWE) entry maintained by MITRE. 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.

Is CWE-94 in the CWE Top 25 Most Dangerous Software Weaknesses?+

Yes. CWE-94 ranked #18 in the CWE Top 25 for 2024, associated with 436 CVEs that year. The CWE Top 25 highlights the most common and impactful software weaknesses based on real-world vulnerability data.

What are the security consequences of Improper Control of Generation of Code ('Code Injection')?+

If exploited, CWE-94 (Improper Control of Generation of Code ('Code Injection')) it can compromise Access Control, Integrity, Confidentiality, Availability and Non-Repudiation, leading to outcomes such as Bypass Protection Mechanism, Gain Privileges or Assume Identity, Execute Unauthorized Code or Commands and Hide Activities.

How do you prevent or mitigate Improper Control of Generation of Code ('Code Injection')?+

Recommended mitigations for CWE-94 include: 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. 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.

Which programming languages are affected by Improper Control of Generation of Code ('Code Injection')?+

CWE-94 commonly affects Interpreted. Note that weaknesses are often language-agnostic patterns, so secure coding practices apply broadly.

What are real-world examples of Improper Control of Generation of Code ('Code Injection')?+

MITRE documents real CVEs mapped to CWE-94, including CVE-2023-29374, CVE-2024-5565, CVE-2024-4181, CVE-2022-2054 and CVE-2021-22204. You can look up the full details of each CVE, including CVSS scores and remediation guidance, on our CVE Lookup tool.

What is the difference between a CWE and a CVE?+

A CWE (Common Weakness Enumeration) like CWE-94 describes a category of software weakness — the underlying flaw type. A CVE (Common Vulnerabilities and Exposures) identifies a specific, real-world vulnerability in a particular product. In short, a CWE is the kind of mistake, and a CVE is an instance of that mistake being found in software.

Learn More

Advertisement