# Unsanitized user input in Access-Control-Allow-Origin

## Overview

* **Rule ID**: `java_lang_insecure_allow_origin`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-346

## Description

Setting the Access-Control-Allow-Origin header with unverified user-defined input can lead to unauthorized access to sensitive data. This vulnerability exposes your application to security risks, as attackers can specify origins that gain access to resources.

## Remediation Guidelines

* **Avoid** using user input to specify the `Access-Control-Allow-Origin` header without proper validation. This practice can unintentionally provide access to sensitive information.
* If it's essential to use user input for defining origins, **ensure thorough validation** to confirm the input comes from a trusted source.
* **Implement a safelist approach** when specifying origins. Limit access to your resources to only known and trusted domains.

## References

* [**OWASP Origin & Access-Control-Allow-Origin**](https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/11-Client-side_Testing/07-Testing_Cross_Origin_Resource_Sharing)
* [**CWE-346: Origin Validation Error**](https://cwe.mitre.org/data/definitions/346.html)
* [**OWASP Top 10: A07:2021 - Identification and Authentication Failures**](https://owasp.org/Top10/A07_2021-Identification_and_Authentication_Failures/)

## 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-access-control-allow-origin.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.
