opyebCorsLab

Access-Control-Allow-Origin, credentials: include and the wildcard ban

Credentials · 8 min

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 includeInstead
Access-Control-Allow-Originforbiddenecho the request origin
Access-Control-Allow-Methodsforbiddenlist the methods
Access-Control-Allow-Headersforbiddenlist 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 messageCause
No 'Access-Control-Allow-Origin' header is presentHeader missing (or a 4xx/5xx response)
has a value '…' that is not equal to the supplied originString mismatch (scheme, port, slash)
must not be the wildcard '*' when the request's credentials mode is 'include'* with include
header contains multiple valuesComma-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 CorsLab

Frequently 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

Read next

0 bytes of your input sent to a server (advertising and affiliate widgets excluded)