: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: apply organization-level sharing to exported assets (#59523)
Reece Jonese53df8880dfe
diff --git a/posthog/api/sharing.py b/posthog/api/sharing.pyindex b1b74d893336..0a859dbf8155 100644--- a/posthog/api/sharing.py+++ b/posthog/api/sharing.py@@ -781,10 +781,8 @@ class SharingViewerPageViewSet(mixins.RetrieveModelMixin, viewsets.GenericViewSeif not resource:return custom_404_response(self.request)- # Check if organization allows publicly shared resourcesif (- isinstance(resource, SharingConfiguration)- and resource.team.organization.is_feature_available(AvailableFeature.ORGANIZATION_SECURITY_SETTINGS)+ resource.team.organization.is_feature_available(AvailableFeature.ORGANIZATION_SECURITY_SETTINGS)and not resource.team.organization.allow_publicly_shared_resources):return custom_404_response(self.request)diff --git a/posthog/api/test/test_sharing.py b/posthog/api/test/test_sharing.pyindex 84534829851b..44cdd0fe50df 100644--- a/posthog/api/test/test_sharing.py+++ b/posthog/api/test/test_sharing.py@@ -1023,6 +1023,86 @@ class TestSharingConfigurationSerializerValidation(APIBaseTest):response = self.client.get(f"/shared/{access_token}")assert response.status_code == 404+ @patch("posthog.models.exported_asset.object_storage.get_presigned_url")+ @patch("posthog.api.exports.ExportedAssetSerializer._start_export_workflow")+ def test_exported_asset_public_url_blocked_when_organization_disallows_public_sharing(+ self, _patched_exporter_task: Mock, patched_get_presigned_url: Mock+ ):+ """+ Regression test: previously, disabling org-level public sharing only blocked+ `/shared/<token>` (SharingConfiguration path) but left `/exporter/...?token=<jwt>`+ (ExportedAsset public token path) returning content. Both surfaces must respect+ the kill switch.+ """+ patched_get_presigned_url.return_value = "https://s3.example.com/presigned-url"+ self.organization.available_product_features = [+ {"key": AvailableFeature.ORGANIZATION_SECURITY_SETTINGS, "name": "organization_security_settings"},+ ]+ self.organization.save()++ # Enable sharing and create a publicly-accessible ExportedAsset for the dashboard.+ response = self.client.patch(+ f"/api/projects/{self.team.id}/dashboards/{self.dashboard.id}/sharing",+ {"enabled": True},+ )+ assert response.status_code == status.HTTP_200_OK++ asset = ExportedAsset.objects.create(+ team=self.team,+ dashboard=self.dashboard,+ export_format=ExportedAsset.ExportFormat.PNG,+ content_location="some object url",+ )+ exporter_url = asset.get_public_content_url()++ # Sanity check: public token URL works while public sharing is allowed.+ response = self.client.get(exporter_url)+ assert response.status_code == 302++ # Disable public sharing at the org level.+ self.organization.allow_publicly_shared_resources = False+ self.organization.save()++ # ExportedAsset public token URL must now be blocked, same as /shared/...+ response = self.client.get(exporter_url)+ assert response.status_code == 404++ @patch("posthog.models.exported_asset.object_storage.get_presigned_url")+ @patch("posthog.api.exports.ExportedAssetSerializer._start_export_workflow")+ def test_exported_asset_public_url_blocked_for_password_protected_share_when_disallowed(+ self, _patched_exporter_task: Mock, patched_get_presigned_url: Mock+ ):+ """+ A known ExportedAsset public token URL must not bypass the org-level kill switch even+ when the underlying SharingConfiguration is password-protected.+ """+ patched_get_presigned_url.return_value = "https://s3.example.com/presigned-url"+ self.organization.available_product_features = [+ {"key": AvailableFeature.ORGANIZATION_SECURITY_SETTINGS, "name": "organization_security_settings"},+ {"key": AvailableFeature.ACCESS_CONTROL, "name": "access_control"},+ ]+ self.organization.save()++ SharingConfiguration.objects.create(+ team=self.team,+ dashboard=self.dashboard,+ enabled=True,+ password_required=True,+ )+ asset = ExportedAsset.objects.create(+ team=self.team,+ dashboard=self.dashboard,+ export_format=ExportedAsset.ExportFormat.PNG,+ content_location="some object url",+ )+ exporter_url = asset.get_public_content_url()++ self.organization.allow_publicly_shared_resources = False+ self.organization.save()++ response = self.client.get(exporter_url)+ assert response.status_code == 404+class TestSharePasswordLogging(APIBaseTest):"""Test the _log_share_password_attempt function for activity logging"""