Insecure Cross-Origin Resource Sharing (CORS) Policy

The application's CORS policy lets untrusted origins read its responses with the user's credentials, so a malicious site can read a logged-in user's data.

SeverityMedium
CVSS 3.15.3 CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:N/A:N Open in the calculator
CVSS 4.06 CVSS:4.0/AV:N/AC:L/AT:P/PR:N/UI:P/VC:H/VI:N/VA:N/SC:N/SI:N/SA:N Open in the calculator
CWECWE-942: Permissive Cross-domain Policy with Untrusted Domains
OWASP Top 10A02:2025 Security Misconfiguration
CategorySecurity Misconfiguration

Description

Cross-Origin Resource Sharing (CORS) lets a server relax the browser's same-origin policy for chosen origins through response headers. The application's policy trusts origins it should not: it reflects any value of the request's Origin header in Access-Control-Allow-Origin, accepts the null origin, or validates origins with a pattern that matches unintended domains, such as a check that the origin merely ends with or contains the organisation's domain, or a regular expression with an unescaped dot. Where it also returns Access-Control-Allow-Credentials: true, script on a trusted origin can make requests that carry the user's cookies and read the responses.

When a logged-in user visits a page controlled by the attacker, the page can then read any response that the affected endpoints return to that user, such as personal data, account details, API keys and anti-CSRF tokens, and can use those tokens to perform further actions in the user's name. Exploitation needs the browser to send the session cookie with the cross-site request, which current defaults restrict unless the cookie is set with SameSite=None or the attacker controls a page on a trusted or same-site origin. Where only a trusted subdomain can exploit the policy, the attacker first needs a cross-site scripting flaw on, or takeover of, that subdomain.

The weakness typically shows itself on a test when a request with an arbitrary or crafted Origin header receives a response that echoes it with credentials allowed. Burp Suite reports trust of arbitrary origins, unencrypted origins and all subdomains as separate CORS issues. A wildcard on its own is not usually exploitable for authenticated data, because browsers refuse to combine it with credentials, but it matters where a response is protected only by network location.

Remediation

Grant cross-origin access only to origins that are trusted, and only where it is needed:

  • Compare the Origin header with an exact list of trusted origins, including scheme, host and port, and return it in Access-Control-Allow-Origin only on a match. Never reflect arbitrary values, trust null, or match origins by prefix, suffix or loose pattern.
  • Return Access-Control-Allow-Credentials: true only on endpoints that genuinely need credentialed cross-origin access, and only to trusted origins.
  • Do not trust http origins for an application served over HTTPS.
  • Add Vary: Origin to responses whose CORS headers depend on the request's origin, so that caches do not serve one origin's response to another.
  • Apply CORS headers only to the routes that need them rather than to the whole application, and set SameSite=Lax or Strict on session cookies.

Confirm the fix by sending requests with arbitrary, null, look-alike and subdomain origins and checking that none is reflected with credentials allowed.

References


Add This Finding to Your Library

In Pental this write-up is in Settings, Library. Add to my library copies it into your own, rated in your firm's CVSS version, ready to put in your own words.

Free trial  ·  No card required

Only need the reporting? Our reporting tool is free and open source, with the same library.


More Web Applications Findings

Every Web Applications finding