Course contentsShow
← Security
Lesson 856 of 3,05218. Web Security - CSRF and Request ForgeryFree lesson

Origin Definition and Comparison

Learning how origins are defined (scheme, host, port) and how browsers determine if two URLs share the same origin.

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:

  1. Scheme (protocol): http or https
  2. Host (domain): example.com or www.example.com
  3. 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/page1 and https://example.com:443/page2 → Same origin ✓
  • http://example.com and https://example.com → Different origins (scheme differs)
  • https://example.com and https://api.example.com → Different origins (host differs)
  • https://example.com:443 and https://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.