CORS (Cross-Origin Resource Sharing)
coreintermediateCORS is a browser-enforced relaxation of the same-origin policy — by default a browser blocks a page on one origin from reading a response from a different origin, and CORS is the set of response headers a server can send to explicitly allow specific other origins to read its responses.
Think of it as
The same-origin policy is a building where every tenant's mail is locked to their own floor by default. CORS is a tenant explicitly posting a notice at the mail room: "residents of floor 7 (this specific origin) may also collect from my box" — the mail room (browser) is what actually enforces it, not the tenant.
What we're doing: Show the concrete decision a server makes per request: reflect the origin back only if it is on an explicit allowlist, never a blanket "*" when credentials are involved.
- 2
- An explicit allowlist, not a wildcard — this is what makes CORS a real access-control decision instead of a formality.
- 7
- Access-Control-Allow-Origin must echo the SPECIFIC requesting origin (not "*") whenever credentials are also allowed, per the CORS spec.
{'Access-Control-Allow-Origin': 'https://app.example.com', 'Access-Control-Allow-Credentials': 'true'}
{}Why this works: The allowed origin gets the full CORS headers back; the disallowed one gets an empty dict — no Access-Control-Allow-Origin header at all — which is what causes a browser to block the page's JavaScript from reading that response, even though the HTTP request itself still reached the server and the server still did the work.
- Page JS → Browser: fetch("https://api.example.com/data")
- Browser → Server: GET /data (Origin: https://app.example.com)
- Server → Browser: Access-Control-Allow-Origin: https://app.example.com (origin is on the server's allowlist)
- Browser → Page JS: response readable
- Browser → Page JS: blocked — no matching header (the HTTP request still reached the server either way)
Setting Access-Control-Allow-Origin: "*" on an endpoint that also allows credentials
Wrong
Better
What you see: A cross-origin request that includes cookies/credentials fails in the browser with a CORS error, even though the same request works fine from curl or Postman.
Why: The Fetch/CORS spec explicitly forbids combining a wildcard origin with Allow-Credentials: true — allowing "any origin" to also read credentialed responses would defeat the entire purpose of the same-origin policy, so browsers refuse to honor that combination rather than silently allowing it.
Key CORS response headers
Remember: CORS is enforced by the browser, not the server — reflect a specific validated origin (never "*") whenever credentials are involved.
See also: csrf · https tls and same origin policy

