Repository navigation
Description
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'sindex.htmlentry when it has one, otherwise the file list.GET /<path>serves the entry at<path>; a path that names a directory serves itsindex.html.GET /_decdn/<hash>[/<path>][?ns=<id>]servesdecdn:<hash>[/<path>][?ns=<id>](see "Links to other content").Content-Typecomes 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. /_delegateand/_capabilityanswer 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: navigatewithSec-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-siteorcross-siterequest gets 403: subresources, iframes andfetchfrom other pages.a.localhostandb.localhostare same-site, so only same-origin passes. - A request without
Sec-Fetch-Sitecomes from outside a browser (curl, a local script) and needsx-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 rewriteshref,src,srcset,action,poster,data,meta http-equiv="refresh"content, and the CSS inside<style>andstyleattributes. - CSS (
text/cssentries and inline CSS) getsurl(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-Modeother thannavigate): 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):
302tohttp://<hash32>.localhost:<port>/<path>for a bundle, built from the request's ownHost, 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'sindex.htmlin 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 CSSurl(decdn:<blob>)load through/_decdn/; the served HTML and CSS contain nodecdn:URI and no host or port. - A link to
decdn:<other>/redirects to<other32>.localhoston navigation; the same path fetched as a subresource returns bytes. - Two bundles' pages cannot read each other's
localStorageor 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-Siteand without the token gets 403. - A site origin answers
/_delegateand/_capabilitywith 404, and the bare origin still answers them. - The bare origin still serves HTML, SVG and scripts as
text/plain. - A
Hostnaming a malformed*.localhostlabel, or any other name, gets 403. - Base32 round-trip,
Hostparsing, theSec-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
*.localhostto loopback; if it does not, the gateway docs say what Safari users need.
Metadata
Metadata
Assignees
Labels
Type
Fields
Priority
Projects
- StatusShow more project fieldsDone
Activity
[-]gateway: serve bundles as websites, one browser origin per bundle[/-][+]gateway: serve bundles as websites, one browser origin per bundle, no extension needed[/+]feat(cli): serve bundles as websites on their own origins (#2457)
feat(cli): serve bundles as websites on their own origins (#2457) (#2590