liveBook · Manning

Origin

As explained in Vanilla Web

A web security identity defined by a scheme, host, and port that determines the boundary for same-origin access.

A web app may call its own API and still need data from another service. Before making that request, check the origin: the combination of URL scheme, host, and port. Browsers use that combination as a security boundary; changing any one part makes a different origin. section 2.1.2 section 2.1.3

Do not confuse an origin with other URL boundaries:

  • A path, query, or fragment identifies or locates content without being part of the origin. section 2.1.2
  • A site is based on the registrable domain and ignores subdomains. Addresses can therefore be on the same site but have different origins. section 2.1.2
  • An app’s scope combines an origin with a path; it is not another name for the origin. section 2.1.2

Read the boundary from a URL

For https://firt.dev/notes/pwa#android, the origin is https://firt.dev:443: HTTPS supplies the implicit port 443. The path and fragment are not included. For http://localhost:8080/webapp, the origin is http://localhost:8080; its explicit port matters. section 2.1.2

The Same-Origin Policy lets a page freely access resources from its exact origin, rather than freely reading another origin’s data. When JavaScript must access a cross-origin API, the server can declare allowed origins through CORS response headers. This is a server decision, not a restriction the requesting page can switch off. section 2.1.3

Table 2.1 Security specification overview
Mechanism What it enforces / solves When to use How it’s set Gotchas / notes

SOP

Isolates origins so one site can’t freely read/modify another site’s data.

Always, it’s the browser’s default isolation model.

Built-in (no config).

Core to web security; use postMessage or server-mediated APIs for safe cross-origin comms.

CORS

Allows controlled cross-origin reads/writes from JS (fetch/XHR).

Exposing APIs/assets to other origins.

HTTP response headers: Access-Control-Allow-Origin, -Methods, -Headers, -Credentials.

Must be set on the server. Wildcard * + credentials is not allowed.

CSP

Restricts where scripts/styles/images/etc. can load from; mitigates XSS/code injection.

Any app loading third-party content or handling user input.

HTTP header Content-Security-Policy (or <meta http-equiv>).

Prefer nonces/hashes over host allowlists; test in report-only mode first.

HTTPS (TLS)

Encrypts transport; required for powerful APIs and secure cookies.

Always in production (and most dev flows).

Server certificate + redirect HTTP→HTTPS; use HSTS where appropriate (a spec that forces your domain into HTTPS for every request).

Needed for Service Workers, Geolocation, etc.; localhost is treated as secure for dev.

Permissions

User-mediated access to camera, mic, location, notifications, etc.

Any feature gated by user consent.

JS APIs trigger prompts; query via navigator.permissions.

Request lazily with context; handle denial gracefully; users can revoke anytime.

Compare the browser’s built-in same-origin isolation with server-configured CORS. The table also notes that a wildcard allowed origin cannot be combined with credentials. section 2.1.3

How Vanilla Web covers it

How deep it goes
Defines origin through URL components and works through two decomposed URLs, then explains browser isolation and server-controlled cross-origin access.
Examples
Uses HTTPS and localhost URLs with implicit and explicit ports, plus a security comparison table.
What it assumes
Introduces the relevant URL components directly before using them to explain browser security rules.
What you can do after
Apply it by identifying a URL’s origin and deciding when cross-origin API access requires server-configured CORS.
How it connects
Connects URL schemes, hosts, and ports to the Same-Origin Policy, CORS, sites, and web app scope.

Also explained in

Compare how 4 books explain origin →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Vanilla Web. The section links point to the parts of the book it draws on.