# Same-Origin Policy (SOP)

> A browser rule. It stops one site from reading what another site sends.

**Field:** Software Development  
**Category:** Security  
**Also known as:** Same Origin Policy, Web Origin, Origin (Web)

## Think of it like

Think of it like flats in one building. You can use your own rooms, but not walk into your neighbour's.

## Definition

The same-origin policy is a browser rule that keeps sites apart. An origin is made of three parts of an address. They are the scheme, the host and the port. A page can freely read data from its own origin. It cannot read replies from another origin unless that site says yes. This stops a bad site from reading your email or bank pages in another tab.

## Example

Jack is logged in to his bank. A bad page in another tab tries to fetch his balance, but the browser will not let it read the reply.

## Why it matters

It is the wall that keeps your open tabs from spying on each other. CORS is the door a site can open in it on purpose.

## Common mistake

Thinking two addresses on one domain share an origin. A switch from http to https, or a new port, makes a new origin.

## Three principles

- **Scheme, host, port.** All three must match.
- **Reading is blocked.** Other origins' replies stay hidden.
- **CORS opens it.** A site can allow named origins.

## Related terms

- [Cross-Origin Resource Sharing (CORS)](https://learn.benibix.com/term/development/cors)
- [Cross-Site Request Forgery (CSRF)](https://learn.benibix.com/term/development/cross-site-request-forgery)
- [Content Security Policy (CSP)](https://learn.benibix.com/term/development/content-security-policy)
- [Web Browser](https://learn.benibix.com/term/general/web-browser)
- [Uniform Resource Locator (URL)](https://learn.benibix.com/term/general/url)

## 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.

![Three panels. Same-origin policy: a page on bad.example asks to read a reply from bank.example and the answer is no, another origin, where an origin is the scheme, host and port. Content Security Policy: a header says script-src 'self', so /app.js from the site runs and a script from evil.example is blocked. Output encoding: a user types a script tag, the page writes it with &lt; and &gt; codes, and it is shown as text, never run.](https://learn.benibix.com/diagrams/dev2-browser-guards.svg)

---

Source: https://learn.benibix.com/term/development/same-origin-policy
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.
