← All tracks
Web InfrastructureCORS Misconfiguration10 labsIntermediate → Advanced6h practice

CORS Misconfiguration

A permission slip written by the requester.

“The API asked who was calling, then repeated the answer as permission.”

CWE-942OWASP Top 10 A05:2021OWASP ASVS 14.5.3
The mental model
CORS is a browser read gate, not authentication. Ask who is allowed to read the response and whether the server echoes that decision back to the caller.

The browser enforces the same-origin policy and asks the server whether another origin may read a response. If the server reflects any Origin and allows credentials, a malicious origin can read authenticated data even though it cannot steal the cookie.

The header looks like a server-side access control decision. It is actually a browser instruction that the server is allowed to grant too broadly.

Threat model

What is actually at stake?

Before touching a payload, map the assets, the actors and the boundary that is supposed to protect them. A finding only becomes a vulnerability when you can connect the failed boundary to a real asset.

Assets

  • Authenticated API data
  • Account and billing details
  • Support secrets and tokens
  • Administrative exports

Actors

  • Attacker hosting a malicious origin
  • Compromised third-party site
  • Subdomain takeover attacker
  • Malicious browser extension

Trust boundaries

  • Browser origin to API origin
  • Access-Control-Allow-Origin policy
  • Credentials flag to cookie sending
  • Cache key to reflected origin

Abuse cases

  • Reflect any Origin with credentials
  • Trust every subdomain
  • Allow null origin
  • Cache a response with a reflected origin
  • Read an internal API from an attacker page
PrerequisitesSame-origin policy and origin vs siteHTTP preflight requestsCookies and credentialed requests
Request anatomy

Follow the decision, not the payload

Every family has a moment where trusted data becomes an authorization, parsing or state decision. Learn to point at that moment in the request path.

  1. 01

    Request

    A page on origin A makes a fetch to origin B, optionally with credentials.

  2. 02

    Preflight

    For non-simple requests, the browser asks B which origins, methods and headers are allowed.

  3. 03

    Decision

    B returns Access-Control-Allow-Origin and Allow-Credentials. A wildcard cannot be combined with credentials.

  4. 04

    Read

    If the browser accepts the response, JavaScript on A can read the body; otherwise it can still send the request.

  5. 05

    Impact

    A reflected or over-broad allowlist lets an attacker read authenticated data without stealing the cookie.

Case study

The API that echoed every origin

Composite case study from public CORS disclosures
Context

A composite case based on common API reviews: a support dashboard API reflected the Origin header and enabled credentials for every route.

Discovery

A tester loaded a page on a second origin and fetched the account endpoint with credentials. The response included the reflected origin and the browser exposed the JSON body.

Impact

Any site could read the signed-in user's support profile and internal secret. The attacker never saw the cookie; the browser attached it.

Root cause

The CORS middleware copied the request Origin into the allow header and enabled credentials globally instead of using an exact allowlist.

Fix

Use an exact origin allowlist, avoid credentials where possible, return Vary: Origin, and test the browser read path rather than curl alone.

Read it as a chain: discovery → failed decision → impact → fix. Then ask which link would have broken earliest.

Attacker lens

A repeatable testing sequence

  1. Read the Access-Control-Allow-Origin and Allow-Credentials headers.
  2. Check whether the server reflects arbitrary origins or trusts a suffix.
  3. Test a credentialed request from a second origin.
  4. Verify the browser actually exposes the body, not just a preflight response.
  5. Show what sensitive data the attacker origin can read.

Where smart people get fooled

  • Wildcard origin with credentials is rejected by browsers; reflected origin with credentials often is not.
  • A blocked response in curl says nothing about browser enforcement.
  • CORS does not stop simple requests from being sent; it controls reading.
  • Trusting any subdomain can be enough if one subdomain is takeover-prone.
Detection engineering

What would the logs show?

A control is stronger when someone can see it fail. These signals are starting points for a detection rule, not a complete SIEM use case.

  • Access-Control-Allow-Origin equal to an unexpected request Origin
  • Access-Control-Allow-Credentials: true on broad routes
  • Origin values from non-production domains or null
  • Cached responses varying by Origin without Vary: Origin
  • Cross-origin requests to sensitive APIs from a small set of referrers
Starter query
index=web sourcetype=api_logs | eval reflected=if(acao=origin AND allow_credentials="true",1,0) | where reflected=1 AND origin!="https://academy.buggravity.com" | stats count values(path) by origin, user_id | where count > 0
The defender's move

Fix the decision, then prove it stays fixed

  • Use an exact allowlist of trusted origins, not suffix or regex matching.
  • Do not enable credentials unless the endpoint truly needs them.
  • Validate Origin on the server and return Vary: Origin for caches.
  • Keep sensitive APIs same-origin or require a separate, scoped token.
Vulnerable patterntypescript
res.setHeader("Access-Control-Allow-Origin", req.headers.origin);
res.setHeader("Access-Control-Allow-Credentials", "true");
Safer patterntypescript
const allowed = new Set(["https://app.example.com"]);
const origin = req.headers.origin;
if (origin && allowed.has(origin)) {
  res.setHeader("Access-Control-Allow-Origin", origin);
  res.setHeader("Access-Control-Allow-Credentials", "true");
  res.setHeader("Vary", "Origin");
}

Use exact string matching, not suffix or regex trust. Keep credentials off routes that do not need them and include Vary: Origin in cache keys.

Regression tests a reviewer would ask for

Foreign origin

GivenAn API allows only app.example.com

WhenOrigin: https://evil.example requests with credentials

ThenNo ACAO is returned and the browser cannot read the body

Exact allowlist

GivenA trusted origin is allowed

WhenThe request comes from app.example.com

ThenThe exact origin is returned with credentials and Vary: Origin

Subdomain

GivenThe allowlist uses a suffix match

WhenA takeover-prone subdomain requests the API

ThenThe server does not trust it automatically

Cache

GivenA CDN caches the API response

WhenTwo origins request the same path

ThenVary: Origin prevents one origin's headers from being served to the other

False positives

What this finding is not

Strong testers kill their own findings before someone else does. These are the shortcuts that turn a real bug into a weak report — or a false alarm into a wasted escalation.

  • The API returns ACAO: * but no credentials: an unauthenticated public endpoint may be intentionally readable.
  • A preflight is allowed but the actual request fails: check the exact methods and headers.
  • curl shows the body: curl ignores CORS; browser enforcement is the security boundary.
  • A wildcard with credentials is configured: browsers reject it, so the configuration may be broken rather than exploitable.
Working vocabulary

Terms you should be able to use precisely

CORS
Cross-Origin Resource Sharing: browser-enforced permission for one origin to read another origin's response.
Origin
Scheme, host and port of a page; different ports are different origins.
Preflight
An OPTIONS request that asks the server which cross-origin methods and headers are allowed.
Credentialed request
A fetch or XHR that includes cookies or HTTP authentication.
ACAO
Access-Control-Allow-Origin: the response header naming the permitted origin.
Vary: Origin
A cache directive that keeps responses for different origins separate.
Interview drill

Answer these without reciting a payload

Is CORS an authentication mechanism?

No. It is a browser read permission. Authentication still depends on cookies, tokens and server-side authorization.

Why is reflecting any Origin with credentials dangerous?

Any site can make the browser send the victim's credentials and then read the authenticated response, because the server explicitly allows that origin.

Why does curl show data that a browser blocks?

CORS is enforced by browsers, not by curl. A server-side client ignores the browser's same-origin policy.

Knowledge check

Can you separate the mechanism from the payload?

Four questions, graded on the server. Answers and explanations are released only after you submit, and signed-in learners keep a best score.

4 questions
01What does CORS actually control?
02Which configuration is exploitable with a victim session?
03Why is ACAO: * with credentials not a working attack?
04Which defense is strongest?
الخلاصة الموسّعة
لماذا هذا مهم؟

CORS ليست مصادقة، بل إذن قراءة يمنحه الخادم للمتصفح. إذا انعكس أي Origin مع credentials، يستطيع موقع المهاجم أن يقرأ بيانات الجلسة دون سرقة الكوكي. لا تثق باللواحق أو بـnull، واستخدم قائمة أصلية دقيقة، وأغلق credentials حيث لا تلزم، وأضف Vary: Origin. وتذكّر أن curl لا يفرض CORS، فالاختبار الحقيقي في المتصفح.

If the browser blocks the attacker from reading the response, what changes when the server grants permission anyway?