# Unsanitized user input in code generation

## Overview

* **Rule ID**: `java_lang_code_injection`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-94

## Description

Allowing user input to directly influence code generation or scripting functions without proper sanitization can result in code injection vulnerabilities. This occurs when attackers inject malicious code into your application, enabling unauthorized actions or unauthorized access to data when executed.

## Remediation Guidelines

* **Avoid** passing unsanitized user input to functions or methods that dynamically execute code.
* **Always** validate or sanitize input to prevent the inclusion of harmful code before utilizing it in such contexts.

## References

* [**OWASP Code injection**](https://owasp.org/www-community/attacks/Code_Injection)
* [**CWE-94: Improper Control of Generation of Code ('Code Injection')**](https://cwe.mitre.org/data/definitions/94.html)
* [**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/unsanitized-user-input-in-code-generation.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.
