Ritenta

A CORS error is a browser contract failure

Use the Network panel to separate a failed connection, preflight and missing CORS permission.

Published: 2 min read

A fetch() call can reach a server and still be unavailable to page JavaScript. Cross-Origin Resource Sharing (CORS) is the browser's protocol for deciding whether a response from another origin may be exposed to a script. It is not a way for the browser to fix a server's permissions. MDN's CORS guide describes the request and response headers.

Read the request before changing headers

Open the Network panel and inspect the request URL, method, status and response. If the connection failed, diagnose DNS, TLS, server availability or mixed content first. If an OPTIONS request appears, it is a preflight: the browser is asking which cross-origin method and headers the server permits. A failing preflight means the actual request may not be sent.

For a permitted origin, the server might return:

Long code lines scroll sideways →
Access-Control-Allow-Origin: https://app.example.test
Vary: Origin

If the server dynamically chooses an allowed origin, Vary: Origin tells caches that responses differ by request origin. A request carrying credentials needs an explicit allowed origin rather than *, plus the appropriate credential permission. Do not copy the request's Origin header into the response without checking it against an allowlist.

Keep security boundaries separate

CORS controls what browser scripts can read. It does not authenticate a user, authorize an operation, or prevent non-browser clients from sending requests. A public API can still require authorization for private data. A same-origin backend proxy can sometimes simplify browser routing, but it must enforce its own authentication and target restrictions; it is not a reason to disable checks.

When debugging, write down which request failed and why: connection, preflight, or response permission. That diagnosis tells you whether to change deployment, server CORS policy, or the client request. Setting mode: 'no-cors' is not a general solution because the script then receives an opaque response it cannot inspect.