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>
78 lines
3.1 KiB
TypeScript
78 lines
3.1 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
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 + ' ')) ?? '';
|
|
|
|
describe('securityHeaders', () => {
|
|
it('productie-CSP heeft geen onveilige uitzonderingen voor scripts', () => {
|
|
const csp = contentSecurityPolicy('production');
|
|
expect(csp).not.toContain('unsafe-eval');
|
|
expect(directive(csp, 'script-src')).toBe(`script-src 'self' ${umami}`);
|
|
expect(csp).not.toContain('ws:');
|
|
expect(directive(csp, 'frame-ancestors')).toBe(
|
|
"frame-ancestors 'none'",
|
|
);
|
|
});
|
|
|
|
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, ...captchaFrames].sort(),
|
|
);
|
|
expect(directive(csp, 'connect-src')).toBe(
|
|
`connect-src 'self' ${umami} ${sentry}`,
|
|
);
|
|
// Alleen script-src, connect-src en frame-src noemen een externe host
|
|
for (const d of csp.split('; ')) {
|
|
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(
|
|
`script-src 'self' ${umami} 'unsafe-inline'`,
|
|
);
|
|
expect(directive(csp, 'connect-src')).toBe(
|
|
`connect-src 'self' ${umami} ${sentry} ws:`,
|
|
);
|
|
expect(csp).not.toContain('unsafe-eval');
|
|
});
|
|
|
|
it('zet alle verplichte headers', () => {
|
|
expect(securityHeaders('production')).toMatchObject({
|
|
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains',
|
|
'X-Content-Type-Options': 'nosniff',
|
|
'X-Frame-Options': 'DENY',
|
|
'Referrer-Policy': 'strict-origin-when-cross-origin',
|
|
});
|
|
});
|
|
});
|