Identify the failing request first
CORS controls whether browser code may read a cross-origin response. Some requests reach the server even if the browser blocks the response; CORS is not authentication or CSRF protection. A missing header can also accompany a 401, 403, 500, redirect, network or TLS failure. Check the original cause before changing access rules.
1. Inspect the browser Network panel
Select the failing request. Record its Origin, URL, method, status and whether a separate OPTIONS preflight failed. An origin is scheme, host and port. Compare the request and response headers without copying cookies, tokens, query strings or private payloads into a ticket.
2. Check preflight and actual response separately
From a terminal, use a synthetic test against an endpoint you own. Replace both example addresses and method/header list with your own authorized test settings; do not include credentials:
curl -i -X OPTIONS 'https://api.example.test/resource' \
-H 'Origin: https://app.example.test' \
-H 'Access-Control-Request-Method: POST' \
-H 'Access-Control-Request-Headers: content-type'
Compare the preflight status and the allowed origin, method and headers with the browser request. Then inspect the actual response, including error responses. A successful OPTIONS response alone does not prove that the real request succeeds. Some requests do not trigger a preflight. Curl does not enforce browser CORS, so repeat the actual scenario in the browser.
3. Match the policy to the application
- For a private API, allow only intended origins, methods and headers; CORS does not grant or replace server-side authorization.
- If the browser sends credentials such as cookies, the response needs the exact permitted origin and
Access-Control-Allow-Credentials: true;Access-Control-Allow-Origin: *is incompatible with credentialed browser requests. Cookie SameSite and third-party cookie policies can still prevent cookies from being sent. - For a deliberately public, non-credentialed resource, a wildcard may be appropriate. Do not blindly reflect arbitrary Origin values. When the response differs by origin, include
Vary: Originand review cache behavior. - Choose one controlled CORS layer, such as application middleware or reverse proxy, and avoid duplicate headers. Preserve existing upstream routing and authentication; a replacement Nginx
locationblock can disrupt the application.
4. Verify positive and negative controls
Use a permitted origin and then a deliberately unpermitted test origin. Verify preflight and actual response, intended method/header, browser credentials policy and an error response. The unpermitted origin should not receive CORS permission. Confirm server authentication and authorization still reject unauthorized operations independently. Do not disable browser security or expose an unrestricted proxy.
References: MDN CORS guide, Express CORS middleware. Related: Laravel 419 session and CSRF checks. Reviewed 14 November 2026.