The product does not properly restrict reading from or writing to dynamically-managed code resources such as variables, objects, classes, attributes, functions, or executable instructions or statements.
Many languages offer powerful features that allow the programmer to dynamically create or modify existing code, or resources used by code such as variables and objects. While these features can offer significant flexibility and reduce development time, they can be extremely dangerous if attackers can directly influence these code resources in unexpected ways.

Primary

Architecture and Design

Implementation

Integrity
Execute Unauthorized Code or Commands

Other
Integrity
Varies by Context
Alter Execution Logic

Fuzzing
Fuzz testing (fuzzing) is a powerful technique for generating large numbers of diverse inputs - either randomly or algorithmically - and dynamically invoking the code with those inputs. Even with random inputs, it is often capable of generating unexpected results such as crashes, memory corruption, or resource consumption. Fuzzing effectively produces repeatable test cases that clearly indicate bugs, which helps developers to diagnose the issues.
High

Implementation
Input Validation
For any externally-influenced input, check the input against an allowlist of acceptable values.

Implementation
Architecture and Design
Refactoring
Refactor the code so that it does not need to be dynamically managed.

This example attempts to write user messages to a message file and allow users to view them.

$MessageFile = "messages.out";if ($_GET["action"] == "NewMessage") {$name = $_GET["name"];$message = $_GET["message"];$handle = fopen($MessageFile, "a+");fwrite($handle, "<b>$name</b> says '$message'<hr>\n");fclose($handle);echo "Message Saved!<p>\n";}else if ($_GET["action"] == "ViewMessages") {include($MessageFile);}

While the programmer intends for the MessageFile to only include data, an attacker can provide a message such as:

name=h4x0rmessage=%3C?php%20system(%22/bin/ls%20-l%22);?%3E

which will decode to the following:

<?php system("/bin/ls -l");?>

The programmer thought they were just including the contents of a regular data file, but PHP parsed it and executed the code. Now, this code is executed any time people view messages.
Notice that XSS (CWE-79) is also possible in this situation.

A common reason that programmers use the
reflection API is to implement their own command
dispatcher. The following example shows a command
dispatcher that does not use reflection:

String ctl = request.getParameter("ctl");
Worker ao = null;
if (ctl.equals("Add")) {

ao = new AddCommand();

}
else if (ctl.equals("Modify")) {

ao = new ModifyCommand();

}
else {

throw new UnknownActionError();
}

ao.doAction(request);

A programmer might refactor this code to use reflection as follows:

String ctl = request.getParameter("ctl");
Class cmdClass = Class.forName(ctl + "Command");
Worker ao = (Worker) cmdClass.newInstance();
ao.doAction(request);

The refactoring initially appears to offer a
number of advantages. There are fewer lines of code,
the if/else blocks have been entirely eliminated, and
it is now possible to add new command types without
modifying the command dispatcher.
However, the refactoring allows an attacker to
instantiate any object that implements the Worker
interface. If the command dispatcher is still
responsible for access control, then whenever
programmers create a new class that implements the
Worker interface, they must remember to modify the
dispatcher's access control code. If they do not modify
the access control code, then some Worker classes will
not have any access control.

One way to address this access control
problem is to make the Worker object responsible for
performing the access control check. An example of the
re-refactored code follows:

String ctl = request.getParameter("ctl");
Class cmdClass = Class.forName(ctl + "Command");
Worker ao = (Worker) cmdClass.newInstance();
ao.checkAccessControl(request);
ao.doAction(request);

Although this is an improvement, it
encourages a decentralized approach to access control,
which makes it easier for programmers to make access
control mistakes.
This code also highlights another security
problem with using reflection to build a command
dispatcher. An attacker can invoke the default
constructor for any kind of object. In fact, the
attacker is not even constrained to objects that
implement the Worker interface; the default constructor
for any object in the system can be invoked. If the
object does not implement the Worker interface, a
ClassCastException will be thrown before the assignment
to ao, but if the constructor performs operations that
work in the attacker's favor, the damage will already
have been done. Although this scenario is relatively
benign in simple products, in larger products where
complexity grows exponentially, it is not unreasonable
that an attacker could find a constructor to leverage
as part of an attack.

CVE-2022-2054
Python compiler uses eval() to execute malicious strings as Python code.
https://www.cve.org/CVERecord?id=CVE-2022-2054

CVE-2018-1000613
Cryptography API uses unsafe reflection when deserializing a private key
https://www.cve.org/CVERecord?id=CVE-2018-1000613

CVE-2015-8103
Deserialization issue in commonly-used Java library allows remote execution.
https://www.cve.org/CVERecord?id=CVE-2015-8103

CVE-2006-7079
Chain: extract used for register_globals compatibility layer, enables path traversal (CWE-22)
https://www.cve.org/CVERecord?id=CVE-2006-7079

CVE-2012-2055
Source version control product allows modification of trusted key using mass assignment.
https://www.cve.org/CVERecord?id=CVE-2012-2055

Allowed-with-Review
This CWE entry is a Class and might have Base-level children that would be more appropriate
Examine children of this entry to see if there is a better fit

CWE Content Team
MITRE
2013-01-26
2.4
2013-02-21

CWE Content Team
MITRE
2015-12-07
updated Relationships

CWE Content Team
MITRE
2017-01-19
updated Relationships

CWE Content Team
MITRE
2017-11-08
updated Relationships

CWE Content Team
MITRE
2019-06-20
updated Relationships

CWE Content Team
MITRE
2020-02-24
updated Relationships

CWE Content Team
MITRE
2020-06-25
updated Potential_Mitigations

CWE Content Team
MITRE
2021-10-28
updated Relationships

CWE Content Team
MITRE
2023-01-31
updated Description

CWE Content Team
MITRE
2023-04-27
updated Detection_Factors, Relationships

CWE Content Team
MITRE
2023-06-29
updated Mapping_Notes

CWE Content Team
MITRE
2023-10-26
updated Observed_Examples

CWE Content Team
MITRE
2025-12-11
4.19
2025-12-11
updated Applicable_Platforms, Demonstrative_Examples, Weakness_Ordinalities