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: admins see feature flags with default no access in list (#58368)

Reece Jonesbcb7f962423a
diff --git a/posthog/api/routing.py b/posthog/api/routing.py
index e62728b7f851..eb6e8b136f6b 100644
--- a/posthog/api/routing.py
+++ b/posthog/api/routing.py
@@ -261,8 +261,8 @@ class TeamAndOrgViewSetMixin(_GenericViewSet): # TODO: Rename to include "Env"
# NOTE: Half implemented - for admins, they may want to include listing of results that are not accessible (like private resources)
include_all_if_admin = self.request.GET.get("admin_include_all") == "true"
- # Projects and dashboards: org admins have implicit access; list must match retrieve (see issue #44364).
- if self.scope_object in ("project", "dashboard"):
+ # Projects, dashboards, feature flags: org admins have implicit access; list must match retrieve (see issue #44364).
+ if self.scope_object in ("project", "dashboard", "feature_flag"):
include_all_if_admin = True
# "insights" are a special case where we want to use include_all_if_admin if listing with short_id because
diff --git a/posthog/api/test/test_feature_flag.py b/posthog/api/test/test_feature_flag.py
index 87b4a7af1364..a674aa98946e 100644
--- a/posthog/api/test/test_feature_flag.py
+++ b/posthog/api/test/test_feature_flag.py
@@ -8590,6 +8590,76 @@ class TestFeatureFlag(APIBaseTest, ClickhouseTestMixin):
status_response = self.client.get(f"/api/projects/{self.team.pk}/feature_flags/{flag.id}/status/")
self.assertEqual(status_response.status_code, status.HTTP_403_FORBIDDEN)
+ def test_org_admin_can_list_flag_with_default_none_after_grantee_removed(self) -> None:
+ # Regression: a flag with a team-wide "none" default plus a single explicit
+ # editor grant becomes invisible to everyone once the grantee is removed
+ # from the org (their AccessControl row cascade-deletes). Org admins should
+ # still be able to find such orphaned flags in the list endpoint.
+ self.organization.available_product_features = [
+ {"key": AvailableFeature.ADVANCED_PERMISSIONS, "name": AvailableFeature.ADVANCED_PERMISSIONS},
+ {"key": AvailableFeature.ROLE_BASED_ACCESS, "name": AvailableFeature.ROLE_BASED_ACCESS},
+ ]
+ self.organization.save()
+
+ creator = self._create_user("[email protected]", level=OrganizationMembership.Level.MEMBER)
+ grantee = self._create_user("[email protected]", level=OrganizationMembership.Level.MEMBER)
+ grantee_membership = grantee.organization_memberships.get(organization=self.organization)
+
+ flag = FeatureFlag.objects.create(
+ team=self.team,
+ created_by=creator,
+ name="orphaned flag",
+ key="orphaned-flag",
+ )
+ # Team-wide "no access" default for this flag
+ AccessControl.objects.create(resource="feature_flag", resource_id=flag.id, team=self.team, access_level="none")
+ # Single explicit editor grant for the grantee
+ AccessControl.objects.create(
+ resource="feature_flag",
+ resource_id=flag.id,
+ team=self.team,
+ organization_member=grantee_membership,
+ access_level="editor",
+ )
+
+ # self.user is the org admin via APIBaseTest setup
+ self.organization_membership.level = OrganizationMembership.Level.ADMIN
+ self.organization_membership.save()
+
+ # Remove the grantee from the org -> cascade deletes their explicit grant
+ grantee_membership.delete()
+
+ # Org admin must still see the flag in the list (it's an orphaned flag now)
+ list_response = self.client.get(f"/api/projects/{self.team.pk}/feature_flags/")
+ self.assertEqual(list_response.status_code, status.HTTP_200_OK)
+ keys = [f["key"] for f in list_response.json()["results"]]
+ self.assertIn("orphaned-flag", keys)
+
+ def test_member_still_blocked_from_listing_default_none_flag(self) -> None:
+ # Counterpart to the test above: non-admin members without an explicit
+ # grant must still be filtered out by the per-object "none" default.
+ self.organization.available_product_features = [
+ {"key": AvailableFeature.ADVANCED_PERMISSIONS, "name": AvailableFeature.ADVANCED_PERMISSIONS},
+ {"key": AvailableFeature.ROLE_BASED_ACCESS, "name": AvailableFeature.ROLE_BASED_ACCESS},
+ ]
+ self.organization.save()
+
+ other = self._create_user("[email protected]", level=OrganizationMembership.Level.MEMBER)
+
+ flag = FeatureFlag.objects.create(
+ team=self.team,
+ created_by=self.user,
+ name="blocked flag",
+ key="blocked-flag",
+ )
+ AccessControl.objects.create(resource="feature_flag", resource_id=flag.id, team=self.team, access_level="none")
+
+ self.client.force_login(other)
+ list_response = self.client.get(f"/api/projects/{self.team.pk}/feature_flags/")
+ self.assertEqual(list_response.status_code, status.HTTP_200_OK)
+ keys = [f["key"] for f in list_response.json()["results"]]
+ self.assertNotIn("blocked-flag", keys)
+
class TestCohortGenerationForFeatureFlag(APIBaseTest, ClickhouseTestMixin):
def test_creating_static_cohort_with_deleted_flag(self):