Origin Definition and Comparison
You'll learn: How browsers define an "origin" and decide when two URLs share the same origin—a critical security boundary for web requests.
What Is an Origin?
An origin is a unique combination of three components in a URL:
- Scheme (protocol):
httporhttps - Host (domain):
example.comorwww.example.com - Port:
80,443,8080, etc. (with defaults per scheme)
Think of an origin like a secure building address: scheme is the security protocol (guest vs. employee entrance), host is the street address, and port is the specific door number. All three must match for two locations to be considered "the same place."
How Browsers Compare Origins
When a browser evaluates whether two URLs share the same origin, it checks if all three components are identical:
https://example.com:443/page1andhttps://example.com:443/page2→ Same origin ✓http://example.comandhttps://example.com→ Different origins (scheme differs)https://example.comandhttps://api.example.com→ Different origins (host differs)https://example.com:443andhttps://example.com:8080→ Different origins (port differs)
Note: Default ports (80 for HTTP, 443 for HTTPS) are often implicit. https://example.com equals https://example.com:443.
Why This Matters for CSRF
The Same-Origin Policy uses origin comparison to determine whether a script can read responses from another site. However, browsers do send cookies to the target origin regardless of where the request originates—this is exactly what makes CSRF attacks possible.
Understanding origin boundaries helps you recognize when cross-origin requests might pose security risks.
Key Takeaway: An origin is defined by scheme + host + port; two URLs share the same origin only if all three match exactly, creating a fundamental security boundary in browsers.