Almost every frontend-to-API integration hits a CORS failure that works in curl and fails only in the browser. In production, three specific misconfigurations cause the majority of these incidents.
1. When a Request Quietly Triggers an OPTIONS Preflight
Adding Content-Type: application/json or an Authorization: Bearer ... header upgrades a request out of the Fetch "simple request" category. The browser sends an unauthenticated OPTIONS preflight first.
If your auth middleware intercepts OPTIONS and returns 401, or your reverse proxy omits Access-Control-Allow-Headers, the browser aborts before sending the real POST or GET.
2. The credentials: 'include' + Wildcard * Trap
Browsers explicitly forbid returning Access-Control-Allow-Origin: * when Access-Control-Allow-Credentials: true is set for cookie-backed sessions.
Instead of a wildcard, validate Origin against an explicit allowlist and echo back that single origin:
map $http_origin $cors_origin { default ""; "https://app.example.com" $http_origin; "http://localhost:3000" $http_origin; } add_header Access-Control-Allow-Origin $cors_origin always; add_header Access-Control-Allow-Credentials "true" always; add_header Vary "Origin" always; 3. Missing Vary: Origin Behind CloudFront or Cloudflare
When multiple subdomains share an API or static asset host, forgetting Vary: Origin lets the CDN cache the first caller's Access-Control-Allow-Origin header and serve it to the second subdomain, producing intermittent CORS failures that vanish on cache purge.
Testing Header Combinations Locally Before Deploying
To sanity-check preflight rules and response headers without deploying guess-and-check config commits:
- CORS Preflight Simulator (client-side, 0B upload): https://global-utils.com/en/cors-simulator
- CSP Header Generator: https://global-utils.com/en/csp-generator
- JWT Decoder (local browser memory): https://global-utils.com/en/jwt-decoder