Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(csp): allow the Stripe and Turnstile scripts (#99736)

Tom Piccirello16b85821da40
diff --git a/posthog/middleware.py b/posthog/middleware.py
index 205153de2de0..816fc4c408a4 100644
--- a/posthog/middleware.py
+++ b/posthog/middleware.py
@@ -1325,7 +1325,15 @@ class CSPMiddleware:
# nothing to an attacker who cannot already run script, and nothing further to one who
# can. Session replay decompresses snapshots with snappy-wasm and the HogQL editor
# parses with a WebAssembly build, so both break without it.
- f"script-src 'self' 'nonce-{nonce}' 'wasm-unsafe-eval' {resource_url} https://*.i.posthog.com",
+ #
+ # Stripe and Turnstile are the two scripts we cannot serve ourselves: both vendors
+ # require the file to load from their own origin, so the flag-font trick of shipping
+ # a copy does not apply. `loadStripe` injects js.stripe.com for the payment entry
+ # modal, and the signup captcha loads the Turnstile API. `frame-src 'self' https:`
+ # already admits the iframes each one opens, and neither produced a connect-src
+ # violation while this policy was report-only, so their API calls run inside those
+ # frames rather than from our page.
+ f"script-src 'self' 'nonce-{nonce}' 'wasm-unsafe-eval' {resource_url} https://*.i.posthog.com https://js.stripe.com https://challenges.cloudflare.com",
# A data: font cannot execute script, and this directive governs font loading only,
# so the token widens nothing else. It also carries nothing out: a data: URL makes
# no request, which is what the CSS-injection attacks on this directive need. The