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

BaseDraft

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.

View on MITRE
Back to CWE Lookup

Extended Description

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.

Technical Details

Structure
Simple

Applicable To

Languages
JavaPHPInterpreted
Platforms

Frequently Asked Questions

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

CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection') is a Common Weakness Enumeration (CWE) entry maintained by MITRE. 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.

What are the security consequences of Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')?+

If exploited, CWE-470 (Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')) it can compromise Integrity, Confidentiality, Availability and Other, leading to outcomes such as Execute Unauthorized Code or Commands, Alter Execution Logic, DoS: Crash, Exit, or Restart, Other and Read Application Data.

How do you prevent or mitigate Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')?+

Recommended mitigations for CWE-470 include: Refactor your code to avoid using reflection. Do not use user-controlled inputs to select and load classes or code. Apply strict input validation by using allowlists or indirect selection to ensure that the user is only selecting allowable classes or code.

Which programming languages are affected by Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')?+

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

What are real-world examples of Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')?+

MITRE documents real CVEs mapped to CWE-470, including CVE-2018-1000613 and CVE-2004-2331. 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-470 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