Skip to content
Web Design & Development

The Same-Origin Policy: What Actually Works

The browser rule that stops scripts on one site from reading data from another site.

MediaScaleUp Editorial Team 2 min read 12 views
The Same-Origin Policy: What Actually Works

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
What to do and what to avoid with the same-origin policy, side by side
Good practice against the usual mistakes, from the sources listed below.

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

Published figures for The Same-Origin Policy
MeasureFigure
Origincombines scheme, host and port
Restrictionsscripts cannot read responses from other origins by default
Exceptionsimages, scripts and styles can be embedded without reading
CORSlets 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

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.

All services

The work behind this article, and what it costs.

MediaScaleUp Editorial Team

Articles here are researched, written and checked by the MediaScaleUp studio team before they are published, and dated when they are reviewed.

Keep reading

More in Web Design & Development