Files
AndreaSlopFotografie/web/config/securityHeaders.ts
T
SluijsensandClaude Opus 5.5 6d3a1566c2
Continuous Integration / lighthouse (pull_request) Canceled after 0s
Continuous Integration / deploy-test (pull_request) Canceled after 0s
Continuous Integration / deploy-production (pull_request) Canceled after 0s
Continuous Integration / check (pull_request) Canceled after 2m22s
Adds Sentry and Umami monitoring to the site
Sentry loads after the page and reports errors only, without personal data;
Umami counts visits per environment. Both only run on andreaslop.nl and
test.andreaslop.nl. The CSP allows just these two hosts, and builds carry the
commit SHA as release.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-19 12:08:47 +02:00

53 lines
2.0 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).
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],
'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',
};
}