What is CORS and why does the browser block a request to your API?
Published on 2026-10-20 by frfrand
What is CORS, how the preflight OPTIONS works, difference with authentication and how to configure it without allowing any origin.

Short answer: CORS is a browser mechanism that controls when code from a page can read responses from another origin. The error is fixed on the server, authorizing with Access-Control-Allow-Origin the corresponding origins and handling the preflight OPTIONS, not by disabling browser security.
Its acronym stands for Cross-Origin Resource Sharing. If a frontend on app.ejemplo.com tries to query an API on api.ejemplo.com, CORS may come into play because the origins are different.
It is not an Internet failure nor an authentication system. It is a policy related to the browser and cross-site security.
What does origin mean?
On a web page, the origin is defined by scheme, host name, and port. https://ejemplo.com and http://ejemplo.com do not have the same origin. Neither do https://ejemplo.com and https://api.ejemplo.com.
This distinction exists so that any page cannot freely read data from other sites where a person has open sessions.
A everyday example
Imagine you are inside your bank in one tab and you open an unknown website in another. It would be dangerous if that second website could automatically query your account details and read the response just because your browser has a bank session.
The browser applies the same-origin policy and allows certain controlled exceptions via CORS. The server decides which origins it authorizes to read certain responses.
What does the server do?
A response can include Access-Control-Allow-Origin to indicate which origin is allowed. For example, an API intended for a single frontend could expressly authorize https://app.ejemplo.com.
It is not always appropriate to use *. If the API sends private data or depends on credentials, the configuration must be much more specific. In addition, there are special rules for requests with credentials.
CORS does not replace backend access controls. A client that is not a browser can call an API directly even if it does not send the Origin header.
What is a preflight OPTIONS?
In certain requests, the browser first checks whether the operation is allowed, normally via an HTTP OPTIONS request. This prior verification is called a preflight.
It can occur, for example, when the frontend needs to send certain custom headers or methods. The server must respond with compatible information about allowed methods and headers.
A common mistake is configuring a POST route correctly, but forgetting that the server or proxy must handle the preflight. From the browser it looks like the API is down, even though it responds perfectly from another tool.
How to investigate a CORS error?
First, open the browser's developer tools and check the failed request, its origin, its headers, and the response. Check if there was a prior OPTIONS call.
Then verify the backend configuration and any intermediate proxy. Do not start by adding duplicate headers in Nginx and in the application without knowing which of the two layers will manage them.
Another mistake is installing an extension that temporarily disables browser restrictions and assuming you have already fixed the application. That only hides the symptom on your machine.
CORS does not protect your API from abusive use
Although an unauthorized website cannot read certain responses via JavaScript in the browser, your API still needs authentication, authorization, validation, traffic limits, and appropriate protection against web attacks.
CORS does not by itself prevent someone from calling a public endpoint from a server-side script.
What happens with ArduMaker?
In ArduMaker, a deployment from GitHub is published by hostname (a domain or subdomain), not by path. The usual thing is to have the frontend on one subdomain and the API on another, for example app.ejemplo.com and api.ejemplo.com: they are different origins, so the API must respond with CORS for the frontend origin. The platform does not add those headers for you: they are configured in the application, and that is usually safer than indiscriminately allowing any origin.
Serving the API under the same domain, at /api, avoids CORS, but requires manually editing the server block of the nginx on the VPS.
In one sentence: CORS controls certain cross-origin reads performed by browsers. The error is not fixed by "turning off security," but by authorizing the necessary origins and verifying how the server responds.
Frequently Asked Questions
Why does the API respond in Postman or curl and fail in the browser? Because CORS is applied by the browser. Postman and curl do not check it, so the call works even if CORS headers are missing.
**Can I use Access-Control-Allow-Origin: ?* Only for public resources without credentials. If the request carries cookies or authorization headers, the browser does not accept the wildcard and the exact origin must be specified.
Does CORS protect my API? No. It only controls what JavaScript from other pages can read in a browser; authentication and authorization are still necessary.
Sources: CORS on MDN · Same-origin policy.
