Confirm the browser is reporting a CORS failure

Start in the browser developer tools, not by changing server headers at random. Record the page origin, request URL, method, and console message. An origin includes the scheme, host, and port, so `http://localhost:3000` and `http://localhost:5173` are different origins.

In the Network panel, check whether the browser sent an OPTIONS preflight and whether the actual request followed it. When a CORS check fails, JavaScript often receives only a generic network error; the browser console and response headers provide the useful detail. A command-line request can succeed because curl does not enforce the browser’s CORS rules.

Inspect the preflight request and response

A preflight tells the server which origin, method, and request headers the browser wants to use. It commonly appears when a cross-origin request uses a method or header that requires preflight; an Authorization header is one common reason. The server’s response must allow that origin, method, and requested headers before the browser sends the actual request.

Code
curl --include --request OPTIONS "${API_URL}" \
  --header "Origin: https://app.example.test" \
  --header "Access-Control-Request-Method: POST" \
  --header "Access-Control-Request-Headers: authorization,content-type"

This sends a harmless preflight-shaped request without an access token. Compare the response status and Access-Control headers with the browser’s requested values. It helps inspect the server response, but only a real browser can confirm that the browser accepts the complete CORS exchange.

Match the response headers to the client request

Request detailWhat the server must address
OriginReturn the exact allowed origin, or a wildcard only when the request does not use credentials.
Requested methodInclude the actual method in Access-Control-Allow-Methods.
Requested headersAllow each non-safelisted header the browser lists in Access-Control-Request-Headers.
Cookies or other credentialsThe client must opt in and the response must allow credentials; a credentialed request cannot use Access-Control-Allow-Origin: *.

When the server chooses an explicit allowed origin dynamically, include `Vary: Origin` so shared caches do not reuse one origin’s response for another. Do not return `Access-Control-Allow-Origin: null` as a shortcut.

Use a narrow configuration, not a universal wildcard

Code
Access-Control-Allow-Origin: https://app.example.test
Access-Control-Allow-Methods: GET, POST
Access-Control-Allow-Headers: Authorization, Content-Type
Access-Control-Allow-Credentials: true
Vary: Origin

This is an illustrative response for a credentialed client on a known origin; it is not a copy-paste configuration for every API. List only the origins, methods, and headers the feature needs. If the client does not send credentials, omit Access-Control-Allow-Credentials rather than setting it to false. The exact server or framework setting depends on where CORS is implemented.

CORS controls whether browser scripts may read a cross-origin response; it does not authenticate callers or replace authorization checks. Non-browser clients can make requests regardless of CORS, so the API must enforce identity and permissions on every protected operation.

Check common failure points in order

  1. Compare the browser Origin with the configured allowed origin, including scheme and port.
  2. If an OPTIONS request exists, confirm it is not rejected by authentication middleware, redirected, or routed to a different server than the actual request.
  3. Compare Access-Control-Request-Method and Access-Control-Request-Headers with the server’s allow lists.
  4. For credentialed fetches, verify the client’s credentials mode and the response’s exact origin and credentials headers; do not combine credentials with a wildcard origin.
  5. Check whether a reverse proxy, CDN, or cache removes headers or serves a response generated for another origin.

Preflight requests do not carry the credentials of the subsequent request. A server that requires a login cookie before it will answer OPTIONS can therefore block the browser before the authenticated request is sent. Configure the preflight path deliberately while continuing to authorize the actual request.

Retest in the browser and keep access control intact

After changing the server or proxy configuration, reload the page and inspect both the preflight and actual response. Test an allowed origin and a disallowed origin, and verify that an unauthenticated caller still cannot access protected data. Keep the console message, sanitized headers, and request ID with the issue so the next failure can be traced to the responsible layer.

Official references