CORS Explained: Why Your Browser Won’t Read the Response
A web server can send data successfully while your browser refuses to let a page read it. CORS is the permission mechanism that helps decide whether code from another web origin may use that response.
CORS stands for Cross-Origin Resource Sharing. It lets a server tell browsers which origins may read particular responses across an otherwise restricted boundary.
A server is the computer or service responding to web requests. Here, the code asking for data usually runs inside a page in your browser.
Why Did the Browser Block That Request?
An origin is more specific than a website name
An origin combines three parts of a web address: the connection scheme, such as http or https; the host name, such as shop.example.com; and the port number.
The scheme identifies how the browser connects, and the host identifies the server by name. A port is a numbered destination for communicating with a service; browsers use a default when the address leaves it out.
Compared with https://shop.example.com, these addresses differ:
| Address | Same origin? | Reason |
|---|---|---|
https://shop.example.com/orders | Yes | A different page path doesn't change the origin |
https://api.example.com | No | The host is different |
http://shop.example.com | No | The scheme is different |
https://shop.example.com:8443 | No | The port differs from the default HTTPS port, 443 |
The browser's same-origin policy restricts how code from one origin interacts with another. Mozilla's explanation distinguishes reading another origin's data from actions such as following links or submitting forms, which often remain possible.
That boundary helps prevent a malicious page from simply reading private information from another site you're signed in to.
The responding service gives the permission
Suppose a shop page needs product information from https://api.example.com. That service could allow the shop's origin to read its response by sending a header like this:
Access-Control-Allow-Origin: https://shop.example.com
A header is a named piece of information sent alongside a web request or response. This one tells the browser which origin may read the response; putting the same text into the requesting page doesn't grant permission.
- Run a test server or a home lab without giving up desk space.
- Start right away with 16GB of memory and a 500GB SSD already inside.
- Drive two 4K screens when it doubles as an everyday desktop.
Mozilla's header reference explains that the value can name one allowed origin. For responses intended for any origin without credentials, the server can use *, meaning any origin.
Credentials are information used to establish access. A sign-in cookie, for example, is a small record stored by your browser that can identify your logged-in visit.
When a request is configured to send credentials, reading the response requires an explicit allowed origin and the server's Access-Control-Allow-Credentials: true header; the wildcard isn't valid for that access.
Browser cookie restrictions still apply, even when the CORS headers permit sharing.
How One Tweet Started Retweeting Itself
Sometimes the browser asks before sending
For certain requests, the browser first sends a preflight: a preliminary request asking whether the intended request type and headers are allowed. It uses OPTIONS, a web request method used here to ask about those permissions.
If the preflight fails, the browser won't send the intended request. If it succeeds, the browser can proceed and then check the actual response's CORS headers too.
Other requests don't need a preflight and may already have reached the server before the browser blocks the page from reading the reply. Mozilla's CORS guide explains both paths.
A CORS error therefore doesn't prove that the server received nothing or made no change.
- Learn to find the flaws in a web app before someone else does.
- Understand injection, broken logins and logic bugs well enough to fix them.
- Build the skills that web security jobs ask for.
CORS doesn't decide who owns an account
For private information, the server still needs authentication, which checks who is making a request, and authorization, which checks what that identity may do. CORS describes browser sharing permission, not a user's right to retrieve a customer's private orders.
Scripts running outside a browser aren't governed by the browser's CORS checks. Microsoft's CORS guidance explains that enabling CORS relaxes a browser restriction rather than adding protection to the service.
It also isn't a complete defense against cross-site request forgery, or CSRF. That attack tricks a signed-in user's browser into making an unwanted request, as described by OWASP; the attacker may not need to read the response at all.
Read a CORS error as a clue
Check the page's exact origin, the responding server's headers, and whether the failed step was a preflight or the actual response. An ordinary server error can also lack the headers the browser expected.
For a service you control, allow the origins that need the data and test the intended requests in a real browser. Public data and private signed-in responses have different sharing needs, so give each an appropriate policy.
HTTP: The Requests and Replies That Make the Web Work

Headers: The Hidden Instructions Traveling With Your Data

Web Servers: What Happens After the Browser Asks

QUOTE:
"Amateurs hack systems, professionals hack people."

