The Same-Origin Policy: What Actually Works
The browser rule that stops scripts on one site from reading data from another site.
On this page
Where most projects go wrong
The usual mistakes:
- Wildcard CORS on authenticated endpoints
- Disabling security to make development easier
- Proxies that bypass origin checks carelessly
- Assuming errors are bugs in the browser
What good looks like instead
- Understand origins before debugging CORS errors
- Use CORS headers deliberately on APIs
- Keep credentials out of cross-origin requests unless needed
- Test cross-origin behavior early
- Document which origins are allowed
Why it matters
It is the foundation of web security, and most cross-origin errors developers meet come from it working correctly.
The specs that matter
| Measure | Figure |
|---|---|
| Origin | combines scheme, host and port |
| Restrictions | scripts cannot read responses from other origins by default |
| Exceptions | images, scripts and styles can be embedded without reading |
| CORS | lets servers opt in to sharing responses |
Knowing when to hand it over
Tip: Bring in help when APIs must be used by other domains.
Where this comes from
- MDN Web Docs — Same-origin policy
- OWASP — HTML5 Security Cheat Sheet
The figures and practices above come from the sources listed.
Working on something like this?
We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.
Where to go next
Spotted something wrong? Report an error on this page. We correct on the page and say what changed.