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(messaging): let API keys read the suppression list, with person:read (#82020)

Sean Mallia9e16eaa94f8c
diff --git a/products/messaging/backend/api/message_suppression.py b/products/messaging/backend/api/message_suppression.py
index 18a6648e899d..04e22c37a628 100644
--- a/products/messaging/backend/api/message_suppression.py
+++ b/products/messaging/backend/api/message_suppression.py
@@ -96,7 +96,8 @@ class MessageSuppressionViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
scope_object = "hog_flow"
# Custom actions must declare their write status so TeamAndOrgViewSetMixin's AccessControlPermission
- # checks hog_flow:write on the mutating endpoints; the default 'suppressions' list stays a read.
+ # checks hog_flow:write on the mutating endpoints. `suppressions` is scoped by its own
+ # `required_scopes` instead, since it needs person:read on top of the workflow scope.
scope_object_write_actions = ["add_suppression", "remove_suppression"]
serializer_class = _FallbackSerializer
@@ -108,7 +109,12 @@ class MessageSuppressionViewSet(TeamAndOrgViewSetMixin, viewsets.ViewSet):
responses={200: PaginatedMessageSuppressionSerializer},
summary="List suppressed email addresses for the team",
)
- @action(detail=False, methods=["get"])
+ # The rows carry recipient email addresses and their SMTP diagnostics, so reading them is
+ # person-data access on top of workflow read — same rationale as the `assets` and
+ # `user_blast_radius` actions on HogFlowViewSet. Without `person:read` a workflow-only token
+ # could enumerate who a team emails, and probe whether a given address is known by paging for
+ # it. The UI uses session auth, which skips scope checks, so the suppression list is unaffected.
+ @action(detail=False, methods=["get"], required_scopes=["hog_flow:read", "person:read"])
def suppressions(self, request: Request, **kwargs: Any) -> Response:
"""List suppressed recipients for the team, most recently updated first."""
# Resource-level check: `AccessControlPermission` only guarantees the caller has some
diff --git a/products/messaging/backend/api/test/test_message_suppression.py b/products/messaging/backend/api/test/test_message_suppression.py
index dff6728e39b3..d5198e107639 100644
--- a/products/messaging/backend/api/test/test_message_suppression.py
+++ b/products/messaging/backend/api/test/test_message_suppression.py
@@ -2,6 +2,11 @@ from posthog.test.base import APIBaseTest
from django.test import SimpleTestCase
+from parameterized import parameterized
+
+from posthog.models.personal_api_key import PersonalAPIKey
+from posthog.models.utils import generate_random_token_personal, hash_key_value
+
from products.messaging.backend.api.message_suppression import MessageSuppressionViewSet
from products.messaging.backend.models.message_suppression import MessageSuppression, SuppressionSource
@@ -24,6 +29,43 @@ class TestMessageSuppressionViewSetScope(SimpleTestCase):
}
+class TestSuppressionListPersonalAPIKeyAccess(APIBaseTest):
+ """
+ Guards the token scopes on the read action. It needs both hog_flow:read and person:read, so
+ neither alone opens up the recipient addresses and SMTP diagnostics the rows carry. Session auth
+ skips scope checks entirely, so only a token exercises this.
+ """
+
+ def _key(self, scopes: list[str]) -> str:
+ value = generate_random_token_personal()
+ PersonalAPIKey.objects.create(
+ label="Test",
+ user=self.user,
+ secure_value=hash_key_value(value),
+ scopes=scopes,
+ )
+ return value
+
+ @parameterized.expand(
+ [
+ (["hog_flow:read", "person:read"], 200),
+ (["hog_flow:read"], 403),
+ (["person:read"], 403),
+ ]
+ )
+ def test_suppressions_read_requires_both_scopes(self, scopes: list[str], expected_status: int) -> None:
+ self.client.logout()
+
+ response = self.client.get(
+ f"/api/projects/{self.team.id}/messaging_suppressions/suppressions/",
+ HTTP_AUTHORIZATION=f"Bearer {self._key(scopes)}",
+ )
+
+ assert response.status_code == expected_status, response.json()
+ if expected_status == 200:
+ assert set(response.json()) == {"count", "next", "previous", "results"}
+
+
class TestRemoveSuppressionResetsSource(APIBaseTest):
"""
Guards against a regression where remove_suppression keeps source='MANUAL' on the removed row.