Homeglossary

Same-Origin Policy

Same-origin policy is a browser security rule that limits how a web page or script can read data and interact with another origin. An origin is the combination of a URL's scheme, host, and port. The policy protects private browser-based data while allowing carefully configured cross-origin access when an application genuinely needs it.

Build secure web apps with Emergent.

What Is the Same-Origin Policy?

Same-origin policy is a browser security rule that limits how a web page or script can read data and interact with another origin. An origin is a URL’s scheme, host, and port. Browsers use this rule to isolate sites from one another, especially when a user is signed in.

How Browsers Decide Whether Two URLs Share an Origin

All three origin parts must match. A different path does not create a new origin.

URL compared with https://app.example.comSame origin?Why
https://app.example.com/settingsYesOnly the path differs.
http://app.example.comNoThe scheme differs.
https://api.example.comNoThe host differs.
https://app.example.com:8443NoThe port differs.

How the Same-Origin Policy Works in Practice

The browser checks the origin when code attempts a protected interaction.

  1. A page loads and its JavaScript runs in that page’s origin.
  2. The code tries to read data, access a window, or call an API at another origin.
  3. The browser compares the scheme, host, and port.
  4. It permits same-origin access, or blocks protected cross-origin reads unless an approved mechanism allows them.

What the Same-Origin Policy Protects

The policy helps prevent a hostile site from treating another open site as its own.

  • It blocks direct cross-origin access to another page’s DOM, or page structure.
  • It isolates browser storage such as localStorage and sessionStorage by origin.
  • It prevents a malicious site from reading an authenticated bank API response without permission.
  • It restricts privileged cross-window access. Cookie rules also use domain, path, and security attributes, rather than SOP alone.

Same-Origin Policy Benefits

SOP provides a secure default for web applications.

  • It limits private-data theft from users signed in to other sites.
  • It reduces unauthorized browser-based reading of API responses.
  • It separates application storage between unrelated origins.
  • It makes explicit permission necessary for cross-origin features.

Same-Origin Policy Limits and Common Misconceptions

SOP is important, but it is not a complete security program.

  • It may allow a request to be sent while preventing the requesting script from reading the response.
  • It does not replace server-side authorization or CSRF protections.
  • It does not protect an API that intentionally returns sensitive data to an untrusted origin.
  • It is a browser control, so server-to-server requests are not governed by it.

Same-Origin Policy vs. CORS

CORS is a controlled exception to the browser’s default restriction.

FeatureSame-origin policyCORS
PurposeRestricts protected cross-origin access by default.Lets a server approve specific origins.
How it worksBuilt into browser security behavior.Uses HTTP response headers and sometimes a preflight request.
RiskCan require extra integration setup.Overly broad allowed origins can expose response data.

Building Secure Cross-Origin Features with Emergent

When planning app design and development, identify every frontend and API origin early. Teams building with Emergent’s AI web app builder should use narrowly scoped CORS rules, enforce authorization on the server, and test third-party integrations before deployment. Build secure web apps with Emergent.

Start Building
on Emergent today
Start Building