The product uses external input with reflection to select which classes or code to use, but it does not sufficiently prevent the input from selecting improper classes or code.
If the product uses external inputs to determine which class to instantiate or which method to invoke, then an attacker could supply values to select unexpected classes or methods. If this occurs, then the attacker could create control flow paths that were not intended by the developer. These paths could bypass authentication or access control checks, or otherwise cause the product to behave in an unexpected manner. This situation becomes a doomsday scenario if the attacker can upload files into a location that appears on the product's classpath (CWE-427) or add new entries to the product's classpath (CWE-426). Under either of these conditions, the attacker can use reflection to introduce new, malicious behavior into the product.

Primary

Reflection Injection

Architecture and Design

Implementation

Integrity
Confidentiality
Availability
Other
Execute Unauthorized Code or Commands
Alter Execution Logic
The attacker might be able to execute code that is not directly accessible to the attacker. Alternately, the attacker could call unexpected code in the wrong place or the wrong time, possibly modifying critical system state.

Availability
Other
DoS: Crash, Exit, or Restart
Other
The attacker might be able to use reflection to call the wrong code, possibly with unexpected arguments that violate the API (CWE-227). This could cause the product to exit or hang.

Confidentiality
Read Application Data
By causing the wrong code to be invoked, the attacker might be able to trigger a runtime error that leaks sensitive information in the error message, such as CWE-536.

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

Architecture and Design
Refactor your code to avoid using reflection.

Architecture and Design
Do not use user-controlled inputs to select and load classes or code.

Implementation
Apply strict input validation by using allowlists or indirect selection to ensure that the user is only selecting allowable classes or code.

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-2018-1000613
Cryptography API uses unsafe reflection when deserializing a private key
https://www.cve.org/CVERecord?id=CVE-2018-1000613

CVE-2004-2331
Database system allows attackers to bypass sandbox restrictions by using the Reflection API.
https://www.cve.org/CVERecord?id=CVE-2004-2331

Unsafe Reflection

SEC06-J
Do not use reflection to increase accessibility of classes, methods, or fields

Allowed
This CWE entry is at the Base level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.

7 Pernicious Kingdoms
2006-07-19
Draft 3
2006-07-19

Eric Dalci
Cigital
2008-07-01
updated Potential_Mitigations, Time_of_Introduction

KDM Analytics
2008-08-01
added/updated white box definitions

CWE Content Team
MITRE
2008-09-08
updated Description, Relationships, Other_Notes, Taxonomy_Mappings

CWE Content Team
MITRE
2008-10-14
updated Applicable_Platforms, Demonstrative_Examples, Description, Other_Notes

CWE Content Team
MITRE
2009-01-12
updated Applicable_Platforms, Common_Consequences, Demonstrative_Examples, Observed_Examples, Potential_Mitigations

CWE Content Team
MITRE
2009-05-27
updated Demonstrative_Examples, Name

CWE Content Team
MITRE
2009-10-29
updated Alternate_Terms, Relationships

CWE Content Team
MITRE
2011-03-29
updated Demonstrative_Examples

CWE Content Team
MITRE
2011-06-01
updated Common_Consequences, Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2012-05-11
updated Relationships, Taxonomy_Mappings

CWE Content Team
MITRE
2013-02-21
updated Relationships

CWE Content Team
MITRE
2014-07-30
updated Relationships

CWE Content Team
MITRE
2017-11-08
updated White_Box_Definitions

CWE Content Team
MITRE
2019-01-03
updated Taxonomy_Mappings

CWE Content Team
MITRE
2019-06-20
updated Relationships

CWE Content Team
MITRE
2020-02-24
updated References, 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 Common_Consequences, Demonstrative_Examples, Description, Related_Attack_Patterns, Relationships

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 Demonstrative_Examples, Relationships, Weakness_Ordinalities

Unsafe Reflection
Use of Externally-Controlled Input to Select Classes or Code (aka 'Unsafe Reflection')