: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(sharing): never enable dashboard sharing from a read (#68663)
posthog[bot]a19a6a744357
diff --git a/posthog/api/sharing.py b/posthog/api/sharing.pyindex b22e56ade912..92bb003db37f 100644--- a/posthog/api/sharing.py+++ b/posthog/api/sharing.py@@ -445,7 +445,11 @@ class SharingConfigurationViewSet(TeamAndOrgViewSetMixin, mixins.ListModelMixin,dashboard.is_shared = Falsedashboard.save(update_fields=["share_token", "is_shared"])else:- instance.enabled = dashboard.is_shared+ # The legacy token isn't owned by any config, so adopt it onto this one. Only+ # migrate the token, never ``enabled``: this helper runs on the read path+ # (``list``), and ``dashboard.is_shared`` is a deprecated field holding stale+ # legacy data, so enabling off it would let a plain GET silently make a+ # dashboard public. Sharing is only ever turned on through an explicit PATCH.instance.access_token = dashboard.share_tokeninstance.save()diff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.pyindex 05732c449dd9..4630765166b1 100644--- a/posthog/api/test/test_sharing.py+++ b/posthog/api/test/test_sharing.py@@ -253,7 +253,7 @@ class TestSharing(APIBaseTest):assert asset.export_format == "image/png"@patch("products.exports.backend.api.exports.ExportedAssetSerializer._start_export_workflow")- def test_should_update_to_match_existing_dashboard_sharing_token(self, patched_exporter_task: Mock):+ def test_should_adopt_legacy_share_token_on_read_without_enabling(self, patched_exporter_task: Mock):dashboard = Dashboard.objects.create(team=self.team, name="example dashboard", created_by=self.user)response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}/sharing")initial_token = response.json()["access_token"]@@ -264,10 +264,12 @@ class TestSharing(APIBaseTest):dashboard.is_shared = Truedashboard.save()+ # A read adopts the legacy token onto the config, but must not turn sharing on: a stale+ # legacy is_shared=True can never make a private dashboard public without an explicit PATCH.response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}/sharing")data = response.json()assert data["access_token"] == "my_test_token"- assert data["enabled"]+ assert not data["enabled"]dashboard.share_token = Nonedashboard.is_shared = False@@ -276,7 +278,34 @@ class TestSharing(APIBaseTest):response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}/sharing")data = response.json()assert data["access_token"] == "my_test_token"- assert data["enabled"]+ assert not data["enabled"]++ @patch("products.exports.backend.api.exports.ExportedAssetSerializer._start_export_workflow")+ def test_read_does_not_enable_sharing_from_stale_legacy_is_shared(self, _patched_exporter_task: Mock):+ # An active (disabled) config exists with one token while the dashboard still carries a stale+ # legacy share_token + is_shared=True pointing at a different token. Reading the sharing config+ # must never persist enabled=True: a plain GET can't make a private dashboard publicly reachable.+ dashboard = Dashboard.objects.create(team=self.team, name="critical dashboard", created_by=self.user)+ active_config = SharingConfiguration.objects.create(+ team=self.team,+ dashboard=dashboard,+ enabled=False,+ access_token="active_token",+ )+ dashboard.share_token = "stale_legacy_token"+ dashboard.is_shared = True+ dashboard.save(update_fields=["share_token", "is_shared"])++ response = self.client.get(f"/api/projects/{self.team.id}/dashboards/{dashboard.id}/sharing")++ assert response.status_code == status.HTTP_200_OK+ assert not response.json()["enabled"]+ active_config.refresh_from_db()+ assert active_config.enabled is False+ # No active config for this dashboard may end up enabled off the back of a read.+ assert not SharingConfiguration.objects.filter(+ dashboard=dashboard, expires_at__isnull=True, enabled=True+ ).exists()@patch("products.exports.backend.api.exports.ExportedAssetSerializer._start_export_workflow")def test_should_not_be_affected_by_collaboration_rules(self, _patched_exporter_task: Mock):