Home
← All questions

Same-Origin Policy and origin definition | Web Fundamentals

MediumPremiumWeb Fundamentals

Asked at Google · Meta · Microsoft

Web Fundamentals interview practice: Define origin, what the SOP restricts, and exceptions (CORS, postMessage, images).

Answer

An origin = scheme + host + port (https://app.example.com:443).

Same-Origin Policy (SOP) limits how documents/scripts from one origin interact with resources from another:

ActionCross-origin?
Embed <img src>Allowed (no JS read of pixels without CORS)
<script src>Allowed (runs in page context — supply-chain risk)
fetch() + read bodyBlocked unless CORS allows
Access iframe.contentWindowBlocked unless same origin
localStorageOrigin-scoped, isolated

Escape hatches: CORS, postMessage with origin checks, JSONP (legacy), WebSockets (different model — server validates Origin header).

Premium question

Unlock the full model answer with Mentoxis Premium.

Unlock with Premium