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 canvas event capture under the cloud app policy (#113387)

Tom Piccirello95d98257c84e
diff --git a/posthog/csp_middleware.py b/posthog/csp_middleware.py
index 6d3feb499bc5..4f779089e5b3 100644
--- a/posthog/csp_middleware.py
+++ b/posthog/csp_middleware.py
@@ -452,6 +452,8 @@ class CSPMiddleware:
f"https://webhooks.{urlsplit(settings.SITE_URL).hostname}",
# The onboarding adblock check probes the region's ingestion host.
f"{get_api_host()}/decide/",
+ # The canvas bridge posts each ph.capture() event to the region's capture endpoint.
+ f"{get_api_host()}/i/v0/e/",
# A task run's live stream, when the server hands out the region's agent-proxy.
*agent_proxy,
],
diff --git a/posthog/test/test_csp_middleware.py b/posthog/test/test_csp_middleware.py
index 563f1af1031d..94acef049f14 100644
--- a/posthog/test/test_csp_middleware.py
+++ b/posthog/test/test_csp_middleware.py
@@ -379,6 +379,9 @@ class TestCSPMiddleware(APIBaseTest):
assert f"https://live.{region}.posthog.com" in connect_src
assert f"https://webhooks.{region}.posthog.com" in connect_src
assert f"https://{region}.i.posthog.com/decide/" in connect_src
+ assert f"https://{region}.i.posthog.com/i/v0/e/" in connect_src
+ # The bare origin would admit every endpoint on the ingestion host, not only the paths the app calls.
+ assert f"https://{region}.i.posthog.com" not in connect_src
assert f"https://agent-proxy.{region}.posthog.com" in connect_src
# Allowing the other region would hide a request that crossed regions by mistake.
assert not any(other_region in (urlsplit(source).hostname or "").split(".") for source in connect_src)