Adds Sentry and Umami monitoring to the site
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
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
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>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
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 directive = (csp: string, name: string) =>
|
||||
csp.split('; ').find((d) => d.startsWith(name + ' ')) ?? '';
|
||||
|
||||
@@ -8,19 +11,37 @@ 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'");
|
||||
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].sort());
|
||||
expect(directive(csp, 'connect-src')).toBe(
|
||||
`connect-src 'self' ${umami} ${sentry}`,
|
||||
);
|
||||
// Alleen script-src en connect-src noemen een externe host
|
||||
for (const d of csp.split('; ')) {
|
||||
if (!/^(script|connect)-src /.test(d)) {
|
||||
expect(d).not.toContain('https://');
|
||||
}
|
||||
}
|
||||
expect(csp).not.toContain('*');
|
||||
});
|
||||
|
||||
it('dev-CSP voegt alleen toe wat Vite nodig heeft', () => {
|
||||
const csp = contentSecurityPolicy('development');
|
||||
expect(directive(csp, 'script-src')).toBe(
|
||||
"script-src 'self' 'unsafe-inline'",
|
||||
`script-src 'self' ${umami} 'unsafe-inline'`,
|
||||
);
|
||||
expect(directive(csp, 'connect-src')).toBe(
|
||||
`connect-src 'self' ${umami} ${sentry} ws:`,
|
||||
);
|
||||
expect(directive(csp, 'connect-src')).toBe("connect-src 'self' ws:");
|
||||
expect(csp).not.toContain('unsafe-eval');
|
||||
});
|
||||
|
||||
|
||||
@@ -1,17 +1,20 @@
|
||||
// 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 alleen van de eigen site.
|
||||
// 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'"],
|
||||
'script-src': ["'self'", umamiOrigin],
|
||||
'style-src': ["'self'", "'unsafe-inline'"],
|
||||
'img-src': ["'self'", 'data:'],
|
||||
'font-src': ["'self'"],
|
||||
'connect-src': ["'self'"],
|
||||
'connect-src': ["'self'", umamiOrigin, sentryIngestOrigin],
|
||||
'object-src': ["'none'"],
|
||||
'base-uri': ["'self'"],
|
||||
'form-action': ["'self'"],
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
<httpProtocol>
|
||||
<customHeaders>
|
||||
<remove name="X-Powered-By" />
|
||||
<add name="Content-Security-Policy" value="default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" />
|
||||
<add name="Content-Security-Policy" value="default-src 'self'; script-src 'self' https://analytics.slpsoftware.nl; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://analytics.slpsoftware.nl https://o4511795618185216.ingest.de.sentry.io; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" />
|
||||
<add name="Strict-Transport-Security" value="max-age=31536000; includeSubDomains" />
|
||||
<add name="X-Content-Type-Options" value="nosniff" />
|
||||
<add name="X-Frame-Options" value="DENY" />
|
||||
|
||||
@@ -15,7 +15,7 @@ server {
|
||||
# nginx naar zijn eigen http://-adres in plaats van de https-hostname
|
||||
absolute_redirect off;
|
||||
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://analytics.slpsoftware.nl; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://analytics.slpsoftware.nl https://o4511795618185216.ingest.de.sentry.io; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-Frame-Options "DENY" always;
|
||||
@@ -25,7 +25,7 @@ server {
|
||||
|
||||
# Testsite nooit indexeren
|
||||
location = /robots.txt {
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://analytics.slpsoftware.nl; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://analytics.slpsoftware.nl https://o4511795618185216.ingest.de.sentry.io; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-Frame-Options "DENY" always;
|
||||
@@ -37,7 +37,7 @@ server {
|
||||
|
||||
# Bestanden met een hash in de naam: lang cachen
|
||||
location /assets/ {
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://analytics.slpsoftware.nl; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://analytics.slpsoftware.nl https://o4511795618185216.ingest.de.sentry.io; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-Frame-Options "DENY" always;
|
||||
@@ -51,7 +51,7 @@ server {
|
||||
# =404 aan het eind: zonder index.html (lege map) een 404 in plaats van een
|
||||
# doorverwijzingslus die nginx als 500 afbreekt
|
||||
location / {
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self'; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Content-Security-Policy "default-src 'self'; script-src 'self' https://analytics.slpsoftware.nl; style-src 'self' 'unsafe-inline'; img-src 'self' data:; font-src 'self'; connect-src 'self' https://analytics.slpsoftware.nl https://o4511795618185216.ingest.de.sentry.io; object-src 'none'; base-uri 'self'; form-action 'self'; frame-ancestors 'none'" always;
|
||||
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
add_header X-Content-Type-Options "nosniff" always;
|
||||
add_header X-Frame-Options "DENY" always;
|
||||
|
||||
@@ -55,6 +55,7 @@
|
||||
"@emotion/react": "^11.14.0",
|
||||
"@fontsource/jost": "^5.3.0",
|
||||
"@fontsource/marcellus": "^5.3.0",
|
||||
"@sentry/react": "^11.8.0",
|
||||
"@tanstack/react-router": "^1.170.39",
|
||||
"react": "^19.3.0",
|
||||
"react-dom": "^19.3.0"
|
||||
|
||||
Generated
+88
@@ -181,6 +181,9 @@ importers:
|
||||
'@fontsource/marcellus':
|
||||
specifier: ^5.3.0
|
||||
version: 5.3.0
|
||||
'@sentry/react':
|
||||
specifier: ^11.8.0
|
||||
version: 11.8.0(react@19.3.0)
|
||||
'@tanstack/react-router':
|
||||
specifier: ^1.170.39
|
||||
version: 1.170.39(react-dom@19.3.0(react@19.3.0))(react@19.3.0)
|
||||
@@ -942,10 +945,30 @@ packages:
|
||||
resolution: {integrity: sha512-Fz5+4XCg3akeoFK+K7g+d7HqGMjmnLoY2eJlpONJmaeT9pXY7yfUyXKZMmMajdE2LxxKJgQ2YKvSCaGVamTjHw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
'@sentry/browser-utils@11.8.0':
|
||||
resolution: {integrity: sha512-tTqJmnfuJaQy9LyInCWJtJ0L+VnOq+L9+lTMkQH+pptXBAuHfdJyEl2IhGqO4QmsfKyZpHa2GVd3HKpEQsVYeg==}
|
||||
engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'}
|
||||
|
||||
'@sentry/browser@11.8.0':
|
||||
resolution: {integrity: sha512-uBC1k2ESZErHv+RfG6p9siHrtxv+QErDxL/jvEBZnoMV6OcWdZyWTGKcqrW7EjwlBiWkgVve1W7z8tNDDuVQxw==}
|
||||
engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'}
|
||||
|
||||
'@sentry/conventions@0.27.0':
|
||||
resolution: {integrity: sha512-Mrqd/o7n/z7qWSYfQQA7x4fFTA0IqOG6JNsbBpnC97khPwZk7n6DPtOO7YgaYplSl8R8QLRbBz9Xv2lVhToSAg==}
|
||||
engines: {node: '>=14'}
|
||||
|
||||
'@sentry/core@11.8.0':
|
||||
resolution: {integrity: sha512-4MVTthk6C/1oQFjbVIfygHyNkx2YGbwNLml0kJji0vjJXy6ZNls9zdIp0FTBTi4e3189IcSc5OXD4qcJdmEeKA==}
|
||||
engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'}
|
||||
|
||||
'@sentry/core@7.120.4':
|
||||
resolution: {integrity: sha512-TXu3Q5kKiq8db9OXGkWyXUbIxMMuttB5vJ031yolOl5T/B69JRyAoKuojLBjRv1XX583gS1rSSoX8YXX7ATFGA==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
'@sentry/feedback@11.8.0':
|
||||
resolution: {integrity: sha512-t8MSpbPoOcPOkywcv0Hwh97A82jWFZju5NU/a6pHmn2pKFktgCgnHKNHvlYp8QUaDNYijYpLv58NIM5Dg7by7A==}
|
||||
engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'}
|
||||
|
||||
'@sentry/integrations@7.120.4':
|
||||
resolution: {integrity: sha512-kkBTLk053XlhDCg7OkBQTIMF4puqFibeRO3E3YiVc4PGLnocXMaVpOSCkMqAc1k1kZ09UgGi8DxfQhnFEjUkpA==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -954,6 +977,24 @@ packages:
|
||||
resolution: {integrity: sha512-qq3wZAXXj2SRWhqErnGCSJKUhPSlZ+RGnCZjhfjHpP49KNpcd9YdPTIUsFMgeyjdh6Ew6aVCv23g1hTP0CHpYw==}
|
||||
engines: {node: '>=8'}
|
||||
|
||||
'@sentry/react@11.8.0':
|
||||
resolution: {integrity: sha512-8+RCBT4kZ954QpkKvHsQpBkFI3Tg0KShZLFRV4WVzocaRJL+iQA9Y2FV1bxQ12meC9BawaTbI8eX/uUIFDjwMA==}
|
||||
engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'}
|
||||
peerDependencies:
|
||||
react: 17.x || 18.x || 19.x
|
||||
react-router: 6.x || 7.x || 8.x
|
||||
peerDependenciesMeta:
|
||||
react-router:
|
||||
optional: true
|
||||
|
||||
'@sentry/replay-canvas@11.8.0':
|
||||
resolution: {integrity: sha512-/MiivHLdDv3ot5uJmWcPhIOubec54hPd4U/c2OE5oNyhM3zrd/S6b2FEfwke/V120QGEdZcuzGatwNJ2jNSkgQ==}
|
||||
engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'}
|
||||
|
||||
'@sentry/replay@11.8.0':
|
||||
resolution: {integrity: sha512-0jXMLd9XCBEZ5tu0VJa1uj1HYCpsjuNjbEBhF5pUw4FHyIH5hz01WuI20SH2Ct0pP1mykTzJLPGjZ8sUiAmMnQ==}
|
||||
engines: {node: '>=20.19.0 <22.0.0 || >=22.12.0 <23.0.0 || >=23.2.0'}
|
||||
|
||||
'@sentry/types@7.120.4':
|
||||
resolution: {integrity: sha512-cUq2hSSe6/qrU6oZsEP4InMI5VVdD86aypE+ENrQ6eZEVLTCYm1w6XhW1NvIu3UuWh7gZec4a9J7AFpYxki88Q==}
|
||||
engines: {node: '>=8'}
|
||||
@@ -3815,6 +3856,9 @@ packages:
|
||||
resolution: {integrity: sha512-4Nsy8K5Tr6SPDH9jhKJOHf7ChDrc1zufZTVSF7x72hwuEXBqxqk9G6cK+K2NRUtB3iELRJqjXb4JPDMBjMTl2Q==}
|
||||
engines: {node: ^22.22.2 || ^24.15.0 || >=26.0.0}
|
||||
|
||||
web-vitals@6.2.3:
|
||||
resolution: {integrity: sha512-Dmy+vdO1UPMqXiAtZSNayhl4f794Bxfd94W4HIj2HlYtczEQfEOon969memlcpcHrTuOKLa5baFjX7WbgmOq+A==}
|
||||
|
||||
webdriver-bidi-protocol@0.4.1:
|
||||
resolution: {integrity: sha512-ARrjNjtWRRs2w4Tk7nqrf2gBI0QXWuOmMCx2hU+1jUt6d00MjMxURrhxhGbrsoiZKJrhTSTzbIrc554iKI10qw==}
|
||||
|
||||
@@ -4740,11 +4784,36 @@ snapshots:
|
||||
'@sentry/types': 7.120.4
|
||||
'@sentry/utils': 7.120.4
|
||||
|
||||
'@sentry/browser-utils@11.8.0':
|
||||
dependencies:
|
||||
'@sentry/conventions': 0.27.0
|
||||
'@sentry/core': 11.8.0
|
||||
web-vitals: 6.2.3
|
||||
|
||||
'@sentry/browser@11.8.0':
|
||||
dependencies:
|
||||
'@sentry/browser-utils': 11.8.0
|
||||
'@sentry/conventions': 0.27.0
|
||||
'@sentry/core': 11.8.0
|
||||
'@sentry/feedback': 11.8.0
|
||||
'@sentry/replay': 11.8.0
|
||||
'@sentry/replay-canvas': 11.8.0
|
||||
|
||||
'@sentry/conventions@0.27.0': {}
|
||||
|
||||
'@sentry/core@11.8.0':
|
||||
dependencies:
|
||||
'@sentry/conventions': 0.27.0
|
||||
|
||||
'@sentry/core@7.120.4':
|
||||
dependencies:
|
||||
'@sentry/types': 7.120.4
|
||||
'@sentry/utils': 7.120.4
|
||||
|
||||
'@sentry/feedback@11.8.0':
|
||||
dependencies:
|
||||
'@sentry/core': 11.8.0
|
||||
|
||||
'@sentry/integrations@7.120.4':
|
||||
dependencies:
|
||||
'@sentry/core': 7.120.4
|
||||
@@ -4760,6 +4829,23 @@ snapshots:
|
||||
'@sentry/types': 7.120.4
|
||||
'@sentry/utils': 7.120.4
|
||||
|
||||
'@sentry/react@11.8.0(react@19.3.0)':
|
||||
dependencies:
|
||||
'@sentry/browser': 11.8.0
|
||||
'@sentry/conventions': 0.27.0
|
||||
'@sentry/core': 11.8.0
|
||||
react: 19.3.0
|
||||
|
||||
'@sentry/replay-canvas@11.8.0':
|
||||
dependencies:
|
||||
'@sentry/core': 11.8.0
|
||||
'@sentry/replay': 11.8.0
|
||||
|
||||
'@sentry/replay@11.8.0':
|
||||
dependencies:
|
||||
'@sentry/browser-utils': 11.8.0
|
||||
'@sentry/core': 11.8.0
|
||||
|
||||
'@sentry/types@7.120.4': {}
|
||||
|
||||
'@sentry/utils@7.120.4':
|
||||
@@ -8153,6 +8239,8 @@ snapshots:
|
||||
dependencies:
|
||||
xml-name-validator: 5.0.0
|
||||
|
||||
web-vitals@6.2.3: {}
|
||||
|
||||
webdriver-bidi-protocol@0.4.1: {}
|
||||
|
||||
webidl-conversions@3.0.1: {}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
import { render } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it } from 'vitest';
|
||||
import UmamiAnalytics from './UmamiAnalytics';
|
||||
|
||||
const umamiScripts = () =>
|
||||
document.querySelectorAll<HTMLScriptElement>(
|
||||
'script[src="https://analytics.slpsoftware.nl/script.js"]',
|
||||
);
|
||||
|
||||
afterEach(() => {
|
||||
umamiScripts().forEach((script) => script.remove());
|
||||
});
|
||||
|
||||
describe('UmamiAnalytics', () => {
|
||||
it('voegt geen script toe op een onbekende host', () => {
|
||||
render(<UmamiAnalytics hostname="localhost" />);
|
||||
expect(umamiScripts()).toHaveLength(0);
|
||||
});
|
||||
|
||||
it.each([
|
||||
['andreaslop.nl', '3edbb7d1-4388-4f2d-9cef-11ade88ace96'],
|
||||
['test.andreaslop.nl', '7fb301ab-6ecc-4aea-beee-71bcb6009bfe'],
|
||||
])('telt op %s met de juiste website', (hostname, websiteId) => {
|
||||
render(<UmamiAnalytics hostname={hostname} />);
|
||||
|
||||
const [script] = umamiScripts();
|
||||
expect(script.defer).toBe(true);
|
||||
expect(script.dataset).toMatchObject({
|
||||
websiteId,
|
||||
domains: hostname,
|
||||
doNotTrack: 'true',
|
||||
});
|
||||
});
|
||||
|
||||
it('voegt het script maar één keer toe', () => {
|
||||
render(<UmamiAnalytics hostname="andreaslop.nl" />);
|
||||
render(<UmamiAnalytics hostname="andreaslop.nl" />);
|
||||
expect(umamiScripts()).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('rendert niets zichtbaars', () => {
|
||||
const { container } = render(
|
||||
<UmamiAnalytics hostname="andreaslop.nl" />,
|
||||
);
|
||||
expect(container).toBeEmptyDOMElement();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import { useEffect } from 'react';
|
||||
import { monitoringFor, umamiOrigin } from '@/monitoring/config';
|
||||
|
||||
const SCRIPT_ELEMENT_ID = 'umami-analytics-script';
|
||||
|
||||
// Bezoekersstatistieken zonder cookies (M6). Alleen op een bekende host, met
|
||||
// de website van die omgeving; data-domains telt nergens anders mee en
|
||||
// data-do-not-track respecteert de Do Not Track-instelling van de browser.
|
||||
export default function UmamiAnalytics({
|
||||
hostname = window.location.hostname,
|
||||
}: {
|
||||
hostname?: string;
|
||||
}) {
|
||||
useEffect(() => {
|
||||
const monitoring = monitoringFor(hostname);
|
||||
if (!monitoring || document.getElementById(SCRIPT_ELEMENT_ID)) return;
|
||||
|
||||
const script = document.createElement('script');
|
||||
script.id = SCRIPT_ELEMENT_ID;
|
||||
script.src = `${umamiOrigin}/script.js`;
|
||||
script.defer = true;
|
||||
script.dataset.websiteId = monitoring.umamiWebsiteId;
|
||||
script.dataset.domains = hostname;
|
||||
script.dataset.doNotTrack = 'true';
|
||||
document.head.appendChild(script);
|
||||
|
||||
return () => script.remove();
|
||||
}, [hostname]);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -2,6 +2,7 @@ import { SkipNavContent, SkipNavLink } from '@chakra-ui/react';
|
||||
import { Outlet } from '@tanstack/react-router';
|
||||
import siteContent from '@/content/siteContent';
|
||||
import useRouteFocus from '@/hooks/useRouteFocus';
|
||||
import UmamiAnalytics from './Analytics/UmamiAnalytics';
|
||||
import BackToTop from './BackToTop/BackToTop';
|
||||
import Footer from './Footer/Footer';
|
||||
import NavigationBar from './NavigationBar/NavigationBar';
|
||||
@@ -22,6 +23,7 @@ export default function AppShell() {
|
||||
</SkipNavContent>
|
||||
<Footer content={siteContent} />
|
||||
<BackToTop />
|
||||
<UmamiAnalytics />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -1,17 +1,19 @@
|
||||
import { useEffect } from 'react';
|
||||
import { chakra, useRecipe } from '@chakra-ui/react';
|
||||
import { useRouter, type ErrorComponentProps } from '@tanstack/react-router';
|
||||
import { reportError } from '@/monitoring/sentry';
|
||||
import LinkButton from '../LinkButton';
|
||||
import StatusPage from './StatusPage';
|
||||
|
||||
// Algemene foutpagina (FR-10). Toont nooit de foutmelding zelf; die gaat
|
||||
// alleen naar de console (BR-ERR-02/03).
|
||||
// alleen naar de console en Sentry (BR-ERR-02/03).
|
||||
export default function ErrorPage({ error, reset }: ErrorComponentProps) {
|
||||
const router = useRouter();
|
||||
const buttonRecipe = useRecipe({ key: 'linkButton' });
|
||||
|
||||
useEffect(() => {
|
||||
console.error(error);
|
||||
reportError(error);
|
||||
}, [error]);
|
||||
|
||||
// Foutgrens resetten en de route opnieuw laden (BR-ERR-04)
|
||||
|
||||
@@ -5,12 +5,16 @@ import { routeTree } from './routeTree.gen';
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import system from './theme.ts';
|
||||
import ErrorPage from './components/StatusPage/ErrorPage';
|
||||
import { startSentry } from './monitoring/sentry';
|
||||
|
||||
import '@fontsource/jost/300.css';
|
||||
import '@fontsource/jost/400.css';
|
||||
import '@fontsource/jost/500.css';
|
||||
import '@fontsource/marcellus/400.css';
|
||||
|
||||
// Foutmeldingen naar Sentry, alleen op test en productie (M1)
|
||||
startSentry();
|
||||
|
||||
// Create a new router instance
|
||||
const router = createRouter({
|
||||
routeTree,
|
||||
|
||||
@@ -0,0 +1,56 @@
|
||||
import fc from 'fast-check';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import {
|
||||
monitoredHostnames,
|
||||
monitoringFor,
|
||||
sentryIngestOrigin,
|
||||
} from './config';
|
||||
|
||||
// Alles wat geen test- of productiehost is
|
||||
const otherHostname = fc
|
||||
.oneof(
|
||||
fc.domain(),
|
||||
fc.ipV4(),
|
||||
fc.ipV6(),
|
||||
fc.string(),
|
||||
fc.constantFrom(
|
||||
'localhost',
|
||||
'127.0.0.1',
|
||||
'www.andreaslop.nl',
|
||||
'andreaslop.nl.',
|
||||
'test.andreaslop.nl.evil.com',
|
||||
'__proto__',
|
||||
'constructor',
|
||||
),
|
||||
)
|
||||
.filter((host) => !monitoredHostnames.includes(host));
|
||||
|
||||
describe('monitoringFor', () => {
|
||||
it('productiehost meet als production met de productiewebsite', () => {
|
||||
expect(monitoringFor('andreaslop.nl')).toEqual({
|
||||
environment: 'production',
|
||||
umamiWebsiteId: '3edbb7d1-4388-4f2d-9cef-11ade88ace96',
|
||||
});
|
||||
});
|
||||
|
||||
it('testhost meet als test met de testwebsite', () => {
|
||||
expect(monitoringFor('test.andreaslop.nl')).toEqual({
|
||||
environment: 'test',
|
||||
umamiWebsiteId: '7fb301ab-6ecc-4aea-beee-71bcb6009bfe',
|
||||
});
|
||||
});
|
||||
|
||||
it('elke andere host meet niets (M1)', () => {
|
||||
fc.assert(
|
||||
fc.property(otherHostname, (host) => {
|
||||
expect(monitoringFor(host)).toBeNull();
|
||||
}),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('Sentry-ingest is de EU-host uit de DSN, zonder sleutel', () => {
|
||||
expect(sentryIngestOrigin).toBe(
|
||||
'https://o4511795618185216.ingest.de.sentry.io',
|
||||
);
|
||||
});
|
||||
@@ -0,0 +1,43 @@
|
||||
// Instellingen voor Sentry en Umami (monitoring-plan M1/M2). Deze waarden zijn
|
||||
// openbaar: ze staan hoe dan ook in de browser van elke bezoeker.
|
||||
// Geen imports uit Vite: config/securityHeaders.ts leest dit bestand ook in Node.
|
||||
|
||||
export type MonitoringEnvironment = 'test' | 'production';
|
||||
|
||||
export interface Monitoring {
|
||||
environment: MonitoringEnvironment;
|
||||
umamiWebsiteId: string;
|
||||
}
|
||||
|
||||
export const sentryDsn =
|
||||
'https://12ec77dcc3216a98b96d3fb3dac13f66@o4511795618185216.ingest.de.sentry.io/4512282287472720';
|
||||
|
||||
// Waar de browser fouten naartoe stuurt; nodig voor connect-src in de CSP
|
||||
export const sentryIngestOrigin = new URL(sentryDsn).origin;
|
||||
|
||||
export const umamiOrigin = 'https://analytics.slpsoftware.nl';
|
||||
|
||||
// Eén build voor beide omgevingen: de hostname bepaalt de omgeving
|
||||
const monitoringByHostname = new Map<string, Monitoring>([
|
||||
[
|
||||
'andreaslop.nl',
|
||||
{
|
||||
environment: 'production',
|
||||
umamiWebsiteId: '3edbb7d1-4388-4f2d-9cef-11ade88ace96',
|
||||
},
|
||||
],
|
||||
[
|
||||
'test.andreaslop.nl',
|
||||
{
|
||||
environment: 'test',
|
||||
umamiWebsiteId: '7fb301ab-6ecc-4aea-beee-71bcb6009bfe',
|
||||
},
|
||||
],
|
||||
]);
|
||||
|
||||
// Onbekende host (localhost, Lighthouse CI, previews): niets meten (M1)
|
||||
export function monitoringFor(hostname: string): Monitoring | null {
|
||||
return monitoringByHostname.get(hostname) ?? null;
|
||||
}
|
||||
|
||||
export const monitoredHostnames = [...monitoringByHostname.keys()];
|
||||
@@ -0,0 +1,99 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
const init = vi.fn();
|
||||
const captureException = vi.fn();
|
||||
vi.mock('@sentry/react', () => ({ init, captureException }));
|
||||
|
||||
// De module houdt zijn toestand bij; elke test begint met een verse kopie
|
||||
async function freshSentry() {
|
||||
vi.resetModules();
|
||||
return import('./sentry');
|
||||
}
|
||||
|
||||
beforeEach(() => {
|
||||
init.mockReset();
|
||||
captureException.mockReset();
|
||||
});
|
||||
|
||||
describe('Sentry', () => {
|
||||
it('start niet en stuurt niets op een onbekende host', async () => {
|
||||
const { startSentry, reportError } = await freshSentry();
|
||||
startSentry('localhost');
|
||||
reportError(new Error('lokaal'));
|
||||
|
||||
await Promise.resolve();
|
||||
expect(init).not.toHaveBeenCalled();
|
||||
expect(captureException).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('start op test met omgeving test en zonder persoonsgegevens', async () => {
|
||||
const { startSentry } = await freshSentry();
|
||||
startSentry('test.andreaslop.nl');
|
||||
|
||||
await vi.waitFor(() => expect(init).toHaveBeenCalledOnce());
|
||||
expect(init.mock.calls[0][0]).toMatchObject({
|
||||
environment: 'test',
|
||||
dataCollection: {
|
||||
userInfo: false,
|
||||
cookies: false,
|
||||
httpHeaders: false,
|
||||
httpBodies: [],
|
||||
urlQueryParams: false,
|
||||
},
|
||||
});
|
||||
expect(init.mock.calls[0][0]).not.toHaveProperty('tracesSampleRate');
|
||||
});
|
||||
|
||||
it('fouten van voor de start gaan mee zodra Sentry klaar is', async () => {
|
||||
const { startSentry, reportError } = await freshSentry();
|
||||
startSentry('andreaslop.nl');
|
||||
const early = new Error('vroeg');
|
||||
reportError(early);
|
||||
expect(captureException).not.toHaveBeenCalled();
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(captureException).toHaveBeenCalledWith(early),
|
||||
);
|
||||
const later = new Error('later');
|
||||
reportError(later);
|
||||
expect(captureException).toHaveBeenLastCalledWith(later);
|
||||
expect(init.mock.calls[0][0]).toMatchObject({
|
||||
environment: 'production',
|
||||
});
|
||||
});
|
||||
|
||||
it('vangt onafgevangen fouten tijdens het laden op', async () => {
|
||||
const { startSentry } = await freshSentry();
|
||||
startSentry('andreaslop.nl');
|
||||
const error = new Error('onafgevangen');
|
||||
window.dispatchEvent(new ErrorEvent('error', { error }));
|
||||
|
||||
await vi.waitFor(() =>
|
||||
expect(captureException).toHaveBeenCalledWith(error),
|
||||
);
|
||||
});
|
||||
|
||||
it('wacht op het load-event als de pagina nog laadt', async () => {
|
||||
const readyState = vi
|
||||
.spyOn(document, 'readyState', 'get')
|
||||
.mockReturnValue('loading');
|
||||
const { startSentry } = await freshSentry();
|
||||
startSentry('andreaslop.nl');
|
||||
|
||||
await Promise.resolve();
|
||||
expect(init).not.toHaveBeenCalled();
|
||||
|
||||
readyState.mockReturnValue('complete');
|
||||
window.dispatchEvent(new Event('load'));
|
||||
await vi.waitFor(() => expect(init).toHaveBeenCalledOnce());
|
||||
});
|
||||
|
||||
it('start maar één keer', async () => {
|
||||
const { startSentry } = await freshSentry();
|
||||
startSentry('andreaslop.nl');
|
||||
startSentry('andreaslop.nl');
|
||||
|
||||
await vi.waitFor(() => expect(init).toHaveBeenCalled());
|
||||
expect(init).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,55 @@
|
||||
import { monitoringFor, sentryDsn } from './config';
|
||||
|
||||
// Sentry laadt pas na het load-event, buiten de hoofdbundel (M4). Fouten van
|
||||
// daarvoor wachten in een wachtrij en gaan mee zodra Sentry klaar is.
|
||||
|
||||
type State =
|
||||
| { kind: 'off' }
|
||||
| { kind: 'loading'; queue: unknown[] }
|
||||
| { kind: 'ready'; capture: (error: unknown) => void };
|
||||
|
||||
let state: State = { kind: 'off' };
|
||||
|
||||
export function reportError(error: unknown): void {
|
||||
if (state.kind === 'ready') state.capture(error);
|
||||
else if (state.kind === 'loading') state.queue.push(error);
|
||||
}
|
||||
|
||||
// Onafgevangen fouten tijdens het laden; daarna vangt Sentry ze zelf
|
||||
const onError = (event: ErrorEvent) => reportError(event.error);
|
||||
const onRejection = (event: PromiseRejectionEvent) => reportError(event.reason);
|
||||
|
||||
export function startSentry(hostname = window.location.hostname): void {
|
||||
const monitoring = monitoringFor(hostname);
|
||||
if (!monitoring || state.kind !== 'off') return;
|
||||
|
||||
const queue: unknown[] = [];
|
||||
state = { kind: 'loading', queue };
|
||||
window.addEventListener('error', onError);
|
||||
window.addEventListener('unhandledrejection', onRejection);
|
||||
|
||||
const load = async () => {
|
||||
const Sentry = await import('./sentryClient');
|
||||
// Alleen fouten: geen tracing, geen replay, geen persoonsgegevens (M5).
|
||||
// Sinds SDK 11 verzamelt Sentry standaard alles; daarom alles expliciet uit.
|
||||
Sentry.init({
|
||||
dsn: sentryDsn,
|
||||
environment: monitoring.environment,
|
||||
release: import.meta.env.VITE_RELEASE,
|
||||
dataCollection: {
|
||||
userInfo: false,
|
||||
cookies: false,
|
||||
httpHeaders: false,
|
||||
httpBodies: [],
|
||||
urlQueryParams: false,
|
||||
},
|
||||
});
|
||||
window.removeEventListener('error', onError);
|
||||
window.removeEventListener('unhandledrejection', onRejection);
|
||||
state = { kind: 'ready', capture: Sentry.captureException };
|
||||
queue.forEach(reportError);
|
||||
};
|
||||
|
||||
if (document.readyState === 'complete') void load();
|
||||
else window.addEventListener('load', () => void load(), { once: true });
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
// Alleen wat sentry.ts gebruikt. Een dynamische import van '@sentry/react'
|
||||
// zelf haalt de hele SDK binnen; via losse named exports kan Vite de rest
|
||||
// weglaten (tree-shaking).
|
||||
export { captureException, init } from '@sentry/react';
|
||||
Reference in New Issue
Block a user