CORS explained in plain terms means the set of rules that decide when a website may ask another website for data. The central question is why a page that works perfectly on its own suddenly fails when it tries to fetch information from a different address, and the short answer is that the browser blocks the request on purpose, unless the other site explicitly says it is allowed.
Anyone who has built a website has met this error. A page loads, the code asks a public data service for the latest figures, and the browser refuses with a message about a missing header. The code is correct and the service is running, yet the browser will not let it through.
The reason is security. Left unchecked, any website could quietly read data from any other site you are logged into, including your email or your bank. CORS is the browser’s way of drawing a line: a page may freely talk to its own site, but talking to another site needs that site’s permission first.
Key takeaways
- CORS is the browser rule that controls when a web page may request data from a different origin.
- An origin is the combination of protocol, domain, and port, so a different subdomain or port counts as different.
- The browser blocks the page from reading the response unless the server sends the right permission headers.
- Simple requests go straight ahead; riskier ones first send a preflight check asking for permission.
- Fixing CORS usually means changing the server’s headers, not the page’s code.
What CORS is
CORS stands for Cross-Origin Resource Sharing, and it is a standard that lets a server tell browsers which other websites may read its responses. Every web page has an origin, defined by three parts: the protocol, such as https, the domain, such as example.com, and the port, such as 443. Two pages have the same origin only when all three match, so a different subdomain or protocol counts as a different origin.
By default, the browser’s same-origin policy stops a page from reading data from a different origin. The page can still send the request in many cases, and it can load images, scripts, and stylesheets from other origins, but it cannot read the response of a data request unless the server grants permission through CORS headers. That distinction matters: the block is about reading the response, not about sending the request.
CORS headers are the server’s way of granting that permission. The most important is Access-Control-Allow-Origin, which names the origins allowed to read the response, or uses a wildcard to allow any origin. Other headers cover which methods, such as GET or POST, and which custom request headers are permitted. Our guide to REST APIs explains the kind of data requests CORS most often guards, and our guide to WebAssembly explains a technology that runs code in the browser under the same origin rules.
How CORS works
When a page makes a cross-origin data request, the browser adds an Origin header naming the page’s own origin. The server reads that header and decides whether to allow it. If it does, it includes an Access-Control-Allow-Origin header in the response, and the browser hands the response to the page. If the header is missing or names a different origin, the browser blocks the page from seeing the response and reports a CORS error, even though the server may have answered perfectly well.
Simple requests, such as a plain GET with no custom headers, go straight ahead as described. More complex requests trigger a preflight first: the browser sends a small OPTIONS request asking what the server allows. Only if the server’s reply grants permission does the browser send the real request. This two-step dance exists so that servers are never surprised by a request they did not agree to, especially one that might change data.
Credentials add a further wrinkle. A request that includes cookies or login details is treated more strictly: the server must name the exact requesting origin, not a wildcard, and must add a header allowing credentials. This matters because a page that could read your bank’s responses with your cookies attached would be a serious hole, and the stricter rule closes it.
It is worth remembering that CORS is enforced by the browser, not by the server and not by the network. A command-line tool, a mobile app, or a server-to-server request ignores CORS entirely, which is why the same request that fails in a browser works everywhere else. The protection exists only where it is needed: in the browser, where any website can run code on your machine.

Comparing CORS with other browser protections
CORS is one of several rules browsers use to keep websites from interfering with each other, and it is easy to confuse with its neighbours. Each rule guards a different boundary, and understanding which one has blocked you is half the job of fixing it.
The table below sets out the main contrasts.
| Aspect | CORS | Same-origin policy | Content Security Policy |
|---|---|---|---|
| What it controls | Reading responses from other origins | All cross-origin access by default | Which resources a page may load at all |
| Who sets the rule? | The server, via response headers | The browser, built in | The page itself, via a header or meta tag |
| Can it be relaxed? | Yes, the server can allow origins | Only through CORS or similar standards | Yes, by changing the policy |
| Typical error | Blocked by CORS policy | Blocked a frame with origin | Refused to load the script |
| Protects against | Reading data from sites you are logged into | Cross-site data theft generally | Injected scripts and stolen data |
The practical distinction is who fixes the problem. A CORS error is fixed on the server that serves the data, by adding the right headers. A Content Security Policy error is fixed on the page that set the policy. And a same-origin error usually means the code is trying something the browser will never allow, such as reading another site’s page directly, and needs a different design.
Where CORS is used
Public data services are the most common place to meet CORS. A weather service, a currency converter, or a public dataset that wants websites to use its data will set permissive CORS headers, often allowing any origin, so that any page can fetch and display the figures. Without those headers, the data would be usable only by servers, not by pages running in browsers.
Single-page applications meet CORS constantly. A modern web app often runs on one domain while its data service lives on another, and every data request crosses that boundary. The team must configure the data service to allow the app’s origin, or the app simply cannot load its data, which makes CORS a routine part of deploying such applications.
Third-party widgets and embeds rely on CORS too. A payment form, a map, or a comment system loaded from another company’s servers needs to exchange data with the page that hosts it, and CORS headers are what make that exchange possible while keeping it controlled.
CORS also matters for security teams. A deliberately strict CORS policy, allowing only named trusted origins and no credentials, limits the damage if an attacker finds a way to run code on a page. It is one layer among several, but it is the layer that stops a hostile page from quietly reading your private data from another site.
Strengths and limits
The greatest strength of CORS is that it lets the open web work at all. Without it, every site would be an island, unable to use data from anywhere else, and the rich mash-ups of maps, payments, and live data that define the modern web could not exist. With it, a server can choose exactly who may read its responses, opening up to the public or restricting access to its own front end.
It is also flexible in a useful way. A server can allow one origin, several origins, or all origins, and can set different rules for reading data and for changing it. That granularity means a public read-only service and a private banking service can use the same standard with very different policies.
The limits are real, though. CORS protects only data read through a browser, so it does nothing against a server or an app that talks directly to the service. Its error messages are famously cryptic, and the fix is often on a server the page author does not control. And a wildcard that allows any origin with credentials is a genuine security hole, so the standard must be configured with care.
CORS checklist
- Read the browser error carefully: a CORS error names the missing header and the blocked origin.
- Check whether the request is simple or needs a preflight, since the fix may be in the OPTIONS reply.
- Set Access-Control-Allow-Origin on the server that serves the data, never on the page.
- Name exact origins rather than a wildcard when the request carries cookies or login details.
- Allow only the methods and headers the app actually needs, not everything.
- Test with the browser’s developer tools open, so you can see the headers that were actually sent.
- Remember that command-line tools ignore CORS, so test in the browser where the problem lives.
- Keep the server’s CORS settings in version control, like any other configuration.
- Do not disable browser security or use a proxy to bypass CORS in production.
Frequently asked questions
What is CORS in simple terms?
CORS is the set of rules that decide when a web page may read data from a different website. The browser blocks the response unless the other site explicitly allows the page’s origin.
Why does my request work in a command-line tool but not in the browser?
Because CORS is enforced only by browsers. A command-line tool, an app, or a server makes the same request without the browser’s same-origin policy, so nothing blocks it.
What is a preflight request?
A preflight is a small OPTIONS request the browser sends before a complex cross-origin request, asking the server what methods and headers it allows. The real request is only sent if the server’s reply grants permission.
Can I fix a CORS error in my page’s code?
Usually not. The permission comes from the server’s response headers, so the fix belongs on the server that serves the data. Changing the page’s code rarely helps, unless the page is sending unnecessary custom headers.
Is allowing any origin with a wildcard safe?
For public, read-only data it is usually fine. For anything involving logins, cookies, or private data it is not, because any website could then read the responses with the user’s credentials attached.
Does CORS protect my server from attackers?
Only partly. CORS stops browsers from reading responses across origins, but it does not stop direct requests from servers, apps, or scripts. Real server security needs authentication and authorisation as well.
The bottom line
CORS explained in one line is this: the browser rule that lets a server decide which other websites may read its responses, blocking the rest by default.
It is a frequent source of frustration, but it exists for a good reason: without it, any website could read data from any other site you are logged into. When the error appears, the fix is almost always on the server that serves the data, in a header that names the origins allowed to read it.
This article is general information about how CORS works, not advice about configuring a web server or a security policy for a particular application.







