: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(signup): scope resend-invite throttle to per-email (#57684)
Yasenfce03a5c77b4
diff --git a/posthog/api/signup.py b/posthog/api/signup.pyindex 79bc53369bda..62ac1bcf6afb 100644--- a/posthog/api/signup.py+++ b/posthog/api/signup.py@@ -39,7 +39,7 @@ from posthog.models import InviteExpiredException, Organization, OrganizationDomfrom posthog.models.organization_invite import INVITE_DAYS_VALIDITYfrom posthog.models.webauthn_credential import WebauthnCredentialfrom posthog.permissions import CanCreateOrg-from posthog.rate_limit import SignupEmailPrecheckThrottle, SignupIPThrottle+from posthog.rate_limit import SignupEmailPrecheckThrottle, SignupIPThrottle, SignupResendInviteThrottlefrom posthog.utils import get_can_create_org, is_relative_urlfrom posthog.workos_radar import RadarAction, RadarAuthMethod, evaluate_auth_attempt@@ -409,7 +409,7 @@ class SignupResendInviteViewset(generics.GenericAPIView):serializer_class = SignupResendInviteSerializerpermission_classes = (permissions.AllowAny,)- throttle_classes = [] if settings.E2E_TESTING else [SignupEmailPrecheckThrottle]+ throttle_classes = [] if settings.E2E_TESTING else [SignupResendInviteThrottle]def post(self, request: Request, *args: Any, **kwargs: Any) -> response.Response:serializer = self.get_serializer(data=request.data)diff --git a/posthog/api/test/test_signup.py b/posthog/api/test/test_signup.pyindex 9313090dd16d..d108e798fe4a 100644--- a/posthog/api/test/test_signup.py+++ b/posthog/api/test/test_signup.py@@ -2939,6 +2939,7 @@ class TestSignupPrecheckPendingInvite(APIBaseTest):class TestSignupResendInvite(APIBaseTest):def setUp(self):+ cache.clear()super().setUp()self.client.logout()@@ -2987,3 +2988,32 @@ class TestSignupResendInvite(APIBaseTest):# Status reflects that an invite exists, but no email goes out.self.assertEqual(response.json(), {"sent": True})mock_send.assert_not_called()++ @patch("posthog.api.signup.is_email_available", return_value=True)+ @patch("posthog.tasks.email.send_invite.apply_async")+ def test_resend_invite_throttles_per_email_after_five_requests(self, _mock_send, _mock_email_available):+ self._create_invite("[email protected]")+ for i in range(6):+ response = self.client.post("/api/signup/resend-invite", {"email": "[email protected]"})+ if i < 5:+ self.assertEqual(response.status_code, status.HTTP_200_OK)+ else:+ self.assertEqual(response.status_code, status.HTTP_429_TOO_MANY_REQUESTS)+ self.assertLessEqual(+ {"attr": None, "code": "throttled", "type": "throttled_error"}.items(),+ response.json().items(),+ )++ @patch("posthog.api.signup.is_email_available", return_value=True)+ @patch("posthog.tasks.email.send_invite.apply_async")+ def test_resend_invite_throttle_is_per_email_not_global(self, _mock_send, _mock_email_available):+ self._create_invite("[email protected]")+ self._create_invite("[email protected]")+ # Exhaust alice's bucket+ for _ in range(5):+ self.client.post("/api/signup/resend-invite", {"email": "[email protected]"})+ alice_blocked = self.client.post("/api/signup/resend-invite", {"email": "[email protected]"})+ self.assertEqual(alice_blocked.status_code, status.HTTP_429_TOO_MANY_REQUESTS)+ # Bob still has a fresh bucket+ bob_ok = self.client.post("/api/signup/resend-invite", {"email": "[email protected]"})+ self.assertEqual(bob_ok.status_code, status.HTTP_200_OK)diff --git a/posthog/rate_limit.py b/posthog/rate_limit.pyindex dd66990ad10c..4ea7887e667a 100644--- a/posthog/rate_limit.py+++ b/posthog/rate_limit.py@@ -346,6 +346,19 @@ class SignupEmailPrecheckThrottle(IPThrottle):rate = "30/minute"+class SignupResendInviteThrottle(UserOrEmailRateThrottle):+ """+ Rate limit signup invite-resend requests per email address.++ Resending an invite triggers a real email side effect, so the per-email cap+ bounds inbox spam to a victim regardless of how many IPs an attacker rotates+ through.+ """++ scope = "signup_resend_invite"+ rate = "5/hour"++class BurstRateThrottle(PersonalApiKeyRateThrottle):# Throttle class that's applied on all endpoints (except for capture + decide)# Intended to block quick bursts of requests, per project