Access-Control-Allow-Origin
This CORS header specifies which origins can access your resources, controlling cross-origin data sharing.
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 CORS can allow any website to read data from your API using victim's credentials. This is a common source of data breaches.
How We Check
We test CORS behavior with various origin values and check for dangerous patterns like reflecting arbitrary origins with credentials.
Good vs Bad Values
| Value | Verdict | Why |
|---|---|---|
Access-Control-Allow-Origin: https://app.example.com | Good | One explicit, trusted origin. Pair it with `Vary: Origin` when the value is chosen per request. |
Echo of the request Origin only if it is in a server-side allow-list | Good | The correct way to support several origins, since the header itself accepts only one. |
Access-Control-Allow-Origin: * on a public, credential-less resource | Weak | Acceptable for fonts, open data or public CDN files. Never for anything personalised. |
Reflects any Origin and sends Access-Control-Allow-Credentials: true | Bad | Any website can read authenticated responses from your visitors' browsers. This is the classic CORS data-theft bug. |
Access-Control-Allow-Origin: null | Bad | Sandboxed iframes and file:// pages send `Origin: null`, so an attacker can produce a matching origin on demand. |
Suffix or substring match such as endsWith('example.com') | Bad | Also matches evilexample.com and example.com.attacker.net. Compare the full origin string exactly. |
Access-Control-Allow-Origin: *.example.com | Bad | Wildcards inside a host are not valid syntax; browsers ignore the header and legitimate calls fail. |
Header absent on endpoints that are not meant for cross-origin use | Good | Default same-origin policy applies. Nothing to configure. |
How to Fix
Use an explicit allowlist of trusted origins. Never reflect the Origin header without validation when credentials are involved.
Nginx — allow-list of origins through map; the header is omitted when the origin is not listed:
map $http_origin $cors_origin {
default "";
"https://app.example.com" $http_origin;
"https://admin.example.com" $http_origin;
}
server {
location /api/ {
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Vary Origin always;
}
}
Apache (requires mod_headers):
SetEnvIf Origin "^https://(app|admin)\.example\.com$" CORS_ORIGIN=$0
Header always set Access-Control-Allow-Origin "%{CORS_ORIGIN}e" env=CORS_ORIGIN
Header append Vary Origin
Next.js — one fixed origin for the API routes in next.config.js:
async headers() {
return [{
source: "/api/:path*",
headers: [
{ key: "Access-Control-Allow-Origin", value: "https://app.example.com" },
{ key: "Access-Control-Allow-Methods", value: "GET,POST,OPTIONS" },
{ key: "Vary", value: "Origin" },
],
}];
}
Several origins in a Next.js route handler or Express app: compare the request's Origin header against a Set of allowed values and echo it back only on a match, then append Vary: Origin. Cloudflare: use a Transform Rule for one fixed origin, or a Worker for an allow-list.
Test it by sending a hostile origin. A safe server returns no Access-Control-Allow-Origin header for an unlisted origin:
curl -si https://api.example.com/me -H 'Origin: https://evil.example' | grep -i '^access-control'
Repeat with Origin: null and with an origin that merely ends with your domain (https://evilexample.com). All three should come back without the header.
Common Mistakes
- Using `*` together with `Access-Control-Allow-Credentials: true`. Browsers reject the combination, which often pushes developers into reflecting the origin instead, which is worse.
- Reflecting the Origin header without `Vary: Origin`. A shared cache can then serve one visitor's CORS response to another origin.
- Allow-listing with a regular expression that is not anchored (`^…$`) or does not escape dots.
- Opening CORS on the whole site to fix one API route. Scope the header to the paths that need it.
Frequently Asked Questions
What is Access-Control-Allow-Origin?
This CORS header specifies which origins can access your resources, controlling cross-origin data sharing.
Why does Access-Control-Allow-Origin matter for website security?
Misconfigured CORS can allow any website to read data from your API using victim's credentials. This is a common source of data breaches.
How do I fix Access-Control-Allow-Origin issues?
Use an explicit allowlist of trusted origins. Never reflect the Origin header without validation when credentials are involved.
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-Origin issues and 61 other security checks.
Scan Your Website Free