As I understand it, the Same-origin policy (SOP) basically prevents a script in a web page from obtaining or sending information from/to a different domain.
I understand that this is important to prevent a page from grabbing private data and passing it along somewhere else. For example, without the SOP, I could write a public web page with a script that:
- reads information from an intranet site only accessible to the client browser (but not to my server) and
- sends it back to my server using
XMLHttpRequest
(orfetch()
)
However, when the SOP was introduced (JavaScript 1.0, in Netscape Navigator 2.0 in 1995), there was no way to send a request from JavaScript. XMLHttpRequest was only introduced in Internet Explorer 5.0 in March 1999, and fetch()
even later.
So - what attacks did the SOP prevent without a way to send a request? Obviously, without SOP a script could grab all kinds of potentially private data, but where is the risk if the script has no way to pass it on?
The Client-Side JavaScript Guide V1.3 (from 1999, hence before XMLHttpRequest) just says:
JavaScript automatically prevents scripts on one server from accessing properties of documents on a different server. This restriction prevents scripts from fetching private information such as directory structures or user session history.
However, it does not explain why "fetching private information" is a problem if there is no way for the script to exfiltrate it.