Debug guide · you're seeing
Access to fetch at 'https://api.example.com/widgets' from origin 'https://app.example.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status.Access to fetch at 'https://api.example.com/widgets' from origin 'https://app.example.com' has been blocked by CORS policy: Request header field authorization is not allowed by Access-Control-Allow-Headers in preflight response.Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.example.com/widgets. (Reason: CORS preflight response did not succeed). Status code: 401.
How to Debug a Failed CORS Preflight
On this page
TL;DR: A preflight failure means the browser never got permission to send your real request. Find the
OPTIONSrequest in DevTools, replay it with curl, and check that it returns a 2xx with an allowed origin, method and headers. The usual culprit is authentication, a redirect or a proxy answeringOPTIONSbefore your CORS handler does.
1. Find the OPTIONS request
Open DevTools, select Network, and filter for OPTIONS. Inspect the preflight separately from the GET, POST, PUT, PATCH or DELETE you meant to send. Three request headers matter:
Origin: the exact scheme, host and port making the request.Access-Control-Request-Method: the method the browser wants to send.Access-Control-Request-Headers: the non-safelisted headers the browser wants to include.
A JSON Content-Type, an Authorization header, or a method such as PUT or DELETE triggers a preflight. The preflight itself is normal browser behavior, not the error.
2. Reproduce the browser’s preflight
Send the same origin, method and header names that DevTools shows:
curl -i -X OPTIONS 'https://api.example.com/widgets' \
-H 'Origin: https://app.example.com' \
-H 'Access-Control-Request-Method: POST' \
-H 'Access-Control-Request-Headers: content-type,authorization'
curl does not enforce CORS, which is exactly why it is useful here: you see the server’s raw answer. It does not prove the browser will accept that answer, so compare each returned header with what the browser asked for.
3. Validate every allow header
Any 2xx status works for a preflight; 204 No Content is the common choice:
HTTP/2 204
Access-Control-Allow-Origin: https://app.example.com
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Headers: Content-Type, Authorization
Access-Control-Allow-Credentials: true
Vary: Origin
| Check | Failure to look for |
|---|---|
| HTTP status | A redirect, 401, 403, 404 or 500 instead of a 2xx (“It does not have HTTP ok status”) |
| Allowed origin | Missing, a trailing-slash mismatch, or * together with credentials |
| Allowed method | The requested method is absent from Access-Control-Allow-Methods |
| Allowed headers | A requested header such as Authorization is absent from Access-Control-Allow-Headers |
| Credentials | The request sends cookies but Access-Control-Allow-Credentials: true is absent |
Header names are case-insensitive, but the values still have to cover what the browser requested. When the allowed origin is chosen dynamically, return the validated origin and add Vary: Origin so a shared cache never serves one site’s answer to another.
4. Check routers, authentication, redirects and proxies
OPTIONS has to reach the code that answers CORS. The classic failure is authentication middleware that runs first: the preflight carries no credentials, gets a 401, and the browser reports a CORS error.
- Handle
OPTIONSfor the same URL as the real endpoint, ahead of authentication. - Look for an HTTP-to-HTTPS or trailing-slash redirect on the route. A preflight may not follow redirects.
- Confirm the CDN, load balancer, WAF or reverse proxy forwards
OPTIONSand keeps the CORS headers. - Inspect error responses too. A proxy-generated 403 or 500 without CORS headers looks like a CORS failure to the browser.
5. Verify the actual response after the preflight succeeds
A successful preflight only lets the browser send the next request. That actual response must still carry a matching Access-Control-Allow-Origin and, when credentials are used, Access-Control-Allow-Credentials: true. Check both entries in the Network panel before calling it fixed.
Paste the request details into the CORS Debugger for a policy check. If the error is about the missing header on the actual response rather than the preflight, continue with No ‘Access-Control-Allow-Origin’ header.
Frequently asked questions
Why does the browser send OPTIONS before POST?
The browser preflights requests that are not CORS-safelisted, such as JSON requests, requests with non-safelisted headers like Authorization, and methods such as PUT, PATCH or DELETE. The OPTIONS request asks the server whether the real request is allowed.
Should a CORS preflight require authentication?
No. A preflight never carries the credentials of the actual request, so an authentication layer that rejects OPTIONS before CORS handling runs is one of the most common causes of this failure.
Why does the actual request fail after OPTIONS returns 204?
The preflight and the actual response are checked independently. The actual response can still lack a matching Access-Control-Allow-Origin header, or fail the credentials rule.
Sources
Related
No 'Access-Control-Allow-Origin' Header Is Present: Fix CORS
Fix the CORS error 'No Access-Control-Allow-Origin header is present on the requested resource' with working Express, nginx, S3, Workers and Django fixes.
Access-Control-Allow-Headers Header
Learn how Access-Control-Allow-Headers specifies which custom HTTP headers can be used during cross-origin requests in CORS preflight responses.
Access-Control-Allow-Origin Header: CORS Errors and Fixes
Access-Control-Allow-Origin explained: exact browser errors, why * fails with credentials, why you need Vary: Origin, and fixes for nginx, Express and Django.
HTTP OPTIONS Method
Learn how HTTP OPTIONS requests discover server capabilities, supported methods, and handle CORS preflight checks for cross-origin requests.