Access-Control-Allow-Credentials
This CORS header determines whether browsers should expose responses to frontend JavaScript when credentials are included.
Results in 1–3 minutes · Free · No signup required
Want the result for your own site? Free CORS Checker — paste your domain, get the report.
Why It Matters
Misconfigured credentials handling can allow malicious sites to make authenticated requests to your API and read the responses, stealing user data.
How We Check
We verify that Access-Control-Allow-Credentials is only used with specific origins (not wildcards) and proper Access-Control-Allow-Origin values.
Good vs Bad Values
| Value | Verdict | Why |
|---|---|---|
Header absent | Good | Cross-origin requests are made without cookies or HTTP authentication. This is the right default for any public API. |
Access-Control-Allow-Credentials: true with Access-Control-Allow-Origin: https://app.example.com | Good | Credentialed requests are limited to one named origin. This is the intended pairing, as long as the origin comes from an allowlist. |
Access-Control-Allow-Credentials: true with Access-Control-Allow-Origin: * | Bad | Browsers refuse this pair, which means the code is broken. It also shows server logic that may reflect any origin in other paths. |
Access-Control-Allow-Credentials: true with a reflected Origin header and no allowlist | Bad | Any website can read authenticated responses. The scanner sends no cross-origin Origin, so test this yourself with `curl -H 'Origin: https://evil.example'`. |
Access-Control-Allow-Credentials: true with Access-Control-Allow-Origin: null | Bad | The `null` origin is sent by sandboxed iframes, data: URLs and local files, so an attacker can produce it at will. |
Access-Control-Allow-Credentials: true with an origin matched by suffix (endsWith("example.com")) | Bad | evil-example.com matches. Compare against exact origins, not substrings or loose regular expressions. |
Access-Control-Allow-Credentials: True | Weak | The value is case-sensitive in the specification; browsers ignore anything other than lowercase `true`, so credentialed calls fail while the scanner passes. |
Access-Control-Allow-Credentials: false | Weak | Not a defined value. It is treated as absent, but omitting the header states the intent more clearly. |
How to Fix
Only set Access-Control-Allow-Credentials: true with explicit origin validation. Never use with Access-Control-Allow-Origin: *.
Express — validate against an exact allowlist, never reflect blindly:
const allowed = new Set(["https://app.example.com", "https://admin.example.com"]);
app.use((req, res, next) => {
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.vary("Origin");
}
next();
});
Nginx — use map blocks to turn the allowlist into header values. Nginx does not send an add_header whose value is empty, so unlisted origins receive no CORS headers at all:
map $http_origin $cors_origin {
default "";
"https://app.example.com" $http_origin;
"https://admin.example.com" $http_origin;
}
map $cors_origin $cors_credentials {
default "true";
"" "";
}
server {
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Access-Control-Allow-Credentials $cors_credentials always;
add_header Vary Origin always;
}
Apache (requires mod_headers and mod_setenvif):
SetEnvIf Origin "^(https://(app|admin)\.example\.com)$" CORS_ORIGIN=$1
Header always set Access-Control-Allow-Origin "%{CORS_ORIGIN}e" env=CORS_ORIGIN
Header always set Access-Control-Allow-Credentials "true" env=CORS_ORIGIN
Header always merge Vary Origin
Next.js route handlers: read request.headers.get("origin"), check it against a Set, and add the three headers to the Response only on a match. Do the same in the OPTIONS handler. Cloudflare: do this in the origin or in a Worker; Transform Rules cannot validate an origin against a list.
Verify with curl -si -H 'Origin: https://evil.example' https://api.example.com/me | grep -i access-control. The command must print nothing, and the same request with an allowed origin should return the exact origin plus true.
Common Mistakes
- Echoing the request's `Origin` header back to satisfy credentialed CORS without checking it. This is the most common route to account takeover through CORS, and many frameworks make it a one-line setting.
- Using wildcard `*` for origin, headers or methods while credentials are on. Wildcards are treated literally in credentialed requests, so browsers reject the response.
- Trusting `null` because a local test page sends it. Remove `null` from the allowlist.
- Allowing every subdomain (`*.example.com`) when any subdomain can host user content or has a takeover issue. A single weak subdomain then reads the whole API.
- Forgetting `Vary: Origin` when the allowed origin changes per request, so a shared cache serves one origin's credentialed answer to another.
- Using cookies for the API but setting `SameSite=None` on them just to make CORS work. Prefer a token in the `Authorization` header or same-site hosting when you can.
Frequently Asked Questions
What is Access-Control-Allow-Credentials?
This CORS header determines whether browsers should expose responses to frontend JavaScript when credentials are included.
Why does Access-Control-Allow-Credentials matter for website security?
Misconfigured credentials handling can allow malicious sites to make authenticated requests to your API and read the responses, stealing user data.
How do I fix Access-Control-Allow-Credentials issues?
Only set Access-Control-Allow-Credentials: true with explicit origin validation. Never use with Access-Control-Allow-Origin: *.
Related Security Checks
Related Tool
CORS Checker
Run all 6 related checks with our free cors checker
Check Your Website Now
Run a free security scan to check for Access-Control-Allow-Credentials issues and 61 other security checks.
Scan Your Website Free