Skip to content
BENIBIX Learn

Same-Origin Policy (SOP)

Development🔐 SecurityDefences

Also known as Same Origin Policy, Web Origin, Origin (Web)

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

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.

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.

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.
The left panel: one site cannot read the reply the bank sends.

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.

Key takeaways

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

Compare