Repository navigation
feat(cli): serve bundles as websites on their own origins (#2457) - #2590
Conversation
Code coverage overviewLanguages: Rust Rust / code-coverage/cargo-llvm-cov
View coverage of the 5 most impacted files.
ℹ️ Calculations represent line coverage. Results may change as calculations are updated. Updated |
There was a problem hiding this comment.
🔵 Needs a closer look
It introduces new per-bundle browser origins with a security-sensitive model (CSP, Sec-Fetch spend gating, DNS-rebinding host checks, streaming rewrite of untrusted content) that warrants final human review.
1 open issue
What changed in this PR
This PR extends decdn gateway so every content-addressed bundle is served as an isolated website at http://[<ns>.]<hash32>.localhost:<port>/, with no browser extension. Each bundle gets its own browser origin (via *.localhost loopback resolution + base32 host labels), so pages are isolated from one another and from the gateway. It adds a Content-Security-Policy, a Sec-Fetch-*-based spend gate (so pages pay without a token but cross-origin requests cannot), and streaming rewriting of decdn: URIs in HTML/CSS to root-relative /_decdn/<hash>… paths. The bare origin is largely unchanged, except a tokenless bundle request now redirects to the bundle's site.
Changes:
- New
sitemodule: base32Sitehost round-trip,may_spendSec-Fetch gate, CSP, and site content-typing. - New
rewritemodule: streaminglol_htmlHTML rewriter and a chunk-safe CSS byte scanner (69-byte holdback) that rewritedecdn:URIs. - Gateway routing:
Presentenum, site routing +/_decdn/handling,to_siteredirects,entry_link, and a refactoredStreamingbody that passes bytes through the optional rewrite.
| File | Description |
|---|---|
crates/cli/src/commands/gateway.rs |
Site routing, Present/Streaming, to_site/entry_link/redirect, rewrite-aware streaming, tokenless redirect. |
crates/cli/src/commands/gateway/site.rs |
New: Site host parse/encode, may_spend, CSP, content_type. |
crates/cli/src/commands/gateway/rewrite.rs |
New: streaming HTML/CSS decdn: URI rewriting. |
crates/cli/src/commands/gateway/site/tests.rs |
New: host round-trip, Sec-Fetch decision, CSP, content-type tests. |
crates/cli/src/commands/gateway/rewrite/tests.rs |
New: URI rewrite + chunk-boundary tests. |
crates/cli/src/commands/gateway/tests.rs |
New gateway-level site/redirect/download/cross-site tests. |
crates/cli/Cargo.toml, Cargo.toml, Cargo.lock |
Add data-encoding and lol_html 3 dependencies. |
CHANGELOG.md |
Document the site-serving feature. |
I verified the trickier logic: base32 label length/trailing-bit rejection, the CSS 69-byte holdback (URI_HEAD-1) correctly never misses a cross-chunk URI and stays linear, the prev-byte tracking across drains, the streaming Streaming state machine (tail emission on clean EOF, abort on funding error), Content-Length suppression when a rewrite is active, loopback-only --listen enforcement, and the Sec-Fetch spend gate against the tests. These all hold up. The only issue found is a minor documentation inconsistency on the Rewrite enum variants.
Review effort: Balanced
`decdn gateway` serves every bundle at `http://[<ns>.]<hash32>.localhost:<port>/`: `index.html` at the root, entries by path, a directory's `index.html`, HTML/CSS/JS as themselves under a CSP that confines the page to its origin. No extension is needed. `Sec-Fetch-*` lets the site's own requests, typed URLs and top-level navigation spend; other cross-origin requests get 403, and a request with no `Sec-Fetch-Site` needs the token. A site pays with the capability covering its host, falling back to `*`. `decdn:` URIs in HTML attributes, `<style>` and CSS are rewritten as they stream (lol_html) to root-relative `/_decdn/<hash>...`, so served pages name no gateway host or port. `/_decdn/` serves a page's subresources and redirects navigation to the other bundle's site. A tokenless bundle request on the gateway origin redirects to its site. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Co-Authored-By: Claude Opus 5.5 <[email protected]>
c748f37 to
6021ca8
Compare

Closes #2457.
What
decdn gatewayserves every bundle as a website athttp://[<ns>.]<hash32>.localhost:<port>/, with no browser extension./servesindex.html, or a file list with relative links./<path>serves that entry, and/<dir>/serves<dir>/index.html./<dir>redirects to<dir>/. HTML, CSS and JS are served as themselves. Every response carriesdefault-src 'self' 'unsafe-inline' 'unsafe-eval' data: blob:; connect-src 'self' http://<gateway>, so a page loads only from its own origin and can still reach/_delegateand/_capabilityon the gateway origin. Inline code is allowed because it ships in the same bundle as the page.site::may_spend): allowed forsame-origin, fornone(a typed URL or bookmark), and for top-level navigation from anywhere, at any path. Any other cross-origin request gets 403. A request with noSec-Fetch-Sitecomes from outside a browser and needs the token. Payment uses the capability that covers the site host, then falls back to*.rewrite):decdn:URIs in HTML URL attributes,styleattributes,<style>and CSS become/_decdn/<hash>…as the page streams. HTML goes throughlol_htmland CSS through a byte scanner that holds back a 69-byte tail between chunks, so a URI split across chunks is still caught. Served pages name no host or port./_decdn/on a site origin: a subresource request gets the bytes, paid by this site. A navigation to a bundle redirects to that bundle's own site origin. A navigation to a single blob downloads it as an attachment.<ns>goes left of the hash. That way a site's registrable domain is<hash32>.localhost, and no page can register a scope that covers other bundles./<hash>/[<path>]now redirects to the bundle's site at no cost, sohttp://127.0.0.1:8484/<hex>/opens a site in any browser.Dependencies
data-encoding, for base32. It was already in the lockfile through iroh.lol_html3, BSD-3-Clause. It pulls incssparser,selectorsandencoding_rs.cargo denylicenses and bans pass, and the crate-edges check passes.Testing
cargo nextest run -p decdn-cli: 942 passed. That includes new unit tests for base32 andHostparsing, theSec-Fetchdecision, the CSP, and the HTML/CSS rewrites at every chunk size. Gateway-level tests cover index rewriting, directories,/_decdn/subresources, redirects and downloads, cross-site refusal, the 404 for the API on a site origin, refusal of bad hosts, and that the bare origin still serves text.cargo docwith warnings denied, the no-inline-test check, and crate edges all pass.cargo denyadvisories fail only on RUSTSEC-2026-0384 (tokio 1.54.0) and RUSTSEC-2026-0385 (ctutils), and both are already onmain.*.localhost(an acceptance item in the issue).🤖 Generated with Claude Code