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

What is CWE-470?

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.

Analyzing data...

Data statistics

OWASP TOP 10:2025 RANK5 — A05:2025 — Injection
RELATED CVES (365 DAYS)49
ABSTRACTIONBase

Vulnerabilities mapped to CWE-470

49 vulnerabilities880% increase year over year

Vulnerabilities in CISA KEV for CWE-470

1 vulnerabilities

Official definition

ByMitre CWE

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.

Characteristics

Alternate terms

  • Reflection Injection

Modes of introduction

  • Architecture and Design
  • Implementation

Common consequences

ImpactScopeExplanation
Execute Unauthorized Code or Commands, Alter Execution LogicIntegrity, Confidentiality, Availability, OtherThe 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.
DoS: Crash, Exit, or Restart, OtherAvailability, OtherThe 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.
Read Application DataConfidentialityBy 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.

Risk mitigations

  1. Architecture and DesignRefactor your code to avoid using reflection.
  2. Architecture and DesignDo not use user-controlled inputs to select and load classes or code.
  3. ImplementationApply strict input validation by using allowlists or indirect selection to ensure that the user is only selecting allowable classes or code.

Detection methods

MethodApproachEffectiveness
Automated Static AnalysisAutomated 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

Representative vulnerabilities

Sources (3)

CWE™ Program, operated by The MITRE Corporation. Copyright © 2006–2026, The MITRE Corporation. The MITRE Corporation hereby grants you a non-exclusive, royalty-free license to use CWE for research, development, and commercial purposes. CWE Terms of Use.

Learn more

Run an in-depth assessment with complete web risk management

CyStack VulnScan continuously discovers assets, validates vulnerabilities, and helps security teams prioritize remediation across the organization.

Explore CyStack VulnScan