Files
SluijsensandClaude Sonnet 5.5 a1444b7b2a Adds the captcha frame hosts to the CSP and handles a widget that cannot load
frame-src gets the three exact Friendly Captcha global hosts (no wildcard).
When the widget errors, is blocked or shows no sign of life, the form says so
and offers the mail button instead of blocking silently. Adds an e2e for the
form with a mocked API, a draft privacy text for approval, and label tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-10 23:27:29 +01:00

67 lines
2.7 KiB
TypeScript

// HTTP-securityheaders voor de Vite dev- en preview-server. De productieset is
// ook het voorschrift voor de toekomstige host (zie NFR-SEC-01/02).
import { sentryIngestOrigin, umamiOrigin } from '../src/monitoring/config.ts';
type Mode = 'production' | 'development';
// Chakra/Emotion zetten tijdens runtime <style>-tags in de pagina, daarom
// staat style-src 'unsafe-inline' toe. Scripts komen van de eigen site en het
// Umami-script; verbindingen alleen naar Umami en Sentry (monitoring-plan M7).
// Friendly Captcha (contactformulier): de widget laadt zijn iframes van het
// hoofdhost en twee reservehosts, die de SDK bij een storing probeert. Exact
// deze drie, geen wildcard (besluit Bryan, 2026-11-10). Bij de overstap naar
// het EU-endpoint komen eu, eu0 en eu1 in de plaats; dat regelt de server
// (token-antwoord) en deze lijst moet dan mee. De SDK zelf zit in de eigen
// bundel, dus script-src verandert niet. connect-src en worker-src komen er
// pas bij als een test met een echte browser laat zien dat ze nodig zijn.
export const captchaFrameOrigins = [
'https://global.frcapi.com',
'https://global0.frcapi.com',
'https://global1.frcapi.com',
];
const productionCsp: Record<string, string[]> = {
'default-src': ["'self'"],
'script-src': ["'self'", umamiOrigin],
'style-src': ["'self'", "'unsafe-inline'"],
'img-src': ["'self'", 'data:'],
'font-src': ["'self'"],
'connect-src': ["'self'", umamiOrigin, sentryIngestOrigin],
'frame-src': captchaFrameOrigins,
'object-src': ["'none'"],
'base-uri': ["'self'"],
'form-action': ["'self'"],
'frame-ancestors': ["'none'"],
};
// Alleen wat de Vite dev-server zelf nodig heeft: een inline script voor
// React Refresh en een websocket voor hot reload.
const developmentExtras: Record<string, string[]> = {
'script-src': ["'unsafe-inline'"],
'connect-src': ['ws:'],
};
export function contentSecurityPolicy(mode: Mode): string {
return Object.entries(productionCsp)
.map(([directive, sources]) => {
const extra =
mode === 'development'
? (developmentExtras[directive] ?? [])
: [];
return [directive, ...sources, ...extra].join(' ');
})
.join('; ');
}
export function securityHeaders(mode: Mode): Record<string, string> {
return {
'Content-Security-Policy': contentSecurityPolicy(mode),
// Browsers negeren HSTS over http://localhost; telt pas op de echte host
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'DENY',
'Referrer-Policy': 'strict-origin-when-cross-origin',
};
}