Your frontend shows a CORS error. You open the same API endpoint with a command-line client and get a response. That is not a contradiction. The browser and the API server are making different decisions.
CORS controls which origins a browser lets read cross-origin responses. It does not establish who a caller is or which records that caller may access. Treating it as an API lock leaves the actual access decision in the wrong place.
There is an important wrinkle: a failed preflight can stop the browser from sending the actual request. So "CORS never blocks requests" is wrong too. The useful question is which request, from which client, and at which stage.
Start with two origins
Imagine a frontend at https://app.example.com calling https://api.example.com. They share a parent domain, but their hostnames differ, so they are different origins.
The MDN CORS guide describes CORS as an HTTP-header-based mechanism for telling browsers which other origins may load resources. An origin includes the scheme, host, and port. A different port can therefore create the same cross-origin problem during local development.
The API might return an Access-Control-Allow-Origin header allowing the frontend's origin. That is permission for the browser's cross-origin access, not evidence that the person using the frontend owns the requested invoice.
The server still needs to authenticate the caller where required and check permission for that invoice. Do that regardless of whether the request came from the approved frontend, a script, or another server.
Some requests go out before the browser refuses the response
MDN calls a category of requests "simple requests," while noting that the term comes from the older CORS specification. These requests do not trigger a preflight.
For example, a cross-origin GET without non-safelisted request headers may go directly to the API. If the response does not grant the requesting origin access, the browser does not expose it to the calling JavaScript.
That failure does not mean the API never received the request. It means the script did not get access to the response. If you use the console error as proof that no server-side work happened, you are checking the wrong evidence.
My advice is to inspect both sides in a test environment: the browser's Network panel and the server's request log. Keep sensitive values out of those logs. A response hidden from JavaScript and a request absent from the server are different outcomes.
Other requests ask permission first
Now change the call to a POST with Content-Type: application/json, or add an Authorization header. Those are examples that trigger CORS preflight rather than meeting the simple-request conditions.
The browser sends an OPTIONS request describing the intended method and headers. If the preflight fails, it does not proceed with the actual request. If it passes, the browser can proceed, subject to the other applicable browser checks.
This is why two requests to the same URL can appear to behave differently. One goes directly to the endpoint, while the other stops after OPTIONS. A cached preflight permission can also mean you do not see a fresh OPTIONS request on every call.
Read the Network panel as a sequence, not a single red error. Was there an OPTIONS request? Was the actual GET or POST sent? Which response failed the browser's access check?
A non-browser client does not become your frontend
The Express cors middleware README makes the boundary explicit: browsers enforce CORS, while clients such as curl, Postman, and other servers do not enforce it.
An origin allowlist therefore cannot substitute for authentication or object-level authorization. A non-browser client can send requests without obeying browser response-reading rules. It still needs whatever credentials and permissions your server actually requires.
This does not make CORS pointless. Correctly configured CORS lets your browser frontend use the API while restricting other origins' access to responses. The mistake is asking it to do a separate job: decide who may use the API at all.
Cookies introduce another question
If your application uses cookies for authentication, do not equate "another origin cannot read this response" with "another site cannot cause an action."
As MDN explains, simple requests are possible across origins partly because HTML forms have long been able to submit them. Whether cookies accompany a particular request depends on credentials settings, cookie attributes, and browser policy. Cross-origin and cross-site are not interchangeable terms.
The OWASP CSRF Prevention Cheat Sheet recommends using your framework's built-in CSRF protection where available. It treats SameSite cookies as a defense layer, not a universal replacement for CSRF defenses.
Choose the controls for your authentication design. Do not fix a browser error by allowing arbitrary origins with credentials, and do not assume a strict CORS configuration completes the CSRF work.
Test the boundary you mean to protect
On an API you control, test an allowed browser origin, an unapproved browser origin, and a non-browser client. Check both an unauthenticated request and a request for another test account's record.
Then separate the results: did the browser send the request, could JavaScript read the response, and did the server authorize the action? Those are different questions. CORS answers the browser-access question. Your API still owns the permission decision.
Cover photo by Guillaume Bourdages, free to use under the Unsplash License.
I write about startups and AI on StartupWiki.

Top comments (0)