Course contentsShow
← Security
Lesson 1056 of 3,05222. Web Security - Client-Side and SPA SecurityFree lesson

Origin Components: Scheme, Host, and Port

Learn how origins are calculated from URL components and when two URLs are considered same-origin versus cross-origin.

Origin Components: Scheme, Host, and Port

You'll learn exactly how browsers determine if two URLs belong to the same "origin" — the foundation of web security boundaries.

What Is an Origin?

In web security, an origin is like your home address — it uniquely identifies where content comes from. An origin consists of three parts extracted from a URL:

  1. Scheme (protocol): http or https
  2. Host (domain): example.com or api.example.com
  3. Port: 80, 443, 8080, etc.

These three components together define the security boundary. If any of them differ between two URLs, they're considered cross-origin.

Same-Origin Examples

Both URLs below share the same origin:

  • https://example.com/page1
  • https://example.com/api/data

Origin: https://example.com:443 (port 443 is default for HTTPS)

Cross-Origin Examples

Each of these is different origin from https://example.com:

  • http://example.com — different scheme (http vs https)
  • https://api.example.com — different host (subdomain matters!)
  • https://example.com:8080 — different port (8080 vs default 443)
  • https://example.org — different host (different domain)

Why This Matters

The Same-Origin Policy uses these components to decide whether JavaScript from one page can access data from another. Two pages are either "same team" (same origin) or "strangers" (cross-origin). The path (/page1 vs /api/data) and query strings don't affect origin — only scheme, host, and port matter.

Think of it like building security: scheme is the building type (secure vs unsecure), host is the street address, and port is the specific entrance. All three must match for full access.

Key Takeaway: An origin is defined by exactly three components: scheme, host, and port. If any differ, two URLs are cross-origin and face security restrictions.