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>
This commit is contained in:
@@ -3,6 +3,11 @@ import { contentSecurityPolicy, securityHeaders } from './securityHeaders';
|
||||
|
||||
const umami = 'https://analytics.slpsoftware.nl';
|
||||
const sentry = 'https://o4511795618185216.ingest.de.sentry.io';
|
||||
const captchaFrames = [
|
||||
'https://global.frcapi.com',
|
||||
'https://global0.frcapi.com',
|
||||
'https://global1.frcapi.com',
|
||||
];
|
||||
|
||||
const directive = (csp: string, name: string) =>
|
||||
csp.split('; ').find((d) => d.startsWith(name + ' ')) ?? '';
|
||||
@@ -21,19 +26,35 @@ describe('securityHeaders', () => {
|
||||
it('productie-CSP opent alleen Umami en Sentry, op de juiste plekken (M7)', () => {
|
||||
const csp = contentSecurityPolicy('production');
|
||||
const externalHosts = new Set(csp.match(/https:\/\/[^\s;]+/g));
|
||||
expect([...externalHosts].sort()).toEqual([sentry, umami].sort());
|
||||
expect([...externalHosts].sort()).toEqual(
|
||||
[sentry, umami, ...captchaFrames].sort(),
|
||||
);
|
||||
expect(directive(csp, 'connect-src')).toBe(
|
||||
`connect-src 'self' ${umami} ${sentry}`,
|
||||
);
|
||||
// Alleen script-src en connect-src noemen een externe host
|
||||
// Alleen script-src, connect-src en frame-src noemen een externe host
|
||||
for (const d of csp.split('; ')) {
|
||||
if (!/^(script|connect)-src /.test(d)) {
|
||||
if (!/^(script|connect|frame)-src /.test(d)) {
|
||||
expect(d).not.toContain('https://');
|
||||
}
|
||||
}
|
||||
expect(csp).not.toContain('*');
|
||||
});
|
||||
|
||||
it('productie-CSP laat het captcha-venster alleen van de drie vaste hosts toe', () => {
|
||||
const csp = contentSecurityPolicy('production');
|
||||
expect(directive(csp, 'frame-src')).toBe(
|
||||
`frame-src ${captchaFrames.join(' ')}`,
|
||||
);
|
||||
// Geen wildcard en niets extra's totdat een echte browser het eist
|
||||
expect(csp).not.toContain('*');
|
||||
expect(directive(csp, 'script-src')).toBe(`script-src 'self' ${umami}`);
|
||||
expect(directive(csp, 'worker-src')).toBe('');
|
||||
expect(directive(csp, 'connect-src')).toBe(
|
||||
`connect-src 'self' ${umami} ${sentry}`,
|
||||
);
|
||||
});
|
||||
|
||||
it('dev-CSP voegt alleen toe wat Vite nodig heeft', () => {
|
||||
const csp = contentSecurityPolicy('development');
|
||||
expect(directive(csp, 'script-src')).toBe(
|
||||
|
||||
@@ -8,6 +8,19 @@ 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],
|
||||
@@ -15,6 +28,7 @@ const productionCsp: Record<string, string[]> = {
|
||||
'img-src': ["'self'", 'data:'],
|
||||
'font-src': ["'self'"],
|
||||
'connect-src': ["'self'", umamiOrigin, sentryIngestOrigin],
|
||||
'frame-src': captchaFrameOrigins,
|
||||
'object-src': ["'none'"],
|
||||
'base-uri': ["'self'"],
|
||||
'form-action': ["'self'"],
|
||||
|
||||
Reference in New Issue
Block a user