# Usage of External Input in Code Reflection

## Overview

* **Rule ID**: `java_lang_reflection_using_user_input`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-470

## Description

Using external input for dynamic class loading or executing code via reflection presents a major security risk. Attackers can exploit this practice to load malicious classes or execute harmful methods, leading to potential remote code execution and other serious security threats.

## Remediation Guidelines

* **Avoid** using external input with code reflection whenever possible. Steering clear of this practice greatly reduces the risk of executing unauthorized or malicious code.
* **Limit** the allowed class names and method names to a predefined safelist. This strategy restricts the range of classes and methods that can be dynamically accessed, minimizing the risk of unauthorized actions.
* **Sanitize** external input by removing special and unexpected characters that could enable code injection attacks. Characters like single or double quotation marks and backslashes are particularly dangerous and should be filtered out.

## References

* [**CWE-470: Use of Externally-Controlled Input to Select Classes or Code ('Unsafe Reflection')**](https://cwe.mitre.org/data/definitions/470.html)
* [**OWASP Top 10: A03:2021 - Injection**](https://owasp.org/Top10/A03_2021-Injection/)

## Configuration

To omit this rule during a scan, and to provide you with continuous 24/7 code-level scanning, you can employ our [**SAST TOOL**](https://scopy.sec1.io/login)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sec1.io/user-docs/4-sast/2-java/usage-of-external-input-in-code-reflection.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
