> For the complete documentation index, see [llms.txt](https://docs.sec1.io/user-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sec1.io/user-docs/4-sast/2-java/permissive-access-control-allow-origin-configuration.md).

# Permissive Access-Control-Allow-Origin configuration

## Overview

* **Rule ID**: `java_lang_permissive_allow_origin`
* **Applicable Languages**: Java
* **Weakness ID**: CWE-942

## Description

A liberal Access-Control-Allow-Origin configuration can pose security risks to your application. Setting this header to "\*" allows any website to access your application's responses, potentially resulting in unauthorized access to sensitive information.

## Remediation Guidelines

* **Avoid** setting the Access-Control-Allow-Origin header to "\*". This excessively permissive configuration can expose your application to potential attacks.

  ```java
  response.addHeader("access-control-allow-origin", "*"); // unsafe

  ```
* **Limit the Access-Control-Allow-Origin header** to permit only specific, trusted origins that require access to your application. This approach reduces the likelihood of exposing sensitive data.

  ```java
  response.addHeader("access-control-allow-origin", "myapp.example.com");
    
  ```

## 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-942: Permissive Cross-domain Policy with Untrusted Domains**](https://cwe.mitre.org/data/definitions/942.html)
* [**OWASP Top 10: A05:2021 - Security Misconfiguration**](https://owasp.org/Top10/A05_2021-Security_Misconfiguration/)

## 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
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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