Skip to content

fix(csp): allow Cloudflare Web Analytics beacon#8

Merged
MattNotarangelo merged 1 commit into
mainfrom
worktree-fix-csp-cf-analytics
Jun 27, 2026
Merged

fix(csp): allow Cloudflare Web Analytics beacon#8
MattNotarangelo merged 1 commit into
mainfrom
worktree-fix-csp-cf-analytics

Conversation

@MattNotarangelo

Copy link
Copy Markdown
Owner

Problem

Cloudflare Web Analytics was recording zero data. The cause is self-inflicted: the strict CSP in index.html blocked the analytics beacon that Cloudflare Pages auto-injects into every served page.

The served HTML contains:

<script defer src='https://static.cloudflareinsights.com/beacon.min.js'
        data-cf-beacon='{"token":"…"}'></script>

…but the meta CSP blocked it on two fronts:

  • script-src 'self'beacon.min.js never loads
  • connect-src 'self' → even if loaded, it couldn't POST RUM data

Result: two CSP violations in the console and no metrics.

Fix

Allowlist exactly the two origins the beacon uses, nothing broader:

  • script-src: add https://static.cloudflareinsights.com
  • connect-src: add https://cloudflareinsights.com

Also updated the adjacent comment, which previously claimed "No third-party/network resources" — no longer accurate now that the beacon is permitted.

Test plan

  • npm run build succeeds; CSP propagates intact to dist/index.html
  • Allowlisted origins match the beacon's actual script host + RUM endpoint
  • Post-deploy: reload live site, confirm CSP console errors gone and Web Analytics starts recording

🤖 Generated with Claude Code

The strict CSP (script-src 'self', connect-src 'self') blocked the
beacon that Cloudflare Pages auto-injects, so Web Analytics recorded
nothing. Allowlist the two beacon origins:
- script-src: https://static.cloudflareinsights.com (beacon.min.js)
- connect-src: https://cloudflareinsights.com (RUM /cdn-cgi/rum endpoint)

Comment updated to reflect the one permitted third-party dependency.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying caveviewer with  Cloudflare Pages  Cloudflare Pages

Latest commit: 1e04258
Status: ✅  Deploy successful!
Preview URL: https://eb1de666.caveviewer.pages.dev
Branch Preview URL: https://worktree-fix-csp-cf-analytic.caveviewer.pages.dev

View logs

@MattNotarangelo MattNotarangelo merged commit a2e430d into main Jun 27, 2026
2 checks passed
@MattNotarangelo MattNotarangelo deleted the worktree-fix-csp-cf-analytics branch June 27, 2026 01:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant