Catalog My learning Blog
Browser Security Headers: CORS, CSP and Cookies Explained · Phase 1 · Lesson 3 · 7 min read

Same-Site vs Same-Origin: eTLD+1 and document.domain

On this page
  1. Learning Objective
  2. Concept Explanation
  3. Worked Example: Why document.domain Was Removed
  4. Real-World Examples
  5. Review Questions & Answers

Learning Objective

Distinguish a "site" from an "origin", explain how the Public Suffix List defines the site boundary, and describe why the legacy document.domain mechanism for relaxing the origin check has been disabled by default in modern browsers.

Concept Explanation

Alongside the origin, browsers use a coarser boundary called the site, and knowing which one a given feature uses is essential because the two are routinely confused. A site is the registrable domain, commonly written as eTLD+1, meaning the effective top-level domain plus one label. For https://app.example.com the eTLD is com, so the site is example.com and every subdomain of it belongs to the same site while remaining a separate origin. Some features additionally include the scheme, producing what the specifications call a schemeful same-site, so http://example.com and https://example.com are different sites under that stricter comparison.

The effective TLD is not simply the last label, which is why the Public Suffix List exists. If the rule were "everything after the final dot," then github.io would be an ordinary domain and every user's GitHub Pages site would be same-site with every other user's, which would let one user's page set cookies readable by all the others. The Public Suffix List, maintained by Mozilla and used by essentially every browser, enumerates the suffixes under which anyone may register a name, including github.io, co.uk, and thousands of others, so that user1.github.io and user2.github.io are correctly treated as separate sites.

The distinction between origin and site matters concretely because different mechanisms use different boundaries. CORS, storage partitioning, and the DOM access check are all origin-based. SameSite cookies, which this course covers in depth later, are site-based, which is exactly why a cookie marked SameSite=Strict is still sent on a request from app.example.com to api.example.com even though those are different origins. Treating the two as interchangeable produces both false confidence and mysterious bugs.

Historically, there was an escape hatch for the origin check: document.domain. Two pages sharing a registrable domain could each set document.domain to that shared suffix, for example both app.example.com and shop.example.com setting it to example.com, and once both had done so the browser would let them reach into each other's DOM directly as though same-origin. It was a convenience feature from the frames era, and it was always more dangerous than it looked, because it is a mutual opt-in with a very blunt granularity: setting document.domain does not open you up to one specific cooperating subdomain, it opens you up to every page on every subdomain that chooses to set the same value.

That is the flaw that killed it. If any single subdomain of example.com is compromised, hosts user-generated content, is a forgotten staging environment, or has been left dangling and claimed by someone else, then a page there can set document.domain and gain full scripting access to any other page that has also set it. Chrome disabled document.domain by default starting in Chrome 115 in July 2023; a site that still requires the old behavior must explicitly send the Origin-Agent-Cluster: ?0 response header to opt back in, and that opt-out is itself a transitional measure. The correct modern replacement is postMessage, which is the subject of a later lesson in this phase, because it is explicit, unidirectional, and lets each side validate exactly who it is talking to.

ConceptBoundaryExampleUsed by
Originscheme + host + porthttps://app.example.com:443CORS, DOM access, localStorage, permissions, service workers
Site (eTLD+1)registrable domainexample.com, covering all its subdomainsSameSite cookies, some storage partitioning schemes
Schemeful same-sitescheme + registrable domainhttps://example.com, excluding the http variantModern SameSite cookie enforcement
Public suffix entrya suffix anyone may register undergithub.io, co.uk, s3.amazonaws.comPreventing cross-tenant cookie and site confusion

Worked Example: Why document.domain Was Removed

The snippet below shows what the legacy mechanism did and what its blast radius was. The critical detail is the third block: the compromised subdomain does not need any cooperation from the victim page beyond the victim page having set document.domain at all.

Code
// Legacy mechanism, now disabled by default in Chrome 115+ (July 2023).

// On https://app.example.com  (the real application, in a frame or opener)
document.domain = 'example.com';

// On https://shop.example.com (the intended partner page)
document.domain = 'example.com';
// -> the two documents can now script each other's DOM directly

// On https://forgotten-staging.example.com  (compromised or dangling)
document.domain = 'example.com';
// -> this page ALSO gets full DOM access to app.example.com.
//    The opt-in was never pairwise; it is domain-wide.

// A site that still depends on the old behavior must opt back in explicitly:
//   Origin-Agent-Cluster: ?0
// The supported replacement is an explicit, validated channel:
targetWindow.postMessage({ type: 'cart:sync', items }, 'https://shop.example.com');
The origin boundary nested inside the wider site boundary, with the Public Suffix List cutting github.io into separate sites, and document.domain shown collapsing every subdomain into one trust pool including a compromised one.
The origin boundary nested inside the wider site boundary, with the Public Suffix List cutting github.io into separate sites, and document.domain shown collapsing every subdomain into one trust pool including a compromised one.

Real-World Examples

  • Chrome disabled the ability to set document.domain by default in Chrome 115, released in July 2023, after the Chrome team publicly documented that the feature undermines origin-based security by allowing any subdomain, including a compromised or attacker-controlled one, to gain scripting access to its siblings; sites needing the legacy behavior must now send the Origin-Agent-Cluster: ?0 header as an explicit and temporary opt-out.
  • The Public Suffix List exists precisely because of cross-tenant incidents on shared hosting suffixes: without an entry for a suffix such as github.io, every GitHub Pages site would be treated as same-site with every other, letting one user's page set domain-wide cookies read by all the others, which is why Mozilla maintains the list as shared infrastructure that browsers, certificate authorities, and cookie implementations all consume.
WarningNever treat a subdomain as trusted simply because it shares your registrable domain. Subdomain takeover of a dangling DNS record, a neglected staging host, or a subdomain serving user content are all common, and any mechanism that grants trust at the site level rather than the origin level, document.domain historically and loosely scoped cookies today, hands that compromised subdomain the keys to your main application.

Review Questions & Answers

Because the number of labels that constitute a public suffix varies. Under a naive two-label rule, co.uk would be treated as a registrable domain, making bbc.co.uk and hmrc.co.uk same-site with each other, and github.io would be treated as registrable, making every GitHub Pages user same-site with every other. The list enumerates the suffixes under which anybody may register a name so that browsers can compute the correct site boundary for cookies and same-site checks regardless of how many labels the suffix has.

Yes, it is sent. SameSite is evaluated against the site, meaning the registrable domain, not the origin. app.example.com and api.example.com are different origins but the same site, so the navigation is same-site and even the Strict value does not withhold the cookie. This is exactly why the origin-versus-site distinction matters in practice: a developer expecting origin-level isolation from SameSite will be surprised.

The opt-in was domain-wide rather than pairwise. When a page set document.domain to its registrable domain, it did not open itself to one specific named partner; it opened itself to any page on any subdomain of that domain that set the same value. Since organizations commonly have subdomains that are delegated to third parties, host user content, or are stale and takeoverable, the effective trust boundary silently expanded to include hosts the application team had no control over.

Because it inverts the trust model from implicit and broad to explicit and narrow. With postMessage, the sender names the exact target origin it is willing to deliver to and the receiver checks the exact origin each message came from, so the relationship is pairwise, auditable, and limited to the specific data placed in the message rather than full DOM access. Nothing is shared by default, and nothing a third subdomain does can insert it into the conversation.