Why the Same-Origin Policy Permits Cross-Site Embedding but Blocks Data Reading
The Same-Origin Policy relies on a strict combination of protocol, host, and port to isolate web documents from one another. Understanding this tuple reveals why modern browsers permit cross-site embedding but block cross-site data reading.
By Wei Zhang
Share this story
In short
- The Same-Origin Policy isolates web documents based on a strict match of protocol, host, and port.
- If any of the three variables differ, the browser blocks scripts from reading the target's Document Object Model.
- The policy is asymmetrical: it blocks cross-origin reading but permits cross-origin embedding of images and scripts.
The exact moment a web application's security is determined happens in milliseconds within the browser's network stack, right before a script attempts to read the Document Object Model (DOM). The browser evaluates three specific variables: the protocol, the host, and the port. If this triple matches the origin of the target data, access is granted. If even one variable differs, the browser enforces a hard boundary. This mechanism is the reason a malicious script in one tab cannot quietly read the session cookies of a banking application open in another.[1][2]
Known formally as the Same-Origin Policy (SOP), this concept was first introduced in 1995 with the release of Netscape Navigator 2.02. Over the subsequent three decades, it has remained the fundamental currency of the web's security model. As the WHATWG HTML standard states, "Two actors in the web platform that share an origin are assumed to trust each other and to have the same authority."[1][5]
The boundary is strictly defined by the tuple. For example, a document loaded from an HTTP connection cannot read data from an HTTPS connection on the same domain because the protocol differs. Similarly, a script running on port 80 cannot access data on port 81 due to a port mismatch, even if the host and protocol are identical.[2][3]
However, the marketing language surrounding web security often presents the Same-Origin Policy as an impenetrable vault. In reality, the architecture is highly porous by design. The policy distinguishes sharply between sending information and receiving it, creating a read/write asymmetry that allows the modern web to function.[2][9]
Browsers routinely permit cross-origin embedding. An HTML document can load images via the image tag, execute scripts, and apply stylesheets from entirely different domains. As the Mozilla Developer Network (MDN) documentation notes, "Cross-origin embedding is typically allowed... Cross-origin reads are typically disallowed."[2][3]
Without this "allow sending" and "allow embedding" exception, the web as a hyperlinked ecosystem would break. If origins could only link to and load resources from themselves, content delivery networks (CDNs) and distributed media would be impossible. The policy specifically targets read access to prevent data exfiltration, rather than isolating the document entirely.[5][8]
This porous nature means developers must actively manage the boundary. When a browser sends an HTTP request from one origin to another, it automatically includes any relevant authentication cookies. If the Same-Origin Policy did not block the reading of the response, a malicious site could easily parse a user's private inbox or financial dashboard.[2][8]
Historically, the implementation of the protocol-host-port triple has not been uniform. Internet Explorer, for instance, famously did not include the port number when calculating the origin tuple. This meant that a script running on port 80 could access data on port 8080 of the same host, a quirk that persisted in enterprise environments for years and required specific workarounds.[8]
To bypass the strict restrictions of the triple when necessary, developers historically relied on the document.domain setter. This allowed subdomains to synchronously access each other's DOMs by truncating their hostnames to a common superdomain, effectively rewriting the host variable of the tuple on the fly.[1][2]
Today, the document.domain approach is actively deprecated. The WHATWG specification warns developers to "Avoid using the document.domain setter. It undermines the security protections provided by the same-origin policy." Modern browsers are phasing out this capability because it breaks the isolation required for shared hosting environments.[1]
Instead, the industry has standardized on Cross-Origin Resource Sharing (CORS). CORS operates via HTTP headers, allowing a server to explicitly declare which external origins are permitted to read its responses. The Access-Control-Allow-Origin header acts as a cryptographic permission slip, relaxing the strict tuple check only when cryptographically verified.[3][4]
As web applications have evolved into complex, multi-threaded software, the basic Same-Origin Policy has proven insufficient against advanced hardware vulnerabilities like Spectre. This has led to the introduction of Cross-Origin Opener Policy (COOP) and Cross-Origin Embedder Policy (COEP).[1][4]
These newer headers enforce "cross-origin isolation," a state where the browser guarantees that a document does not share a memory process with cross-origin content. According to the OWASP HTTP Headers Cheat Sheet, COOP "allows you to ensure a top-level document does not share a browsing context group with cross-origin documents."[4]
The distinction between "Same-Origin" and "Same-Site" also confuses many implementations. While an origin requires an exact match of the protocol, host, and port, a "site" is defined only by the scheme and the registrable domain. Thus, two different subdomains are cross-origin but same-site, a distinction that dictates how modern cookies are routed.[1][2]
Ultimately, the protocol-host-port triple remains the bedrock of web security. While new headers and isolation modes continue to layer on top of it, the fundamental check—evaluating those three variables before granting DOM access—is the single mechanism keeping the open web from collapsing into a massive data breach.[1][9]
Jargon, explained
- Tuple
- A mathematical term for a finite ordered list of elements; in web security, it refers to the three-part combination of protocol, host, and port.
- Document Object Model (DOM)
- The programming interface that represents an HTML document as a tree of objects, allowing scripts to read and manipulate the page content.
- Cross-Origin Resource Sharing (CORS)
- An HTTP-header based mechanism that allows a server to indicate any origins other than its own from which a browser should permit loading resources.
- Cross-Origin Opener Policy (COOP)
- A security header that ensures a top-level document does not share a browsing context group with cross-origin documents, isolating it from attacks like Spectre.
Common questions
What happens if the port number is not specified in a URL?
If a port is not explicitly specified, the browser assumes the default port for the given protocol (e.g., port 80 for HTTP and port 443 for HTTPS) when calculating the origin tuple.
Does the Same-Origin Policy prevent cross-site linking?
No. The policy specifically restricts read access to data across origins. It intentionally permits cross-origin writes (like links and form submissions) and cross-origin embedding (like images and scripts).
How do modern applications bypass the Same-Origin Policy?
Developers use Cross-Origin Resource Sharing (CORS), a mechanism where the server sends specific HTTP headers to explicitly grant read access to designated external origins.
Competing readings
Web Standards Authors
Focuses on strict specification compliance and deprecating legacy workarounds.
Organizations like the W3C and WHATWG view the Same-Origin Policy as a rigid, immutable baseline. They actively push to deprecate historical workarounds like the document.domain setter, arguing that such loopholes undermine the fundamental security model. Their goal is to force developers toward explicit, secure channels like postMessage and CORS, ensuring that any relaxation of the boundary is cryptographically verifiable and intentional.
Security Researchers
Views the policy as a porous boundary requiring constant vigilance against read/write asymmetry exploits.
Security organizations like OWASP emphasize that the Same-Origin Policy is not a silver bullet. Because the policy permits cross-origin embedding and form submissions, researchers constantly hunt for vulnerabilities where this read/write asymmetry can be exploited. They point out that attacks like Cross-Site Request Forgery (CSRF) or Cross-Site Scripting (XSS) exist precisely because the browser allows sending data across origins by default, requiring developers to implement secondary defenses like CSRF tokens.
Application Developers
Prioritizes functionality and seamless cross-domain resource sharing via CORS.
For developers building complex, distributed applications, the strict tuple check is often a friction point. They rely heavily on CORS and Content Delivery Networks (CDNs) to bypass the default restrictions, viewing the policy as a necessary hurdle rather than a feature. When integrating third-party APIs or microservices hosted on different subdomains, developers must carefully orchestrate HTTP headers to ensure functionality without accidentally exposing sensitive user data.
- Web Standards Authors
- Focuses on strict specification compliance and deprecating legacy workarounds.
- Security Researchers
- Views the policy as a porous boundary requiring constant vigilance against read/write asymmetry exploits.
- Application Developers
- Prioritizes functionality and seamless cross-domain resource sharing via CORS.
Perspectives this story doesn't cover
- Legacy Enterprise System Administrators
Sources
[1]WHATWGWeb Standards AuthorsHTML Standard: Origins
Read on WHATWG →
[2]MDN Web DocsWeb Standards AuthorsSame-origin policy - Security
Read on MDN Web Docs →
[3]web.devApplication DevelopersSame-origin policy
Read on web.dev →
[4]OWASPSecurity ResearchersHTTP Headers - OWASP Cheat Sheet Series
Read on OWASP →
[5]WikipediaSame-origin policy
Read on Wikipedia →
[6]PentesterLabSecurity ResearchersSame-Origin Policy (SOP): Definition & Security Context
Read on PentesterLab →
[7]GeeksforGeeksApplication DevelopersWhat is Same Origin Policy (SOP)?
Read on GeeksforGeeks →
[8]PortSwiggerSecurity ResearchersSame-origin policy
Read on PortSwigger →
[9]Factlen Editorial TeamSynthesis by Factlen editorial team
Read on Factlen Editorial Team →
More in Technology
See all →Digital Typography
How Zero-Width Joiners Assemble Complex Emojis Without Exhausting the Unicode Standard
5 sources
Seller Automation
Amazon Opens Seller Operations to Outside AI Agents with Claude Plugin
4 sources
Platform Policy
Meta Expands Test Limiting Facebook Page Link Posts to Two Per Month Unless Subscribed to 'Meta One'
6 sources
Ad Tech Infrastructure
The Second-Price Auction: How Real-Time Bidding Selects an Ad in 100 Milliseconds
6 sources
Comments
Every angle. Every day.
Get Technology stories with full source coverage and perspective breakdowns, free every day.




