From 1d4f7dade7c4407fcfdaa1639ab89a2aa1f3bc3a Mon Sep 17 00:00:00 2001 From: scttbnsn <80784472+scttbnsn@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:44:10 -0500 Subject: [PATCH 1/4] ci(security): scan dev PRs with CodeQL and add fast-check property tests for the privacy envelope --- .github/workflows/codeql.yml | 7 ++ frontend/package-lock.json | 41 +++++++ frontend/package.json | 3 +- .../test/posthog-privacy.property.test.ts | 107 ++++++++++++++++++ frontend/test/workflow.test.mjs | 7 +- 5 files changed, 163 insertions(+), 2 deletions(-) create mode 100644 frontend/test/posthog-privacy.property.test.ts diff --git a/.github/workflows/codeql.yml b/.github/workflows/codeql.yml index 06387b7..ec183a6 100644 --- a/.github/workflows/codeql.yml +++ b/.github/workflows/codeql.yml @@ -7,12 +7,19 @@ on: pull_request: branches: - main + - dev schedule: - cron: "23 4 * * 1" permissions: contents: read +# A newer push to the same PR supersedes the running scan; pushes to main and the +# weekly run are keyed by their own ref and are never cancelled. +concurrency: + group: codeql-${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: analyze: runs-on: ubuntu-latest diff --git a/frontend/package-lock.json b/frontend/package-lock.json index 9aa259b..dd00fcc 100644 --- a/frontend/package-lock.json +++ b/frontend/package-lock.json @@ -24,6 +24,7 @@ "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", "@types/three": "^0.187.0", + "fast-check": "4.11.0", "lefthook": "^2.2.2", "playwright-core": "^1.65.1", "typescript": "^7.0.2" @@ -1763,6 +1764,29 @@ "integrity": "sha512-m6WCKt/erDXcw+70IJXnG7M3awwQPAsZvJGX5zY7beBqpELw6RDGkYVU0W43AFxye4pDZ5i2Lbyc/NNGqwjUVQ==", "license": "Apache-2.0" }, + "node_modules/fast-check": { + "version": "4.11.0", + "resolved": "https://registry.npmjs.org/fast-check/-/fast-check-4.11.0.tgz", + "integrity": "sha512-V4Uc238rhQOdQlc+Gz7JG6SGBtrWnWL8d/6RyiBeCMcNKMhF6DZ0KkAVHJSyNV5r4lA0PmIpZ6iRpTVoz4qjoA==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ], + "license": "MIT", + "dependencies": { + "pure-rand": "^8.0.0" + }, + "engines": { + "node": ">=12.17.0" + } + }, "node_modules/fflate": { "version": "0.8.3", "resolved": "https://registry.npmjs.org/fflate/-/fflate-0.8.3.tgz", @@ -2240,6 +2264,23 @@ "lie": "^3.0.2" } }, + "node_modules/pure-rand": { + "version": "8.4.2", + "resolved": "https://registry.npmjs.org/pure-rand/-/pure-rand-8.4.2.tgz", + "integrity": "sha512-vvuOGgcuPJAirlHvuQw1TrOiw7ptaIXXmIbNuiNOY6lNGJJH49PQ1Kj4nd783nPdQhQdicgOjVI2yI/9BD6/Ng==", + "dev": true, + "funding": [ + { + "type": "individual", + "url": "https://github.com/sponsors/dubzzz" + }, + { + "type": "opencollective", + "url": "https://opencollective.com/fast-check" + } + ], + "license": "MIT" + }, "node_modules/query-selector-shadow-dom": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/query-selector-shadow-dom/-/query-selector-shadow-dom-1.0.1.tgz", diff --git a/frontend/package.json b/frontend/package.json index 865b829..1e7b861 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -22,7 +22,7 @@ "test:support": "node --experimental-strip-types --test test/support.test.ts test/sitemap.test.ts test/csp-adapter.test.mjs", "test:subscribe": "node --experimental-strip-types --import ./test/resolve-next-server.mjs --test test/subscribe-turnstile.test.ts", "test:scene": "node --experimental-strip-types --test test/scene.test.mjs test/mylar-pixels.test.ts", - "test:posthog": "node --experimental-strip-types --test test/posthog.test.ts test/posthog-source.test.mjs test/posthog-instrumentation.test.mjs", + "test:posthog": "node --experimental-strip-types --test test/posthog.test.ts test/posthog-source.test.mjs test/posthog-instrumentation.test.mjs test/posthog-privacy.property.test.ts", "test:posthog:browser": "node --test test/posthog-browser.test.mjs", "test:browser": "node --test test/site-browser.test.mjs", "test:browser:all": "BROWSER_ENGINE=chromium npm run test:browser && BROWSER_ENGINE=firefox npm run test:browser && BROWSER_ENGINE=webkit npm run test:browser", @@ -48,6 +48,7 @@ "@types/react": "^19.3.0", "@types/react-dom": "^19.3.0", "@types/three": "^0.187.0", + "fast-check": "4.11.0", "lefthook": "^2.2.2", "playwright-core": "^1.65.1", "typescript": "^7.0.2" diff --git a/frontend/test/posthog-privacy.property.test.ts b/frontend/test/posthog-privacy.property.test.ts new file mode 100644 index 0000000..c4cc123 --- /dev/null +++ b/frontend/test/posthog-privacy.property.test.ts @@ -0,0 +1,107 @@ +import assert from "node:assert/strict"; +import { test } from "node:test"; +import fc from "fast-check"; +import { ALLOWED_ROUTES, sanitizeEvent, sanitizeRoute } from "../lib/posthog-privacy.ts"; + +// Property tests for the analytics privacy envelope. sanitizeEvent receives +// whatever the browser SDK (or a tampered client) hands it, so these generate +// hostile input and check the invariants that must hold for every event. + +const EVENTS = [ + "$pageview", + "$pageleave", + "cta activated", + "$web_vitals", + "newsletter submitted", + "client error", +]; +const OUTPUT_KEYS = new Set([ + "token", + "$cookieless_mode", + "$process_person_profile", + "schema_version", + "site", + "surface", + "path", + "$raw_user_agent", + "$host", + "distinct_id", + "$referring_domain", + "utm_source", + "utm_medium", + "utm_campaign", + "$current_url", + "$pathname", + "cta_id", + "placement", + "result", + "error_class", + "error_kind", + "error_name", + "$web_vitals_CLS_value", + "$web_vitals_FCP_value", + "$web_vitals_INP_value", + "$web_vitals_LCP_value", +]); +const SECRET = "leak-canary@example.com"; +const ROUTES = new Set([...ALLOWED_ROUTES, "/_other"]); + +const anything = fc.anything({ withNullPrototype: true, withBigInt: true }); +const looseValue = fc.oneof(anything, fc.string(), fc.constant(SECRET), fc.double()); +const base = { + token: "phc_property_fixture", + $cookieless_mode: true, + $process_person_profile: false, + $raw_user_agent: "Mozilla/5.0 (Property Fixture)", + $host: "codeswhat.com", +}; +// Extra properties are arbitrary, but never override the envelope fields that +// make an event valid, so most generated events reach the branch under test. +const properties = fc + .dictionary(fc.oneof(fc.string(), fc.constantFrom(...OUTPUT_KEYS)), looseValue) + .map((extra) => ({ ...extra, ...base })); +const event = fc.record({ + event: fc.oneof(fc.constantFrom(...EVENTS), fc.string(), anything), + properties: fc.oneof(properties, anything), + timestamp: fc.oneof(fc.date({ noInvalidDate: false }), anything), + uuid: anything, +}); + +test("sanitizeEvent never throws and only emits allowlisted keys with primitive values", () => { + fc.assert( + fc.property(fc.oneof(event, anything), (input) => { + const result = sanitizeEvent(input); + if (result === null) return; + assert.ok(EVENTS.includes(result.event)); + for (const [key, value] of Object.entries(result.properties)) { + assert.ok(OUTPUT_KEYS.has(key), `unexpected key ${key}`); + assert.ok( + ["boolean", "number", "string"].includes(typeof value), + `${key} is not primitive`, + ); + } + assert.ok(ROUTES.has(String(result.properties.path))); + }), + { numRuns: 500 }, + ); +}); + +test("sanitizeEvent never forwards attacker-controlled free text", () => { + fc.assert( + fc.property(event, (input) => { + const result = sanitizeEvent(input); + if (result === null) return; + assert.ok(!JSON.stringify(result.properties).includes(SECRET)); + }), + { numRuns: 500 }, + ); +}); + +test("sanitizeRoute only ever returns an allowed route or /_other", () => { + fc.assert( + fc.property(fc.oneof(fc.string(), fc.webUrl(), anything), (input) => { + assert.ok(ROUTES.has(sanitizeRoute(input))); + }), + { numRuns: 1000 }, + ); +}); diff --git a/frontend/test/workflow.test.mjs b/frontend/test/workflow.test.mjs index f0c538b..6f3a841 100644 --- a/frontend/test/workflow.test.mjs +++ b/frontend/test/workflow.test.mjs @@ -262,8 +262,13 @@ test("codeql.yml scans javascript-typescript and actions on push, PR and a sched const text = stripComments(readWorkflow("codeql.yml")); const on = extractBlocks(text).triggers; assert.match(on, /^ {2}push:\n {4}branches:\n {6}- main$/m); - assert.match(on, /^ {2}pull_request:\n {4}branches:\n {6}- main$/m); + assert.match(on, /^ {2}pull_request:\n {4}branches:\n {6}- main\n {6}- dev$/m); assert.match(on, /^ {2}schedule:\n {4}- cron:/m); + // Scorecard's SAST check looks for a scan on each merged PR, and dev PRs are most of them. + assert.match( + text, + /^concurrency:\n {2}group: codeql-.*\n {2}cancel-in-progress: .*pull_request/m, + ); assert.match(text, /^ {10}- javascript-typescript$/m); assert.match(text, /^ {10}- actions$/m); assert.match(text, /^permissions:\n {2}contents: read$/m); From 78c47cb3d76b3522639530679d825ba06de96503 Mon Sep 17 00:00:00 2001 From: scttbnsn <80784472+scttbnsn@users.noreply.github.com> Date: Thu, 26 Nov 2026 08:55:34 -0500 Subject: [PATCH 2/4] fix(catalogue): align plate rows and fill the empty grid cell --- frontend/app/(site)/page.tsx | 6 ++++++ frontend/components/catalogue/catalogue.module.css | 13 +++++++++++++ 2 files changed, 19 insertions(+) diff --git a/frontend/app/(site)/page.tsx b/frontend/app/(site)/page.tsx index c2f4206..740e8fc 100644 --- a/frontend/app/(site)/page.tsx +++ b/frontend/app/(site)/page.tsx @@ -157,6 +157,12 @@ export default function Home() { ))} + diff --git a/frontend/components/catalogue/catalogue.module.css b/frontend/components/catalogue/catalogue.module.css index ec37b0d..616b8d4 100644 --- a/frontend/components/catalogue/catalogue.module.css +++ b/frontend/components/catalogue/catalogue.module.css @@ -694,9 +694,22 @@ grid-template-columns: 200px minmax(0, 1fr); gap: 8px 28px; align-content: start; + height: 100%; + box-sizing: border-box; padding: 36px 0; border-bottom: 1px solid var(--ink); } +.plateNote { + display: none; +} +@media (min-width: 980px) { + .plateNote { + display: grid; + place-items: center; + padding: 36px 0; + border-bottom: 1px solid var(--ink); + } +} .portrait { position: relative; display: grid; From a25e880172882e04fa1e0a1e8dcd76973ab37623 Mon Sep 17 00:00:00 2001 From: scttbnsn <80784472+scttbnsn@users.noreply.github.com> Date: Thu, 26 Nov 2026 09:38:24 -0500 Subject: [PATCH 3/4] fix(catalogue): show the commissions note once, in the plate grid at 980px and up --- frontend/app/(site)/page.tsx | 8 ++++---- frontend/components/catalogue/catalogue.module.css | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/frontend/app/(site)/page.tsx b/frontend/app/(site)/page.tsx index 740e8fc..d383225 100644 --- a/frontend/app/(site)/page.tsx +++ b/frontend/app/(site)/page.tsx @@ -157,11 +157,11 @@ export default function Home() { ))} -
  • +
  • @@ -178,7 +178,7 @@ export default function Home() { help you ship it faster.

    -