Kayavak / The Web Frontend / FE·12 The Web Platform / Deeper
Deeper · The Web Frontend
The Web Platform
The questions the chapter doesn't stop for: why this exists, the model to keep in your head, what changes when an assumption does, how sure we are of each claim, and what's still open. Read it after the chapter; back to the chapter.
Why does this exist?
Early web pages were documents. When Netscape added JavaScript in 1995, pages became programs, and a new problem appeared at once: a script from one site, running in your browser next to your bank's page, could read it. Netscape Navigator 2.0 introduced the same-origin policy in response: a page may freely use resources only from its own origin. Nearly every rule in this chapter descends from that decision to run code from strangers side by side.
The platform kept growing: storage (cookies in 1994, then localStorage and IndexedDB), background work, cameras, payments. Each new capability had to fit the same model of origins and permissions. After the Spectre attacks of 2018 showed that code in one page could read memory in the same process through CPU side channels, browsers went further: Chrome shipped site isolation, putting each site in its own process, and new rules such as cross-origin isolation gate the most powerful features.
The mental model
Try it yourself first: write your own model in the Mental Model Explorer, then compare.
The browser is an operating system for untrusted programs. Origins play the role of users: each gets its own storage and permissions, and the browser is the kernel that keeps them apart.
| Question | Answer |
|---|---|
| What is it? | A runtime that loads documents and scripts from many origins and gives them controlled capabilities |
| Problem it solves | Running anyone's code safely on your machine, at the click of a link |
| Parts | URLs and origins, browsing contexts (tabs, iframes), the document lifecycle, storage per origin, web APIs, permissions |
| How it works | Every access is checked against the caller's origin; powerful APIs need a secure context and often user consent |
| Assumptions | Origins are trustworthy boundaries; the browser itself is correct |
| When they change | Hardware side channels (Spectre) break in-process isolation, hence process-per-site |
| Where it fails | Cookies are scoped by site, not origin, so subdomains can interfere; users can be tricked into granting permissions |
| Related ideas | OS processes and isolation (Foundations, ch08); CORS and cookies (ch19); frontend security (ch28) |
What if?
What if there were no same-origin policy?
Reason it through, then open
Any page you visited could fetch your email, your bank statements and your company's intranet, using your logged-in cookies, and read the answers. Every site would effectively have your identity everywhere. The web would only be usable with one tab, or with no logins at all.
What if origins ignored the port?
Reason it through, then open
Two unrelated services on one host (a development server on :3000 and an admin console on :8080) could read each other's storage and responses. Origins include the scheme, host and port precisely so that different services don't share an identity. Cookies, older than origins, do ignore the port, which is one of their known weaknesses.
Where the boundary is
| Aspect | Origin | Site |
|---|---|---|
| Made of | Scheme + host + port | Scheme + registrable domain (eTLD+1) |
https://a.shop.example:443 vs https://b.shop.example |
Different origins | Same site |
| Governs | Same-origin policy, storage, most web APIs | Cookies' SameSite, site isolation processes |
| Confused because | "Cross-origin" and "cross-site" sound alike and differ for subdomains |
How sure are we?
| Claim | How it's known | Where from |
|---|---|---|
| Same-origin policy introduced with JavaScript in Navigator 2.0 (1995–96) | Historical | Netscape's documentation of the time |
| Site isolation was enabled widely in Chrome in 2018 after Spectre | Historical | Chromium's announcements |
| Origins fully isolate pages | Model | Within one process, side channels can leak; hence site isolation |
| The registrable domain comes from the Public Suffix List | Convention | A list maintained by Mozilla and contributors, not a protocol rule |
Still open
How to give web apps more power (file systems, USB, Bluetooth) without making the web less safe is argued between browser vendors, who disagree openly; some APIs ship only in Chromium. Third-party cookies and cross-site tracking are in the middle of a long, unsettled transition.
What would change your mind? If a capability could be shown safe without origin checks (for example, because it reveals nothing about other sites), it wouldn't need the model. Few have been.
Recall
What three parts make an origin?
Scheme, host and port.
How does a site differ from an origin?
A site is scheme plus registrable domain (eTLD+1), so subdomains of one domain are one site but different origins.
What did the same-origin policy prevent?
Pages reading other sites' responses and data using the visitor's credentials.
Why did browsers move to a process per site?
Spectre showed code in one process could read memory across origins via CPU side channels.
Reflect
Be honest with yourself; this stays in your browser. Anything you can't tick yet is what to revisit.