Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 get a unique group per run, so a pending scan is never replaced.
concurrency:
group: codeql-${{ github.event.pull_request.number || github.run_id }}
cancel-in-progress: ${{ github.event_name == 'pull_request' }}

jobs:
analyze:
runs-on: ubuntu-latest
Expand Down
8 changes: 7 additions & 1 deletion frontend/app/(site)/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@ export default function Home() {
</article>
</li>
))}
<li className={styles.plateNote}>
<aside className={styles.dotCard} aria-label="Commissions note">
<p className={styles.eyebrow}>Commissions</p>
<p className={styles.dotCardBig}>Taken on, one at a time.</p>
</aside>
</li>
</ul>
</section>

Expand All @@ -172,7 +178,7 @@ export default function Home() {
help you ship it faster.
</p>
</div>
<aside className={styles.dotCard} aria-label="Commissions note">
<aside className={`${styles.dotCard} ${styles.headNote}`} aria-label="Commissions note">
<p className={styles.eyebrow}>Commissions</p>
<p className={styles.dotCardBig}>Taken on, one at a time.</p>
</aside>
Expand Down
16 changes: 16 additions & 0 deletions frontend/components/catalogue/catalogue.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -694,9 +694,25 @@
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) {
.headNote {
display: none;
}
.plateNote {
display: grid;
place-items: center;
padding: 36px 0;
border-bottom: 1px solid var(--ink);
}
}
.portrait {
position: relative;
display: grid;
Expand Down
41 changes: 41 additions & 0 deletions frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
107 changes: 107 additions & 0 deletions frontend/test/posthog-privacy.property.test.ts
Original file line number Diff line number Diff line change
@@ -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<string>([...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 },
);
});
7 changes: 6 additions & 1 deletion frontend/test/workflow.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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-\$\{\{ github\.event\.pull_request\.number \|\| github\.run_id \}\}\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);
Expand Down
2 changes: 1 addition & 1 deletion lefthook.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pre-commit:
jobs:
- name: biome
root: frontend/
glob: "*.{js,ts,jsx,tsx,json,css}"
glob: "*.{js,mjs,cjs,ts,mts,jsx,tsx,json,css}"
run: npx @biomejs/biome check --write --no-errors-on-unmatched {staged_files}
stage_fixed: true

Expand Down