From db06b614516dc1145f606034104b3c63582a91dc Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Mon, 23 Nov 2026 01:45:33 +0100 Subject: [PATCH 1/2] fix(security): allow the cloudflare analytics beacon in the csp Cloudflare injects its Web Analytics beacon at the edge. The report-only policy did not allow it, so Chrome logged a CSP issue and Lighthouse Best Practices dropped. --- shared/utils/securityHeaders.ts | 9 +++++++-- tests/architecture/security-headers.spec.ts | 8 ++++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/shared/utils/securityHeaders.ts b/shared/utils/securityHeaders.ts index 66c55fef..3b4fe49a 100644 --- a/shared/utils/securityHeaders.ts +++ b/shared/utils/securityHeaders.ts @@ -14,7 +14,12 @@ export const CSP_SOURCES = { // 'unsafe-inline': Nuxt inlines `window.__NUXT__` and the payload bootstrap. // A nonce would differ per request, and pages are cached and shared at the // edge; a hash would change with every page. Revisit with a build-time hash step. - 'script-src': ["'self'", "'unsafe-inline'"], + // static.cloudflareinsights.com: Web Analytics beacon, injected by Cloudflare at the edge. + 'script-src': [ + "'self'", + "'unsafe-inline'", + 'https://static.cloudflareinsights.com' + ], // Vue's `style` bindings and Nuxt's inlined critical CSS are inline styles. 'style-src': ["'self'", "'unsafe-inline'"], // img.onelitefeather.net: @nuxt/image's Cloudflare provider. The other two @@ -27,7 +32,7 @@ export const CSP_SOURCES = { 'https://images.opencollective.com'], 'font-src': ["'self'", 'data:'], // PostHog reaches the browser through the same-origin /ingest proxy. - 'connect-src': ["'self'"], + 'connect-src': ["'self'", 'https://cloudflareinsights.com'], // The BlueMap embed (runtimeConfig.public.bluemapUrl). 'frame-src': ['https://bluemap.onelitefeather.dev'], 'worker-src': ["'self'", 'blob:'], diff --git a/tests/architecture/security-headers.spec.ts b/tests/architecture/security-headers.spec.ts index ebfe54d2..f35ef23d 100644 --- a/tests/architecture/security-headers.spec.ts +++ b/tests/architecture/security-headers.spec.ts @@ -71,7 +71,11 @@ describe('content security policy source list', () => { it('allows exactly these sources', () => { expect(CSP_SOURCES).toEqual({ 'default-src': ["'self'"], - 'script-src': ["'self'", "'unsafe-inline'"], + 'script-src': [ + "'self'", + "'unsafe-inline'", + 'https://static.cloudflareinsights.com' + ], 'style-src': ["'self'", "'unsafe-inline'"], 'img-src': [ "'self'", @@ -81,7 +85,7 @@ describe('content security policy source list', () => { 'https://images.opencollective.com' ], 'font-src': ["'self'", 'data:'], - 'connect-src': ["'self'"], + 'connect-src': ["'self'", 'https://cloudflareinsights.com'], 'frame-src': ['https://bluemap.onelitefeather.dev'], 'worker-src': ["'self'", 'blob:'], 'manifest-src': ["'self'"], From 99306ee04af3b93dbbf03b68a078f7686381a6c2 Mon Sep 17 00:00:00 2001 From: TheMeinerLP Date: Mon, 23 Nov 2026 01:46:03 +0100 Subject: [PATCH 2/2] fix(security): keep connect-src at self for the injected beacon With automatic injection the beacon reports to /cdn-cgi/rum on the same host, so only script-src needs the Cloudflare origin. --- shared/utils/securityHeaders.ts | 2 +- tests/architecture/security-headers.spec.ts | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/shared/utils/securityHeaders.ts b/shared/utils/securityHeaders.ts index 3b4fe49a..fb2788d6 100644 --- a/shared/utils/securityHeaders.ts +++ b/shared/utils/securityHeaders.ts @@ -32,7 +32,7 @@ export const CSP_SOURCES = { 'https://images.opencollective.com'], 'font-src': ["'self'", 'data:'], // PostHog reaches the browser through the same-origin /ingest proxy. - 'connect-src': ["'self'", 'https://cloudflareinsights.com'], + 'connect-src': ["'self'"], // The BlueMap embed (runtimeConfig.public.bluemapUrl). 'frame-src': ['https://bluemap.onelitefeather.dev'], 'worker-src': ["'self'", 'blob:'], diff --git a/tests/architecture/security-headers.spec.ts b/tests/architecture/security-headers.spec.ts index f35ef23d..0c5a39d3 100644 --- a/tests/architecture/security-headers.spec.ts +++ b/tests/architecture/security-headers.spec.ts @@ -85,7 +85,7 @@ describe('content security policy source list', () => { 'https://images.opencollective.com' ], 'font-src': ["'self'", 'data:'], - 'connect-src': ["'self'", 'https://cloudflareinsights.com'], + 'connect-src': ["'self'"], 'frame-src': ['https://bluemap.onelitefeather.dev'], 'worker-src': ["'self'", 'blob:'], 'manifest-src': ["'self'"],