Fix permissive CORS configuration
Updated 1 Dec 2026
What it means
Your API allows any website to read its responses (Access-Control-Allow-Origin: * or echoing the caller's origin), possibly together with cookies. A malicious site can then read your users' data from their browser.
Why it matters
Customer data exposed to any website a logged-in user visits; can lead to account takeover through stolen tokens.
How to fix it
- Replace * or origin-reflection with an explicit allow-list of your own front-end origins.
- Never combine Access-Control-Allow-Credentials: true with a wildcard or reflected origin.
- Add Vary: Origin when the allowed origin is chosen per request.
Configuration examples
nginx
map $http_origin $cors_origin {
default "";
"https://app.YOUR_DOMAIN" $http_origin;
}
add_header Access-Control-Allow-Origin $cors_origin always;
add_header Vary Origin always;
Apache
SetEnvIf Origin "^https://app\.YOUR_DOMAIN$" CORS_ORIGIN=$0
Header always set Access-Control-Allow-Origin "%{CORS_ORIGIN}e" env=CORS_ORIGIN
Header always merge Vary Origin
Node.js / Express
import cors from 'cors';
app.use(cors({ origin: ['https://app.YOUR_DOMAIN'], credentials: true }));
Django (settings.py (django-cors-headers))
CORS_ALLOWED_ORIGINS = ['https://app.YOUR_DOMAIN']
CORS_ALLOW_CREDENTIALS = True
Laravel / PHP (config/cors.php)
'allowed_origins' => ['https://app.YOUR_DOMAIN'],
'supports_credentials' => true,
Any platform
Access-Control-Allow-Origin: https://app.YOUR_DOMAIN
Vary: Origin
Check your fix
curl -sI -H "Origin: https://evil.example" https://api.YOUR_DOMAIN/ | grep -i access-control
References
- https://developer.mozilla.org/docs/Web/HTTP/CORS
- https://portswigger.net/web-security/cors