Skip to content

gateway: serve bundles as websites, one browser origin per bundle, no extension needed #2457

Closed

Description

@alpergundogdu

Summary

Serve a bundle as a website through decdn gateway (#2456): index.html for the bundle root, HTML as HTML, and every bundle on its own browser origin. A static site published as a bundle then opens in any browser, with no extension, and every byte is verified against its BLAKE3 hash and paid like any other decdn: content. A site links to other content with plain decdn: URIs, and the gateway rewrites them as it serves the page, so a published bundle never names a gateway host or port.

Today the gateway serves /<hash>/ as an HTML file list and every text/*, HTML, SVG, XML and script type as text/plain. That is deliberate: every bundle shares the one origin 127.0.0.1:8484, and active content there could read every other bundle, share cookies and storage with them, and request any decdn: URL under whatever capability covers that origin.

Design

One origin per bundle

Serve a bundle at http://<hash32>.localhost:<port>/, where <hash32> is the manifest's BLAKE3 hash in RFC 4648 base32, lowercase, unpadded (52 characters). The hex form is 64 characters, past the 63-character DNS label limit. Browsers resolve *.localhost names to loopback, so each bundle is its own origin and the browser isolates its storage, cookies and scripts from every other bundle and from the gateway. This is gateway presentation only: the decdn: URI (#2449) keeps its hex hash.

Routing on a site origin

  • GET / serves the bundle's index.html entry when it has one, otherwise the file list.
  • GET /<path> serves the entry at <path>; a path that names a directory serves its index.html.
  • GET /_decdn/<hash>[/<path>][?ns=<id>] serves decdn:<hash>[/<path>][?ns=<id>] (see "Links to other content").
  • Content-Type comes from the entry name (mime_guess). HTML, SVG and scripts are served as themselves here, and only here.
  • Every response carries Content-Security-Policy: default-src 'self', so a page loads only from its own origin.
  • /_delegate and /_capability answer 404. Only the bare origin answers the management API.

Access without the extension

A site origin takes no gateway token. The browser's Sec-Fetch-* headers, which it sends to every localhost origin and which page scripts cannot set, decide what a request may spend:

  • Sec-Fetch-Site: same-origin: allowed (the site loading its own files and /_decdn/ content).
  • Sec-Fetch-Site: none: allowed (typed URL, bookmark).
  • Sec-Fetch-Mode: navigate with Sec-Fetch-Dest: document, from any site and to any path: allowed, so a link from another page opens the site, deep links included. Each such spend is one page load the user sees.
  • Every other same-site or cross-site request gets 403: subresources, iframes and fetch from other pages. a.localhost and b.localhost are same-site, so only same-origin passes.
  • A request without Sec-Fetch-Site comes from outside a browser (curl, a local script) and needs x-decdn-token, as on the bare origin.

Payment

The gateway takes the page host from Host (no x-decdn-host on site origins) and applies the scope rules unchanged: a capability scoped to <hash32>.localhost first, then *. The site's own page may register a capability scoped to its own origin through the bare origin's /_capability (it can never claim another host), so a published site can fund its own readers. Without one, the token holder's * capability pays.

Links to other content

A site references content outside its own bundle with canonical decdn: URIs (<img src="decdn:<hash>">, <a href="decdn:<hash>/">). Links within the bundle stay relative and are served untouched. As it serves a page, the gateway rewrites every decdn: URI to a root-relative path on the page's own origin:

decdn:<hash>[/<path>][?ns=<id>]   ->   /_decdn/<hash>[/<path>][?ns=<id>]

The served page names no host, port or gateway, so the same bundle works on any port and under any later site domain.

  • HTML streams through lol_html, which keeps the gateway's in-order streaming of verified bytes. It rewrites href, src, srcset, action, poster, data, meta http-equiv="refresh" content, and the CSS inside <style> and style attributes.
  • CSS (text/css entries and inline CSS) gets url(decdn:...) and @import "decdn:..." rewritten by a small scanner.
  • A rewritten response is sent chunked, since its length changes.
  • URLs a script builds at runtime are not rewritten. Scripts use relative paths or /_decdn/<hash>, and /_decdn/ is a stable, documented path.

/_decdn/ answers by request kind:

  • Subresources (Sec-Fetch-Mode other than navigate): the gateway serves the bytes on this origin, typed by entry name, active types included. The page's author chose that hash, so a script pinned by hash is as safe here as one with Subresource Integrity, and the request passes the CSP and the same-origin rule and is paid by this site's capability.
  • Navigations (links, iframes): 302 to http://<hash32>.localhost:<port>/<path> for a bundle, built from the request's own Host, so another site's HTML never runs on this origin. A blob, which has no site, is served as a download (Content-Disposition: attachment).

Host check

Accept <hash32>.localhost:<port> for a well-formed base32 hash besides today's loopback names; keep refusing everything else (DNS rebinding).

The bare origin stays as it is

127.0.0.1:<port> keeps GET /<hash>[/<path>] with active types served as text, token-gated content requests, and /_delegate and /_capability. The browser extension (decdn/browser-demo) keeps serving single decdn: files through it. Sites need no extension.

Out of scope

  • Mutable names. A bundle hash is immutable, so a new version of a site is a new hash; a stable name that points at the latest bundle is protocol design and goes through spec discipline first.
  • A configurable site domain for a gateway off loopback. The root-relative rewrite keeps served pages independent of it.
  • Rewriting URLs that scripts build at runtime.

Acceptance

  • http://<hash32>.localhost:<port>/ serves a test site bundle's index.html in a browser without the extension, and its relative CSS, script and image references load from the same bundle.
  • A page's <img src="decdn:<blob>"> and CSS url(decdn:<blob>) load through /_decdn/; the served HTML and CSS contain no decdn: URI and no host or port.
  • A link to decdn:<other>/ redirects to <other32>.localhost on navigation; the same path fetched as a subresource returns bytes.
  • Two bundles' pages cannot read each other's localStorage or cookies (separate origins).
  • A cross-site <img> or iframe pointing at a site origin gets 403; a cross-site top-level navigation to any path succeeds.
  • A site-origin request without Sec-Fetch-Site and without the token gets 403.
  • A site origin answers /_delegate and /_capability with 404, and the bare origin still answers them.
  • The bare origin still serves HTML, SVG and scripts as text/plain.
  • A Host naming a malformed *.localhost label, or any other name, gets 403.
  • Base32 round-trip, Host parsing, the Sec-Fetch-* decision, and the HTML and CSS rewrites are unit tested; the CSP header is present on every site response.
  • Check whether Safari on macOS resolves *.localhost to loopback; if it does not, the gateway docs say what Safari users need.

Activity

  1. added
    kind:feature
    kind:security
    area:cli
    on Oct 14, 2026
  2. changed the title [-]gateway: serve bundles as websites, one browser origin per bundle[/-] [+]gateway: serve bundles as websites, one browser origin per bundle, no extension needed[/+] on Oct 23, 2026
  3. moved this from Backlog to In progress in deCDNon Oct 23, 2026
  4. moved this from In progress to Done in deCDNon Oct 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:clikind:featurekind:security

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    • Status
      Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions