Monitoring settings (Sentry, Umami) and the CSP origins come from the build environment

One build per environment: PROD_* variables for the production artifact,
TEST_* for the test build and the CSP check. The build fails when a variable
is empty. Tests use the production values from config/monitoringTestEnv.ts.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-18 19:29:51 +01:00
co-authored by Claude Sonnet 5.5
parent 6475696709
commit 49b1d5f0ba
14 changed files with 286 additions and 85 deletions
+20 -15
View File
@@ -1,7 +1,7 @@
// 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';
import { monitoringOrigins } from '../src/monitoring/config.ts';
type Mode = 'production' | 'development';
@@ -21,19 +21,24 @@ export const captchaFrameOrigins = [
'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'"],
};
// De herkomsten van Umami en Sentry komen uit de build-omgeving (zie
// src/monitoring/config.ts); zonder die instellingen staan ze er niet in.
function productionCsp(): Record<string, string[]> {
const origins = monitoringOrigins();
return {
'default-src': ["'self'"],
'script-src': ["'self'", ...origins.umami],
'style-src': ["'self'", "'unsafe-inline'"],
'img-src': ["'self'", 'data:'],
'font-src': ["'self'"],
'connect-src': ["'self'", ...origins.umami, ...origins.sentry],
'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.
@@ -43,7 +48,7 @@ const developmentExtras: Record<string, string[]> = {
};
export function contentSecurityPolicy(mode: Mode): string {
return Object.entries(productionCsp)
return Object.entries(productionCsp())
.map(([directive, sources]) => {
const extra =
mode === 'development'