Same-Origin Policy Explained
The Same-Origin Policy is the most important security boundary in the browser. It prevents a malicious website from reading data from another website.
What Is an Origin?
An origin is defined by the combination of protocol, host, and port:
https://example.com:443andhttps://example.com:443- Same originhttps://example.comandhttp://example.com- Different (protocol)https://example.comandhttps://api.example.com- Different (host)
What SOP Restricts
- DOM access across origins
- XMLHttpRequest and fetch responses
- Cookie and storage access
What SOP Does NOT Restrict
- Embedding images, scripts, stylesheets
- Form submissions
- Navigating the top-level window