: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.
Python ab-testingai-analyticsanalyticscdpdata-warehouseexperimentsfeature-flagsjavascriptproduct-analyticspythonreactsession-replaysurveystypescriptweb-analytics
fix(csp): leave frame-ancestors out of the embed report-only policy (#106971)
Tom Piccirelloca2ccfab50d2
diff --git a/posthog/csp_middleware.py b/posthog/csp_middleware.pyindex be3e3a6656ed..d487bb19c59b 100644--- a/posthog/csp_middleware.py+++ b/posthog/csp_middleware.py@@ -379,6 +379,12 @@ class CSPMiddleware:# without this origin a staff logout is cancelled with nothing shown to the user."form-action 'self' https://accounts.google.com",]+ if is_embeddable_document(request.path):+ # Customers frame these documents on their own sites, and no list of ancestors can+ # name every such site. In a report-only policy the directive only sends a report for+ # each embed. Chrome cuts the document URL of that report to the origin, so it looks+ # the same as a report from an app page that the browser blocks in a frame.+ csp_parts.remove(frame_ancestors)# The hosts and the config token below belong to PostHog Cloud, so self-hosted installs, E2E# runs and the dev environment keep the wildcards. A load from a PostHog host that is notdiff --git a/posthog/test/test_csp_middleware.py b/posthog/test/test_csp_middleware.pyindex 8c0e4ca27279..61e169df48a9 100644--- a/posthog/test/test_csp_middleware.py+++ b/posthog/test/test_csp_middleware.py@@ -116,7 +116,7 @@ class TestCSPMiddleware(APIBaseTest):embedded = self.client.get("/shared/notarealtoken")assert "Content-Security-Policy" not in embedded- assert "frame-ancestors" in embedded["Content-Security-Policy-Report-Only"]+ assert "frame-ancestors" not in embedded["Content-Security-Policy-Report-Only"]@override_settings(CLOUD_DEPLOYMENT="US") # As PostHog Clouddef test_html_response_declares_default_reporting_endpoint_with_distinct_id(self):