Skip to content

Commit 3b78666

Browse files
fix: CSP blocks webanalytics.digiaiiris.com script
Refs: PALVELUKARTTA-UI-9E (#1358) * fix: include Matomo URL in CSP script-src Refs: PALVELUKARTTA-UI-9E * fix: gate Matomo CSP source on Matomo being enabled --------- Co-authored-by: sentry[bot] <39604003+sentry[bot]@users.noreply.github.com> Co-authored-by: timwessman <tim.wessman@gofore.com>
1 parent d32d1e4 commit 3b78666

1 file changed

Lines changed: 8 additions & 1 deletion

File tree

server/server.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -337,10 +337,17 @@ const generateCSPHeaders = () => {
337337
csp['form-action'] = `'self'`;
338338
csp['img-src'] = `'self' data: https://www.hel.fi ${process.env.CSP_IMG_SRC}`;
339339
csp['manifest-src'] = `'self'`;
340+
// Only allowlist the Matomo source when Matomo is actually enabled, matching
341+
// the frontend condition in src/App.js, to keep the CSP as strict as possible.
342+
const matomoEnabled =
343+
process.env.REACT_APP_MATOMO_ENABLED === 'true' &&
344+
!!process.env.REACT_APP_MATOMO_URL &&
345+
!!process.env.REACT_APP_MATOMO_SITE_ID;
346+
const matomoScriptSrc = matomoEnabled ? process.env.REACT_APP_MATOMO_URL : '';
340347
csp['script-src'] = `'self' \
341348
'nonce-${nonce}' \
342349
https://unpkg.com/leaflet@1.9.4/dist/leaflet.js \
343-
${process.env.CSP_SCRIPT_SRC}`;
350+
${matomoScriptSrc} ${process.env.CSP_SCRIPT_SRC || ''}`;
344351
csp['script-src-attr'] =
345352
`'unsafe-hashes' 'sha256-7Hm4kDnuwRKq0GkRVBPz6YL9PvbRT9e9rAqI5RnLzBQ='`;
346353
csp['style-src'] =

0 commit comments

Comments
 (0)