Storage and browser security

What is an origin

Identify an origin from its scheme, host, and port and understand why paths do not create separate origins.

8 minute lesson

~~~

An origin is the combination of a URL’s scheme, host, and port. All three parts must match.

For this URL:

https://shop.example.com:8443/account?tab=orders

the origin is:

https://shop.example.com:8443

The path, query string, and fragment do not participate. These pages therefore share an origin:

https://example.com/account
https://example.com/shop

These do not:

http://example.com
https://example.com
https://app.example.com
https://example.com:8443

Browsers use this boundary for DOM access, network response access, and storage. A subdomain is not automatically trusted merely because it belongs to the same parent domain.

Open the Console on any page and run:

location.origin

Then compare it with the origin of an API, iframe, or asset the page uses. Asking “do scheme, host, and port match?” is the first step in explaining many CORS and cross-window errors.

Lesson completed

Take this course offline

Get every free book and course as PDF and EPUB files.

Get the download library →