THE TAKEAWAYS

What to take away

  • CORS decides which origins' scripts may read responses; it does not protect the server.
  • Credentialed requests cannot use an asterisk. Keep an allowlist and return only matching origins.
  • When returning a specific origin, add Vary: Origin so caches do not mix responses.
  • Check preflight responses, Max-Age and redirects per environment with a checklist.

FROM PRIMARY SOURCES

What CORS decides

Browsers restrict cross-origin requests from scripts; fetch() and XMLHttpRequest follow the same-origin policy unless the other origin returns the right CORS headers.

CORS lets a server tell the browser which other origins may read its responses; it does not stop clients calling the API outside a browser.

Treating CORS as API protection, or opening it fully because it is only a browser rule, are both mistakes.

MDN notes that error details are not available to JavaScript, so the browser console is the only reliable clue.

Sources: [1]

FROM PRIMARY SOURCES

Keep an allowlist of origins

Access-Control-Allow-Origin accepts an asterisk, a specific origin or null; the asterisk can be used only for requests without credentials.

Public data may be fine with an asterisk, but per-user APIs should return only origins on an explicit list.

Match the full scheme, host and port exactly; substring checks allow lookalike domains.

MDN says the null value should be avoided because anyone can create a document with a null origin.

Sources: [2]

FROM PRIMARY SOURCES

Rules for credentialed requests

By default, browsers do not send credentials in cross-origin fetch() or XMLHttpRequest calls; the caller must opt in.

The response must include Access-Control-Allow-Credentials: true, and a wildcard origin causes the browser to block access and report a CORS error.

Reflecting the request Origin with credentials enabled lets any site read signed-in users' responses, which can be worse than an asterisk.

Third-party cookie policies may still block credentialed requests even when CORS allows them.

Sources: [1]

FROM PRIMARY SOURCES

Understanding preflight

For preflighted requests, the browser first sends an OPTIONS request to check whether the actual request is safe to send.

The response lists allowed methods and headers; since preflight requests never include credentials, they must be handled before authentication.

Access-Control-Max-Age controls how long the preflight result is cached; the default is 5 seconds and browsers cap the value.

Some browsers do not follow redirects after preflight, so use canonical API addresses that do not redirect.

Sources: [1]

FROM PRIMARY SOURCES

Caching and Vary

When returning a specific origin, MDN says the response should also include Vary: Origin.

Without it, caches may serve one origin's headers to another, causing intermittent errors or unintended permission.

With a CDN, either include Origin in the cache key or exclude CORS responses from caching, and keep signed-in responses out of shared caches.

Sources: [2]

EDITORIAL PRACTICE

Managing settings per environment

Keep separate allowlists per environment so development origins such as localhost never reach production.

Record who requested each origin and why, and remove origins when partnerships end.

Choose one layer, application, gateway or CDN, to add CORS headers to avoid duplicates and overrides.

Sources: [2][1]

EDITORIAL PRACTICE

Investigating errors

Start with the console and network log: is a preflight sent, what does it return, and does the actual response carry the headers?

Common causes are missing origins, authentication rejecting OPTIONS, an asterisk with credentials, missing headers on error responses, and redirects.

Do not widen permissions immediately; schedule the reversal of any emergency change.

When outsourcing, require console messages, both sets of headers and tested origins in the report.

Sources: [1]

EDITORIAL PRACTICE

Acceptance checklist

Check per-environment allowlists, exact matching, no headers for unknown origins and no null.

Check credentialed APIs return specific origins, preflight is handled before authentication, and Max-Age and canonical addresses are set.

Check Vary: Origin and CDN settings, and confirm the API's own authentication and authorisation work independently of CORS.

Sources: [1][2]

WITH OPERUN.

Delegate everyday AI management.

CORS tells the browser which origins' scripts may read your responses. Widening it to silence errors risks exposing signed-in users' data to other sites. Keep an allowlist, understand credentials and preflight, and align caching with Vary: Origin, and configuration changes stop being emergencies.

Discuss your product and AI work

Primary sources

Sources checked on 18 November 2026. The workflows and checklists are editorial proposals.

  1. [1]
  2. [2]

Share this insight