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

## Overview

* **Rule ID**: `javascript_express_insecure_allow_origin`
* **Applicable Languages**: Javascript
* **Weakness ID**: CWE-346

## Description

Using unverified user-defined input to set the Access-Control-Allow-Origin header can result in unauthorized access to sensitive data. This vulnerability exposes your application to potential security risks by allowing attackers to specify origins that can access resources.

## Remediation Guidelines

* **Do not** define the `Access-Control-Allow-Origin` header with user input. This practice can compromise the security of your application by allowing data access to unintended users.
* **Do** verify user input if it is absolutely necessary to use it for defining origins. Ensure that the verification process is robust to prevent security breaches.
* **Do** use a safelist approach when specifying origins. This uses a predefined list of trusted origins and only allows requests from those origins.

## 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/3-javascript/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.
