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): let firefox preload the app bundle (#103950)

Tom Piccirello61557c854866
diff --git a/posthog/middleware.py b/posthog/middleware.py
index dfdfca83455a..19da3b70b082 100644
--- a/posthog/middleware.py
+++ b/posthog/middleware.py
@@ -1469,7 +1469,11 @@ class CSPMiddleware:
connect_debug_url = "ws://localhost:8234" if settings.DEBUG or settings.TEST else ""
csp_parts = [
- "default-src 'self'",
+ # Firefox checks <link rel="modulepreload"> against default-src instead of script-src,
+ # so without the static host it refuses the preloads index.html emits for the boot
+ # chain. The fetch directives below each set their own sources, so only a load a
+ # browser cannot map to one of them falls back to this list.
+ f"default-src 'self' {resource_url}",
f"style-src 'self' 'unsafe-inline' {resource_url} https://fonts.googleapis.com",
# 'wasm-unsafe-eval' permits WebAssembly compilation and nothing else. It is not
# 'unsafe-eval': it does not permit eval() or the Function constructor. Compiling a
diff --git a/posthog/test/test_middleware.py b/posthog/test/test_middleware.py
index 225b2e144c7f..ab3e82874a4e 100644
--- a/posthog/test/test_middleware.py
+++ b/posthog/test/test_middleware.py
@@ -2182,6 +2182,12 @@ class TestCSPMiddleware(APIBaseTest):
response = self.client.get("/")
assert "frame-src 'self' https:" in response["Content-Security-Policy-Report-Only"]
+ def test_app_policy_lets_firefox_preload_the_app_bundle(self):
+ # Firefox judges <link rel="modulepreload"> by default-src, not script-src. A default-src of
+ # 'self' alone refuses every preload index.html emits for the boot chain.
+ response = self.client.get("/")
+ assert "default-src 'self' http://localhost:8234" in response["Content-Security-Policy-Report-Only"]
+
def test_replay_player_frame_serves_the_mount_node_without_a_session(self):
# Shared recordings render the player for logged-out viewers.
self.client.logout()