1. Home
  2. Web App Vulnerabilities
  3. How to remediate – Insecure Cross-Origin Resource Sharing Configuration

How to remediate – Insecure Cross-Origin Resource Sharing Configuration

1. Introduction

Insecure Cross-Origin Resource Sharing Configuration allows websites to make requests on behalf of a user to your application, potentially reading sensitive information or performing actions they shouldn’t be able to. This matters because it can lead to data breaches and unauthorized access. Systems using web browsers with CORS enabled are usually affected. Impact is likely to affect confidentiality, integrity, and availability.

2. Technical Explanation

Cross Origin Resource Sharing (CORS) allows websites from different domains to interact with each other. The Same Origin Policy normally prevents this for security reasons. An insecure configuration permits any website to make requests to your application using the user’s credentials, potentially exposing sensitive data. Attackers can exploit this by crafting malicious web pages that trigger these unauthorized requests.

  • Root cause: Incorrectly configured CORS policy allowing all origins instead of specific trusted domains.
  • Exploit mechanism: An attacker hosts a malicious website and tricks the user into visiting it. The website then sends requests to your application, bypassing the Same Origin Policy due to the open CORS configuration.
  • Scope: Web applications using HTML5 browsers with CORS enabled are affected.

3. Detection and Assessment

You can confirm if a system is vulnerable by checking its CORS headers or scanning for misconfigurations.

  • Quick checks: Use your browser’s developer tools to inspect the response headers when making requests to your application. Look for an Access-Control-Allow-Origin header with a value of *.
  • Scanning: Burp Suite or OWASP ZAP can identify open CORS configurations. These are examples only, and may require configuration updates.
  • Logs and evidence: Examine web server logs for requests originating from unexpected domains.
curl -I https://your-application-url

4. Solution / Remediation Steps

Configure your application to only allow specific, trusted domains to perform CORS requests.

4.1 Preparation

  • Identify the trusted domains that need access to your application’s resources. A roll back plan is to restore from the previous backup.
  • Consider a change window and approval process if this impacts production systems.

4.2 Implementation

  1. Step 1: Edit your web server configuration file (e.g., Apache’s httpd.conf or Nginx’s nginx.conf).
  2. Step 2: Add a CORS policy that only allows requests from trusted domains. For example, in Apache: Header set Access-Control-Allow-Origin "https://trusted-domain.com". Repeat for each trusted domain.
  3. Step 3: Restart your web server to apply the changes.

4.3 Config or Code Example

Before

Header set Access-Control-Allow-Origin "*"

After

Header set Access-Control-Allow-Origin "https://trusted-domain.com"

4.4 Security Practices Relevant to This Vulnerability

  • Least privilege: Restrict access only to trusted domains, minimizing the potential impact of a compromised domain.
  • Secure configuration: Regularly review and update your web server configuration to ensure it follows security best practices.

5. Verification / Validation

Confirm the fix by checking that requests from untrusted domains are blocked and requests from trusted domains are allowed.

  • Post-fix check: Use your browser’s developer tools to inspect the response headers when making a request from an untrusted domain. The Access-Control-Allow-Origin header should not be present, or it should not match the requesting origin.
  • Re-test: Repeat the quick checks from Section 3 and verify that the open CORS configuration is no longer present.
  • Smoke test: Ensure all legitimate users can still access the application’s resources as expected.
curl -I https://your-application-url

6. Preventive Measures and Monitoring

  • Baselines: Implement a security baseline that enforces strict CORS policies.
  • Pipelines: Use SAST tools to scan your code for insecure CORS configurations during development.

7. Risks, Side Effects, and Roll Back

  • Roll back: Restore your web server configuration from the backup taken in Section 4.1.

8. References and Resources

Updated on December 27, 2025

Was this article helpful?

Related Articles