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
CORS
Cross-Origin Resource Sharing is a set of HTTP headers that lets a server say which other origins are allowed to read its responses from JavaScript. Without those headers the browser fetches the file but refuses to hand the contents to the calling script.
Cross-Site Scripting
A flaw in which text supplied by a visitor ends up being executed as JavaScript on your page. Because the script runs on your origin, it inherits everything your page can see.
Browser Storage
The set of places a web page can keep data on the visitor's own machine — localStorage, sessionStorage, IndexedDB and cookies. It is private to that browser on that device, not a shared database.
iframe Sandbox
The sandbox attribute on an HTML iframe strips the embedded page of most privileges, then lets you hand back only the ones you name. It is how a host page displays untrusted content without giving it the run of the browser.
Subdomain
A subdomain is a label placed in front of a domain you already control, such as docs.acme.com or acme-pitch.99helpers.site. It is a separate address that can point somewhere completely different from its parent.
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 →