diff --git a/README.md b/README.md index e151536..1f53297 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ client components initialized. The Content Security Policy uses a fresh request nonce for Next's generated scripts and the initial theme script. HTML renders per request; immutable JavaScript and static assets keep their existing caching. Keep the request and -response policies consistent, and verify a real theme toggle and mounted scene +response policies consistent, and verify a real theme toggle and rendered specimen plates when changing scripts, headers or rendering. Analytics uses the shared CodesWhat Public Websites PostHog project through diff --git a/ROADMAP.md b/ROADMAP.md index 51c054e..8f19d48 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -14,18 +14,16 @@ Links, `llms.txt` and `.well-known/security.txt`. ## Open -- [ ] Evaluate the next `posthog-js` upgrade against the public SDK capture - contract tests. CI runs both `test:posthog` and the production response - check, `test:posthog:browser`. - [ ] #57, the public-repo security baseline, is partly done. The remaining items are tracked privately. + +## Parked: coherent 3D brand-asset set + - [ ] Decide whether three, react-three-fiber, drei and rapier stay. They're only imported under `frontend/components/studio/`, which backs the dev-only `/studio/*` capture routes (they 404 in production), but they're still in `frontend/package.json` and the lockfile, so they show up in audits. -## Parked: coherent 3D brand-asset set - The Catalogue uses hand-drawn pixel sprites, so a 3D-minted icon set isn't on the critical path. `frontend/scripts/capture-assets.mjs` and the `/studio/*` routes still work. What exists today: `exports/coin/` (light and dark spin WebP) diff --git a/frontend/README-VERCEL.md b/frontend/README-VERCEL.md index afd5a53..530d39d 100644 --- a/frontend/README-VERCEL.md +++ b/frontend/README-VERCEL.md @@ -32,7 +32,9 @@ then runs `test:posthog:browser` against an isolated local production server and it requires a production build. `npm run og` regenerates the share cards in `public/og*` with playwright-core -and the locally installed Google Chrome; it isn't part of the build. +and the locally installed Google Chrome; it isn't part of the build. After +`npm ci`, provision Chrome once with `npx playwright-core install chrome` before +running `npm run og`. Installing `playwright-core` alone doesn't install Chrome. ## Rendering and security headers diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 1154cae..c52a7e3 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -13,7 +13,7 @@ "@react-three/fiber": "^9.8.2", "@react-three/rapier": "^2.2.0", "next": "^16.4.3", - "posthog-js": "1.443.0", + "posthog-js": "1.447.0", "react": "19.3.1", "react-dom": "19.3.1", "three": "^0.187.0" @@ -982,29 +982,30 @@ } }, "node_modules/@posthog/browser-common": { - "version": "0.10.2", - "resolved": "https://registry.npmjs.org/@posthog/browser-common/-/browser-common-0.10.2.tgz", - "integrity": "sha512-ieHSMmY4xG+HfkMTrT9yZoG0NMBWyA4aXMFPCuOOV+xRe706+zoPuwqmNHXv7LGXfi6CvOv4qksEoPNWfP359Q==", + "version": "0.10.7", + "resolved": "https://registry.npmjs.org/@posthog/browser-common/-/browser-common-0.10.7.tgz", + "integrity": "sha512-1V2SBu7gxVbroZk49YsCM++K9qy3qcrOaylemjkkTPvACgAGwm0Y/AkJN2eRZO1YME0FnagF6QKBaXmq3o0e8g==", "license": "MIT", "dependencies": { - "@posthog/core": "^1.61.2", - "@posthog/types": "^1.418.0", + "@posthog/core": "^1.63.2", + "@posthog/types": "^1.420.0", + "dompurify": "^3.4.13", "preact": "^10.29.3" } }, "node_modules/@posthog/core": { - "version": "1.61.2", - "resolved": "https://registry.npmjs.org/@posthog/core/-/core-1.61.2.tgz", - "integrity": "sha512-l3b6Dc2NmItwmyu6ot7K2jtStQOAQjZw/PB/gpZwk2W6SBCbvPg6YJzReSBSQLuok19ridbfVNk70a5hgoGX2Q==", + "version": "1.64.0", + "resolved": "https://registry.npmjs.org/@posthog/core/-/core-1.64.0.tgz", + "integrity": "sha512-D284VHRgqw2AilzNOmpI4a2rmKrC+4b1xB1Z+p3edwlA1gGKpHxM0PwfB3Jz+TBxXP1uU3ceJ4dwYinzOkqscg==", "license": "MIT", "dependencies": { - "@posthog/types": "^1.418.0" + "@posthog/types": "^1.421.0" } }, "node_modules/@posthog/types": { - "version": "1.418.0", - "resolved": "https://registry.npmjs.org/@posthog/types/-/types-1.418.0.tgz", - "integrity": "sha512-WqDXUWH1R8OilBp2PfDpQIRZSCs3QyOnw7H3YK7lvZLCMIsOqSZAKJrrqYWt4f7FvnVCACRuNGCC0HKh3J/HWw==", + "version": "1.421.0", + "resolved": "https://registry.npmjs.org/@posthog/types/-/types-1.421.0.tgz", + "integrity": "sha512-KP34CqgRYYyp3wU77OixL0URb2ildKM+QxBOXtQ4YYaa1ARTt3looxkn/w8gwKo6gWZg2VW/DgSoqAW4XeDAPQ==", "license": "MIT" }, "node_modules/@react-three/drei": { @@ -2170,14 +2171,14 @@ } }, "node_modules/posthog-js": { - "version": "1.443.0", - "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.443.0.tgz", - "integrity": "sha512-PpfvtZ4cj5uDhXrILlfoV8/Qva+ZBntp75Px+HR7kcKHMSdHIsBVpj5rdMLLgH94APsoP13ZMz8bXO4kwrrZ+Q==", + "version": "1.447.0", + "resolved": "https://registry.npmjs.org/posthog-js/-/posthog-js-1.447.0.tgz", + "integrity": "sha512-9zWnDVipzFU3NU+BikJXOMJPL/iFH9SYuvwp4zbUXbvoJCZrd21KSuI3HGD4HKIriCeiySC26Jh35F+QuWtEew==", "license": "(Apache-2.0 AND MIT)", "dependencies": { - "@posthog/browser-common": "^0.10.2", - "@posthog/core": "^1.61.2", - "@posthog/types": "^1.418.0", + "@posthog/browser-common": "^0.10.7", + "@posthog/core": "^1.64.0", + "@posthog/types": "^1.421.0", "core-js": "^3.49.0", "dompurify": "^3.4.13", "fflate": "^0.4.8", diff --git a/frontend/package.json b/frontend/package.json index b0a8557..d56f587 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -35,7 +35,7 @@ "@react-three/fiber": "^9.8.2", "@react-three/rapier": "^2.2.0", "next": "^16.4.3", - "posthog-js": "1.443.0", + "posthog-js": "1.447.0", "react": "19.3.1", "react-dom": "19.3.1", "three": "^0.187.0" diff --git a/frontend/test/posthog-browser.test.mjs b/frontend/test/posthog-browser.test.mjs index b29f36c..c389d30 100644 --- a/frontend/test/posthog-browser.test.mjs +++ b/frontend/test/posthog-browser.test.mjs @@ -55,6 +55,28 @@ after(async () => { }); }); +function protectsHtml(cacheControl) { + const unquoted = cacheControl.replace(/"(?:[^"\\]|\\.)*"/g, '""'); + return /(?:^|,)\s*(?:private|no-store)\s*(?:,|$)/i.test(unquoted); +} + +test("HTML cache protection requires an unqualified directive", () => { + for (const header of ["private", "no-store", "max-age=0, private", "private, no-store"]) { + assert.equal(protectsHtml(header), true, header); + } + for (const header of [ + "", + "public, max-age=600", + 'public, private="Set-Cookie"', + 'private="Set-Cookie, no-store, X-Other"', + 'x-note="private", public', + 'public, x-note="a\\"b, no-store, c"', + "no-store=true", + ]) { + assert.equal(protectsHtml(header), false, header); + } +}); + test("production browser response keeps PostHog on the exact proxy", async () => { const response = await fetch(`${baseUrl}/?query-secret=should-not-leave`, { signal: AbortSignal.timeout(15_000), @@ -66,9 +88,8 @@ test("production browser response keeps PostHog on the exact proxy", async () => assert.match(csp, /script-src[^;]*https:\/\/e\.codeswhat\.com/); assert.match(csp, /connect-src[^;]*https:\/\/e\.codeswhat\.com/); assert.doesNotMatch(csp, /\*\.posthog\.com|https:\/\/(app|us)\.posthog\.com/); - assert.match( - response.headers.get("cache-control") ?? "", - /\b(private|no-store)\b/, + assert.ok( + protectsHtml(response.headers.get("cache-control") ?? ""), "HTML reflects request data (Next.js flight payload), which is only safe if the page isn't shared-cached", ); // Next.js inlines router state, including the request's own query, in diff --git a/frontend/test/posthog-source.test.mjs b/frontend/test/posthog-source.test.mjs index ff6a210..fbfd840 100644 --- a/frontend/test/posthog-source.test.mjs +++ b/frontend/test/posthog-source.test.mjs @@ -15,7 +15,9 @@ test("PostHog is initialized only by instrumentation-client", async () => { test("telemetry dependencies use the audited exact PostHog version", async () => { const packageJson = JSON.parse(await read("package.json")); - assert.equal(packageJson.dependencies["posthog-js"], "1.443.0"); + assert.equal(packageJson.dependencies["posthog-js"], "1.447.0"); + const installedSdk = JSON.parse(await read("node_modules/posthog-js/package.json")); + assert.equal(installedSdk.version, packageJson.dependencies["posthog-js"]); assert.equal(packageJson.dependencies["@vercel/analytics"], undefined); assert.equal(packageJson.dependencies["@vercel/speed-insights"], undefined); }); diff --git a/frontend/test/site-browser.test.mjs b/frontend/test/site-browser.test.mjs index 6aee033..94c2372 100644 --- a/frontend/test/site-browser.test.mjs +++ b/frontend/test/site-browser.test.mjs @@ -4,6 +4,7 @@ import { existsSync } from "node:fs"; import { after, before, test } from "node:test"; import { fileURLToPath } from "node:url"; import { chromium, firefox, webkit } from "playwright-core"; +import { SPECIMEN_EXAMPLES } from "../lib/specimen-examples.ts"; const root = fileURLToPath(new URL("..", import.meta.url)); const nextBin = fileURLToPath(new URL("../node_modules/next/dist/bin/next", import.meta.url)); @@ -260,6 +261,7 @@ test("the primary navigation marks Support only while its page is current", { await nav.getByRole("link", { name: "Specimens" }).click(); await page.waitForURL(`${baseUrl}/#specimens`); assert.equal(await nav.locator('[aria-current="page"]').count(), 0); + assert.equal(await support.evaluate((link) => getComputedStyle(link).textDecorationLine), "none"); await support.click(); await page.waitForURL(`${baseUrl}/support`); await page.waitForFunction( @@ -341,8 +343,13 @@ test("field notes show attributed README excerpts and leave unsourced examples a const excerpt = await row.locator("pre code").textContent(); const lines = excerpt.split("\n"); assert.equal(lines[0], firstLine, slug); + assert.equal(excerpt, SPECIMEN_EXAMPLES[slug].excerpt, `${slug}: complete rendered excerpt`); assert.ok(lines.length >= 3 && lines.length <= 6, `${slug}: a short excerpt`); const source = row.getByRole("link", { name: "Read the full README" }); + const sourceUrl = await source.getAttribute("href"); + assert.equal(sourceUrl, SPECIMEN_EXAMPLES[slug].sourceUrl, `${slug}: exact source URL`); + const [, start, end] = sourceUrl.match(/#L(\d+)-L(\d+)$/); + assert.equal(Number(end) - Number(start) + 1, lines.length, `${slug}: source range length`); assert.match( await source.getAttribute("href"), new RegExp(