TR EN

How to Fix CORS Error: No 'Access-Control-Allow-Origin' Header

CORS errors need diagnosis of the browser request, preflight, actual response and permitted origins before changing server access rules.

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: Origin and 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 location block 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.

Frequently Asked Questions

Can CORS errors be resolved strictly from client-side JavaScript?
A client can correct an incorrect URL or request mode, but cannot grant itself server CORS permission. A proxy you control is a separate server component.
Is wildcard Access-Control-Allow-Origin: * secure in production?
It can be appropriate for deliberately public non-credentialed resources. Credentialed browser requests require an explicit allowed origin and credential permission.