Reason about origins, sites and CORS boundaries
Quick answer
The same-origin policy limits access between documents or resources from different origins. An ordinary HTTP(S) origin consists of scheme, host and effective port. A site is a different concept used by cookie rules.
How it works
Paths do not change HTTP(S) origin; changes in scheme, host or effective port do. Some documents have opaque origins, serialized as null; that string is not a trustworthy identity. The same-origin policy does not prevent every cross-origin request or embedding. CORS is a server opt-in to browser read access and does not authenticate a requester or replace authorization. Cookie same-site decisions are not identical to origin equality. Examples compare URLs only, not browser navigation or CORS exchanges.
Local examples
Run in Node.js v22.16.0 as a CommonJS script. Actual ByteMind editor support is unverified.
(async () => {const a=new URL("https://app.example/list"),b=new URL("https://app.example:443/detail"),c=new URL("https://app.example:8443/list");console.log(a.origin===b.origin,a.origin===c.origin);})()Expected console output:
true falsePaths and explicit default ports do not change the origin, but a nondefault port does.
Run in Node.js v22.16.0 as a CommonJS script. Actual ByteMind editor support is unverified.
(async () => {console.log(new URL("data:text/plain,A").origin,new URL("data:text/plain,B").origin);})()Expected console output:
null nullBoth serializations are null; equality of the printed strings proves no shared principal.
Common mistakes
Do not use a domain suffix as a substitute for exact origin comparison, or assume CORS prevents all unwanted writes.
Practice
Classify URL pairs that differ by path, subdomain, scheme and nondefault port; explain why origin comparison does not prove authorization.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Reason about origins, sites and CORS boundaries — Knowledge Check
Apply the concept and reason about local example output.
Which URL change preserves the ordinary HTTPS origin?
What does CORS primarily control for browser fetches?
Why is the serialized opaque origin "null" not an identity?
What is the exact console output in Reason about origins, sites and CORS boundaries example 1?
(async () => {const a=new URL("https://app.example/list"),b=new URL("https://app.example:443/detail"),c=new URL("https://app.example:8443/list");console.log(a.origin===b.origin,a.origin===c.origin);})()What is the exact console output in Reason about origins, sites and CORS boundaries example 2?
(async () => {console.log(new URL("data:text/plain,A").origin,new URL("data:text/plain,B").origin);})()