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(
|
||||
|
||||
Reference in New Issue
Block a user