# Cross-Origin Resource Sharing (CORS)

> A browser rule. It decides if a page on one site may read another site's data.

**Field:** Software Development  
**Category:** Security  
**Also known as:** CORS, CORS Error, Access-Control-Allow-Origin

## Think of it like

Think of it like a guest list. The server says which other sites may come in and ask for data.

## Definition

CORS is a browser rule that says if a page may read another site's data. By default, a browser stops a page from reading replies from another site. The server can relax that with a header that names the sites it trusts. If the header is missing or wrong, the browser shows a CORS error. It protects users. It does not protect the server from scripts or tools.

## Example

Jack's shop page calls his API on a different address. The browser blocks it until the API sends a header that names the shop.

## Example code

```http
HTTP/1.1 200 OK
Access-Control-Allow-Origin: https://shop.example.com
```

The API tells the browser that the shop may read this reply.

## Why it matters

Most web apps that call their own API from another address meet CORS on day one.

## Common mistake

Fixing a CORS error by allowing every site with a star. That lets any page read the reply, including with logins.

## Three principles

- **A browser rule.** Tools like curl ignore it.
- **The server decides.** With a header.
- **Name the sites.** Avoid the star.

## Related terms

- [HTTP Header](https://learn.benibix.com/term/infrastructure/http-header)
- [Application Programming Interface (API)](https://learn.benibix.com/term/development/api)
- [Cross-Site Request Forgery (CSRF)](https://learn.benibix.com/term/development/cross-site-request-forgery)
- [Web Browser](https://learn.benibix.com/term/general/web-browser)
- [Same-Origin Policy (SOP)](https://learn.benibix.com/term/development/same-origin-policy)

## Told apart from

- [Same-Origin Policy vs CORS](https://learn.benibix.com/compare/same-origin-policy-vs-cors): People think CORS is a lock that blocks requests, and it is the other way round. The same-origin policy is the lock: it stops one site from reading another site's replies. CORS is a header a server sends to open that lock for sites it names. So a CORS error means the server did not give your site a key.

---

Source: https://learn.benibix.com/term/development/cors
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
