Same-Origin Policy
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.com | Same origin? | Why |
|---|---|---|
| https://app.example.com/settings | Yes | Only the path differs. |
| http://app.example.com | No | The scheme differs. |
| https://api.example.com | No | The host differs. |
| https://app.example.com:8443 | No | The port differs. |
How the Same-Origin Policy Works in Practice
The browser checks the origin when code attempts a protected interaction.
- A page loads and its JavaScript runs in that page’s origin.
- The code tries to read data, access a window, or call an API at another origin.
- The browser compares the scheme, host, and port.
- 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.
| Feature | Same-origin policy | CORS |
|---|---|---|
| Purpose | Restricts protected cross-origin access by default. | Lets a server approve specific origins. |
| How it works | Built into browser security behavior. | Uses HTTP response headers and sometimes a preflight request. |
| Risk | Can 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.
on Emergent today

