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
2 changes: 1 addition & 1 deletion AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ REAL_DATA_DIR=data pnpm vitest run src/lib/server/import/realData.test.ts # op
## What not to do

- Don't edit, rename, re-save or "clean" the spreadsheets. Don't commit them, fixtures derived from them, or SQLite caches.
- Don't add a chart library or third-party scripts/fonts without updating the CSP in `vite.config.ts` and this file. Allowed third parties: GA4 gtag (`www.googletagmanager.com` / `*.google-analytics.com` / `*.analytics.google.com`; Measurement ID `G-VZF5DR37YH`, loaded only on `data.physioshark.org` / `physioshark.org` via `GoogleAnalytics.svelte`) and map tiles (Esri World Imagery, OpenStreetMap — the only external images besides GA beacons; a new tile host needs the CSP, the e2e tile stub in `e2e/pages.spec.ts` and the attribution).
- Don't add a chart library or third-party scripts/fonts without updating the CSP in `vite.config.ts` and this file. Allowed third parties: GA4 gtag (`GA_HOSTS` in `vite.config.ts`: `*.googletagmanager.com`, `*.google-analytics.com`, `analytics.google.com` and `*.analytics.google.com` (a `*.` wildcard doesn't match the bare host), plus `www.google.com` and `*.g.doubleclick.net` for Google signals, #166; Measurement ID `G-VZF5DR37YH`, loaded only on `data.physioshark.org` / `physioshark.org` via `GoogleAnalytics.svelte`) and map tiles (Esri World Imagery, OpenStreetMap — the only external images besides GA beacons; a new tile host needs the CSP, the e2e tile stub in `e2e/pages.spec.ts` and the attribution).
- Don't hard-code numbers in page copy; compute them in the load function.
- Don't claim causation from the correlations; don't overstate the human-pressure results (the source paper found no significant effect).
- Don't reintroduce dual-axis charts or per-point value labels.
Expand Down
22 changes: 22 additions & 0 deletions e2e/pages.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,25 @@ test('pages are compressed and revalidate with a 304 (#76)', async ({ request })
const again = await request.get('/morphometrics', { headers: { 'if-none-match': etag } });
expect(again.status()).toBe(304);
});

test('the content security policy lets Google Analytics hits through (#166)', async ({
request
}) => {
const res = await request.get('/');
const csp = res.headers()['content-security-policy'] ?? '';
const directive = (name: string) =>
csp
.split(';')
.map((d) => d.trim().split(/\s+/))
.find(([n]) => n === name)
?.slice(1) ?? [];
for (const host of [
'https://analytics.google.com',
'https://*.google-analytics.com',
'https://www.google.com',
'https://*.g.doubleclick.net'
]) {
expect(directive('connect-src')).toContain(host);
expect(directive('img-src')).toContain(host);
}
});
25 changes: 16 additions & 9 deletions vite.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,18 @@ import { defineConfig } from 'vite';
// Release version shown in the footer. Release workflows bump package.json before tagging.
const { version } = JSON.parse(readFileSync('package.json', 'utf8')) as { version: string };

// Hosts gtag.js sends GA4 hits to (#166). A `*.` wildcard needs a subdomain, so the bare
// analytics.google.com is listed on its own; with Google signals on, hits also go to
// www.google.com and stats.g.doubleclick.net.
const GA_HOSTS = [
'https://*.google-analytics.com',
'https://*.analytics.google.com',
'https://analytics.google.com',
'https://*.googletagmanager.com',
'https://www.google.com',
'https://*.g.doubleclick.net'
] as const;

export default defineConfig({
define: {
__APP_VERSION__: JSON.stringify(version)
Expand All @@ -29,22 +41,17 @@ export default defineConfig({
// Svelte `style:` directives use inline styles.
'style-src': ['self', 'unsafe-inline'],
// Map tiles for the interactive maps (#29): Esri imagery and OpenStreetMap.
// GA4 beacons may use image pings.
// GA4 beacons may use image pings (Google's CSP guide for GA4 with signals).
// The country-specific ga-audiences pixel (www.google.com.au…) stays blocked.
'img-src': [
'self',
'data:',
'https://server.arcgisonline.com',
'https://tile.openstreetmap.org',
'https://www.google-analytics.com',
'https://www.googletagmanager.com'
...GA_HOSTS
],
'font-src': ['self', 'data:'],
'connect-src': [
'self',
'https://*.google-analytics.com',
'https://*.analytics.google.com',
'https://*.googletagmanager.com'
],
'connect-src': ['self', ...GA_HOSTS],
'object-src': ['none'],
'base-uri': ['self'],
'form-action': ['self'],
Expand Down
Loading