Access-Control-Allow-Origin, credentials: include and the wildcard ban
In one line: Exact-match rules for Allow-Origin, the multiple-value error, why * is forbidden with credentials, and the three headers the rule applies to.
Access-Control-Allow-Origin is the centre of CORS. If it is missing or slightly off, the browser never hands the response body to the script — which is why a 200 status can still produce an empty screen.
1. Exactly one value
Only two forms are valid.
- The request origin, character for character — for example
https://app.example.com. Scheme, host and port must all match; a trailing slash makes it a different string. *— every origin, but only for requests that carry no credentials.
https://a.com, https://b.com is not a list — the browser reports “multiple values” and discards the response. To support several sites, compare the request origin against an allowlist and echo that one value, together with Vary: Origin.
2. Why * is forbidden with credentials
Allowing * on a request that carries cookies would let a malicious site read the response with the user's session. The specification therefore forbids * in three headers when the credentials mode is include.
| Header | * with include | Instead |
|---|---|---|
| Access-Control-Allow-Origin | forbidden | echo the request origin |
| Access-Control-Allow-Methods | forbidden | list the methods |
| Access-Control-Allow-Headers | forbidden | list the header names |
Access-Control-Allow-Credentials: true must also be present; without it an include response fails. The reverse is harmless but pointless: sending it on requests that carry no credentials only advertises permission you do not need.
3. The allowlist pattern
const ALLOWED = new Set(["https://app.example.com", "https://admin.example.com"]);
const origin = request.headers.get("Origin") || "";
const ok = ALLOWED.has(origin);
// only when ok: Access-Control-Allow-Origin = origin, Vary: Origin
Regular expressions such as https://*.example.com are common but dangerous: one compromised subdomain opens the whole tree. An explicit list is safer.
4. The messages you will meet
| Console message | Cause |
|---|---|
| No 'Access-Control-Allow-Origin' header is present | Header missing (or a 4xx/5xx response) |
| has a value '…' that is not equal to the supplied origin | String mismatch (scheme, port, slash) |
| must not be the wildcard '*' when the request's credentials mode is 'include' | * with include |
| header contains multiple values | Comma-separated values |
5. When cookies still do not arrive
Passing CORS does not guarantee cookies are sent. Check SameSite=None; Secure, third-party cookie blocking and a missing credentials: 'include' on the client. CORS headers and cookie attributes are separate problems.
6. Checking it in CorsLab
Set credentials to include and Allow-Origin to *: the block and the console message appear immediately. Switch to allowlist mode to watch the request pass only when its origin is on the list.
Put the same request and response into the simulator to see whether it passes and which header to change.
Open CorsLabFrequently asked questions
Can one Allow-Origin header list several domains?
No. One header, one value. Server code should look at the request origin, echo it when it is on the allowlist, and omit the header otherwise.
What is Origin: null?
It comes from sandboxed iframes, file:// documents and some redirects. Putting null on an allowlist trusts all of those, so avoid it.
Do I need CORS when the front end and API share a domain?
Same-origin requests skip the CORS check. A different subdomain or port makes it cross-origin again.
Sources
- Fetch Standard — CORS protocol
- MDN — Access-Control-Allow-Origin
- MDN — Cross-Origin Resource Sharing (CORS)
Read next
- When a CORS preflight (OPTIONS) is sent, and what the browser checksThe exact conditions that make the browser send OPTIONS before the real request, the three headers it carries, and the order in which the response is checked.
- Simple-request checks: method, headers and Content-TypeThe Fetch Standard safelist explained value by value, including the byte rules for header values and the Range exception.
- Vary: Origin and CDN cache poisoningHow a cache that keys on the URL alone reuses the wrong response, what it looks like in both directions, and how to set Vary: Origin on each platform.