CORS errors are identical-looking messages with wildly different root causes, so resolving them fast requires a repeatable diagnostic process rather than trial-and-error configuration changes.
Overview
- CORS errors are symptoms, not diagnoses - the same browser message ("No Access-Control-Allow-Origin header") can mean network failure, server crash, missing config, stripped headers, or duplicate headers.
- Two checks resolve most issues: verify the server is reachable with a non-browser tool (curl/Postman), then inspect the DevTools Network tab for the preflight OPTIONS request.
- Preflight requests gate the real request - if OPTIONS fails, the browser never sends the actual GET/POST/PUT/DELETE, so debugging the "real" handler is wasted effort.
- CORS can only be fixed server-side or in infrastructure - no frontend code change (headers,
no-corsmode, library swaps) can bypass browser enforcement. - Multiple infrastructure layers (app code, proxy, load balancer, CDN) can each add CORS headers independently, and duplicates cause outright rejection since the spec requires exactly one
Access-Control-Allow-Originvalue.
Key Concepts
Reading CORS error messages correctly
- "No Access-Control-Allow-Origin header" has at least five distinct causes (network failure, server crash, no CORS config, stripped headers, wrong endpoint) - the message can't distinguish them.
- "Multiple values" errors are actually informative: they confirm the request reached the server and returned, but more than one layer (app, proxy, CDN) is adding the header.
- Credential and preflight-specific errors (e.g., "Method DELETE is not allowed by Access-Control-Allow-Methods") are the most actionable, naming the exact missing config.
Preflight requests (OPTIONS)
- Non-simple requests - custom headers like
Authorization, JSONContent-Type, or non-GET/POST methods - trigger an automatic OPTIONS request before the real one. - If the preflight response is missing or mismatched on
Access-Control-Allow-Methods,-Headers, or-Origin, the actual request never fires. - Common failure: the server returns 404/405 for OPTIONS (no handler), or custom routing/security middleware intercepts OPTIONS before CORS middleware runs.
// If only this OPTIONS request appears in DevTools Network tab,
// with no follow-up GET/POST/etc., the preflight is the failure point:
// OPTIONS /users/123
// Access-Control-Request-Method: GET
// Access-Control-Request-Headers: authorization, content-type
DevTools Network tab over Console tab
- The Console tab shows the browser's interpreted summary, which can hide whether the real cause is a preflight failure, an origin mismatch, or duplicate headers.
- The Network tab shows raw request/response headers, status codes, and timing - always compare the
Originrequest header against the returnedAccess-Control-Allow-Originvalue directly. - The Timing tab distinguishes "request never completed" (network/server issue) from "data received but blocked" (genuine CORS block) via Stalled/Waiting vs. Receiving phases.
Credentials and wildcard restrictions
credentials: 'include'(frontend) andAccess-Control-Allow-Credentials: true(backend) must both be explicitly set - one without the other fails.- The spec forbids
Access-Control-Allow-Origin: '*'combined withAccess-Control-Allow-Credentials: true; the backend must return an explicit origin instead.
Infrastructure and caching pitfalls
- CDNs, load balancers, reverse proxies, and API gateways can each independently add CORS headers, producing duplicates the browser rejects.
- CDNs that don't respect
Vary: Originmay serve one client's cachedAccess-Control-Allow-Originvalue to a different origin's request. Access-Control-Max-Agecaches preflight responses client-side, so a backend CORS fix can appear "not to work" for users with stale cached preflights until that cache expires.
Environment- and framework-specific failure modes
- Production commonly introduces cross-origin scenarios that don't exist in development (e.g., frontend/backend on the same
localhostport locally, separate domains in production). - Express relies on shared global middleware (ordering matters); Django uses
django-cors-headerswithCORS_ALLOWED_ORIGINS(the oldCORS_ORIGIN_WHITELISTis deprecated); Next.js API routes have no shared middleware pipeline by default, so each route must set headers itself (or usemiddleware.ts). - Development proxies (Vite, Next.js rewrites) eliminate CORS locally by making requests same-origin, but this masks real backend misconfiguration until deployment.
Trade-offs / Caveats
- Development proxies speed up local iteration but create a development/production behavior gap - periodic testing against a real deployed backend (or CI/CD validation) is needed to catch what the proxy hides.
- Gateway-level CORS (API Gateway, Kong) centralizes config and improves performance but conflicts if application code also sets CORS headers - pick one layer, not both.
mode: 'no-cors'in fetch doesn't bypass CORS; it makes the response opaque and unreadable, useful only for fire-and-forget requests where the response body is irrelevant.- Applying a blanket
Access-Control-Allow-Origin: '*'fix, or disabling auth "to simplify debugging," resolves the visible error while introducing security risk - the fix should be the minimal change addressing the actual mismatch.
Example in Practice
A team's checkout flow works in staging but throws CORS errors immediately after a production deploy. Following the systematic process:
# Step 1: Confirm the API is reachable outside the browser
curl -v -H "Origin: https://app.example.com" https://api.example.com/health
# Step 2: If curl succeeds but the browser fails, check DevTools Network tab
# for the OPTIONS preflight and compare its response headers:
# Access-Control-Allow-Origin: https://app.example.com (must match exactly)
# Access-Control-Allow-Methods: GET, POST, PUT, DELETE
# Access-Control-Allow-Headers: authorization, content-type
If the preflight succeeds but duplicate Access-Control-Allow-Origin headers appear in the actual response, the next step is testing each infrastructure layer independently (direct to app server, through load balancer, through CDN) with curl -v to identify which layer is adding a redundant header - a scenario common when a CDN's own CORS handling wasn't disabled after application-level CORS was added.
Related topics
- CI/CD validation of CORS configuration per deployment environment (e.g., GitHub Actions checks)
- HAR file analysis and browser extensions (CORS Unblock, CORS Everywhere) for advanced/collaborative debugging
- Serverless-specific CORS handling (AWS Lambda/API Gateway, Azure Functions) and cold-start timeout effects on preflight