Security, Abuse & Privacy

Same-Origin Policy

Definition

An origin is the combination of scheme, host and port. Under the same-origin policy, a script may freely read the page, cookies, storage and responses of its own origin and is blocked from reading those of any other. https://app.99helpers.site and https://docs.99helpers.site are different origins, as are http and https versions of the same host, and the same host on port 443 and port 8080. The policy restricts reading, not loading: a page may still display an image, load a stylesheet, run a script or embed a frame from anywhere. What it cannot do is reach into that frame's document or read the body of a cross-origin fetch, unless the other side opts in with CORS headers.

Why It Matters

Without it, any page you opened could quietly read your webmail in another tab. That is the whole point, and it is why the policy is not configurable by users or by sites. The practical consequence for anyone publishing files is that origin boundaries are also data boundaries. Move a page from one subdomain to another and its localStorage does not follow, because storage is keyed by origin — a saved draft, a theme setting, a list of entries all appear to vanish. Two pages that need to share state must sit on the same origin or exchange messages deliberately with postMessage.

How It Works

The browser tags every document with its origin and checks that tag on each access. A cross-origin fetch is still sent, but the response body is withheld from the calling script unless Access-Control-Allow-Origin names the caller; this is exactly the hole CORS was designed to open in a controlled way. Frames are similar: a parent can set the src of a cross-origin iframe and can post messages into it with window.postMessage, but cannot read its DOM. Cookies follow a looser, older rule based on domain and path rather than full origin, which is why SameSite attributes exist as a separate control. Where two documents share a parent domain, both can set document.domain to that parent to relax the check — a legacy mechanism now deprecated and disabled by default in current browsers.

Real-World Example

A designer publishes a mood board at studio-board.99helpers.site and a separate notes page at studio-notes.99helpers.site, expecting the two to share a saved list held in the browser. They do not: different subdomains are different origins, so each page has its own storage. Putting both pages under one address, as 'board.html' and 'notes.html' on a single site, makes the shared list work with no code change at all.

Common Mistakes

  • Thinking the policy blocks requests — it blocks the script from reading the reply, while the request itself usually still reaches the server
  • Expecting localStorage to follow a page across subdomains — storage is per origin, so moving the page loses the data
  • Counting http and https versions of a host as one origin — the scheme is part of the origin, so they are separate
  • Reaching for document.domain to bridge two subdomains, a deprecated mechanism that modern browsers ignore

Related Terms

Put a file online in seconds

Drop in a document, an image, a page or a whole static website and share the link — free, with no build step and no server to set up.

Host a file free →