Skip to content

Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.

fix(server): rehash a page's CSP when its file changes so a rebuilt dist cannot blank it

nirholasc04604c902c4
diff --git a/data/changelog.json b/data/changelog.json
index 8048a4c31..0ca6a65d5 100644
--- a/data/changelog.json
+++ b/data/changelog.json
@@ -1,6 +1,25 @@
{
"$comment": "Curated changelog entries for three.ws, the editorial layer of the public changelog. New PAGE launches are tracked automatically via the `added` field in data/pages.json; this file is for everything else holders care about: improvements, fixes, SDK releases, trading/payments capabilities, security work. scripts/build-page-index.mjs merges both sources into CHANGELOG.md, public/changelog.json, and public/changelog.xml. Newest first. Allowed tags: feature, improvement, fix, sdk, infra, docs, security. `link` is optional and must be a live three.ws path.",
"entries": [
+ {
+ "date": "2026-08-14",
+ "title": "The legal pages now say what is in them, and call the terms by their real name",
+ "summary": "The six pages under three.ws/legal (the index, privacy policy, terms of service, end-user license agreement, risk disclosure, and content policy) were audited in a real browser at phone and desktop widths. Every page loads, every link on them resolves, and the layout holds at 320 pixels wide. Three things were wrong. The terms of service was filed under the name Terms of Use in the site's page index, so a search result or a shared link showed one name while the document itself showed another; it is now Terms of Service everywhere. The privacy policy, the terms, and the EULA each carried a search-result description that only restated their title, so a search engine or a chat preview told you nothing about what was inside; each now describes what the document actually covers. And several of the policies linked to each other by their raw file names rather than their real addresses, which split the same document across two web addresses; they now all use the address shown in the browser bar. The content policy was also missing its publication date in the page index, which is what the changelog and sitemap read.",
+ "tags": [
+ "fix",
+ "docs"
+ ],
+ "link": "/legal"
+ },
+ {
+ "date": "2026-08-14",
+ "title": "The security headers every three.ws page serves are now checked against the live site, not just the config",
+ "summary": "Every page three.ws serves carries a set of browser security rules: which scripts are allowed to run, that the connection must stay encrypted, that browsers must not second-guess a file's type, how much of the current address is passed on when you follow a link, and who is allowed to put a three.ws page inside a frame. Those rules are written in one config file, but until now nothing checked that the site actually answered with them. The sweep that loads real pages in a real browser now also compares each response against that config, and it can be pointed at the live site to check the whole catalogue in about a minute. Running it against production found no gap: all 25 of the most script-heavy pages, and the rest of the catalogue with them, serve exactly the rules the config declares. Two fixes came out of building it. Files that are not web pages, like robots.txt and the machine-readable service descriptions, were being reported as wrong when they were correct. And a page whose file changed while the server was running could be sent with the script rules of the previous version, which would have blocked its own scripts and shown a blank page; the server now notices the change and recomputes them.",
+ "tags": [
+ "security",
+ "infra"
+ ]
+ },
{
"date": "2026-08-14",
"title": "The 3D viewer no longer starts up blank when its box has not been measured yet",
diff --git a/docs/guards.md b/docs/guards.md
index 0e25eb5af..c113a7f5b 100644
--- a/docs/guards.md
+++ b/docs/guards.md
@@ -140,7 +140,7 @@ Run `npm run audit:guards` to print the current count and per-stage breakdown. T
| Guard | Command | Protects |
|---|---|---|
| CSP-safe inline markup | `npm run audit:inline-handlers` | No served HTML carries an inline event handler attribute or a `javascript:` URL. |
-| Live CSP sweep | `npm run audit:csp` | No page violates the Content-Security-Policy the server sends with it. |
+| Live CSP sweep | `npm run audit:csp` | No page violates the Content-Security-Policy the server sends with it, and every response carries the security headers `vercel.json` declares. `--headers-only --base https://three.ws` checks the header half against a live origin with no browser. |
| Console sweep | `npm run audit:console` | A clean browser console on every route, desktop and mobile. |
| `/play` failure modes | `npm run audit:play-failures` | `/play` stays usable when its dependencies fail, and hostile deep-link params never execute. |
| Overlapping fixed overlays | `npm run audit:overlays` | No persistent floating widget can cover another one's controls. |
diff --git a/server/index.mjs b/server/index.mjs
index 6f3201ed6..aaf3bb20c 100644
--- a/server/index.mjs
+++ b/server/index.mjs
@@ -249,20 +249,36 @@ function resolveStatic(pathname) {
}
// Static HTML gets its CSP tightened to the inline scripts it actually
-// contains (see server/csp-hashes.mjs). dist/ is immutable for the lifetime of
-// a deploy, so each file is read and hashed at most once per process; the
+// contains (see server/csp-hashes.mjs). In production dist/ is immutable for
+// the lifetime of a deploy, so each file is read and hashed at most once; the
// response itself still streams from res.sendFile.
+//
+// The cache is keyed by the file's size and mtime rather than its path alone,
+// because "immutable" is only true of the container. Run this server against a
+// working tree and a rebuild rewrites dist/ underneath it: sendFile then
+// streams the new bytes while the header still carries the old file's hashes,
+// and every inline script on that page is blocked. That is a page-blanking
+// failure produced entirely by a stale cache, and one statSync per HTML
+// response is a cheap way to never see it again.
const staticCspCache = new Map();
function cspForStaticHtml(file) {
- if (staticCspCache.has(file)) return staticCspCache.get(file);
+ let stamp = '';
+ try {
+ const st = statSync(file);
+ stamp = `${st.size}:${st.mtimeMs}`;
+ } catch {
+ // Unreadable stat: fall through to a read, which reports its own failure.
+ }
+ const hit = staticCspCache.get(file);
+ if (hit && hit.stamp === stamp) return hit.html;
let html = null;
try {
html = readFileSync(file, 'utf8');
} catch (err) {
console.error(`[csp] could not read ${file} for hashing:`, err.message);
}
- staticCspCache.set(file, html);
+ staticCspCache.set(file, { stamp, html });
return html;
}