Skip to content

feat: Cloudflare Web Analytics のスクリプトと送り先を CSP で許可する - #7

Merged
t1nyb0x merged 1 commit into
developfrom
feat/csp-cloudflare-insights
Oct 11, 2026
Merged

t1nyb0x merged 1 commit into
developfrom
feat/csp-cloudflare-insights

Conversation

@t1nyb0x

@t1nyb0x t1nyb0x commented Oct 11, 2026

Copy link
Copy Markdown
Member

なぜ

本番の lumorphia.com で、Cloudflare が配信のときに自動で差し込む Web Analytics のスクリプト (https://static.cloudflareinsights.com/beacon.min.js/...) が、CSP の script-src 'self' で止められていた。コンソールに違反が出て、計測も取れていない。

変えたこと

  • script-src に https://static.cloudflareinsights.com、connect-src に計測の送り先 https://cloudflareinsights.com を足す
  • 本番の _headers (scripts/build.mjs)、プレビュー (scripts/serve.mjs)、README の CSP を同じにする

ほかのオリジンは足さない。'unsafe-inline' も使わない (差し込まれるのは外部のスクリプトの読み込みだけ)。

確かめたこと

  • npm test (13 件) と npm run check が通る。CSP のテストは、先に新しい値に変えて落ちることを確かめた

本番では、リリースの後にブラウザのコンソールで CSP の違反が消えたことを確かめる。

🤖 Generated with Claude Code

Cloudflare が配信のときに自動で差し込む Web Analytics のスクリプト
(static.cloudflareinsights.com) が script-src 'self' で止められ、本番のコンソールに
CSP の違反が出ていた。script-src に static.cloudflareinsights.com、connect-src に
計測の送り先の cloudflareinsights.com を足す (本番の _headers、プレビュー、README)。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@cloudflare-workers-and-pages

cloudflare-workers-and-pages Bot commented Oct 11, 2026 •

Copy link
Copy Markdown

🚀 Deploying Preview to Cloudflare 🚀

Preview Deployments by commit

Status Deployment URL Commit Updated (UTC) See this deployment's details
  • Build: Failed ❌

View logs ↗
9a9a83c 2026-10-11T09:24:18.464Z View logs ↗

@t1nyb0x
t1nyb0x merged commit 391099f into develop Oct 11, 2026
1 of 2 checks passed
@t1nyb0x
t1nyb0x deleted the feat/csp-cloudflare-insights branch October 11, 2026 09:28
t1nyb0x added a commit that referenced this pull request Oct 11, 2026
release: ログインの入口を出し、Cloudflare Web Analytics を CSP で許可する (#6, #7)
t1nyb0x added a commit that referenced this pull request Oct 11, 2026
#7 で connect-src に cloudflareinsights.com を足したが、Cloudflare を通しているサイトでは
beacon は同じサイトの /cdn-cgi/rum に送るので、本番で connect-src の違反が出ていた。
connect-src に 'self' を足す。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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