: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(auth): extend login verification code TTL to 30 minutes (#70756)
Yasen9572937fdd90
diff --git a/posthog/api/test/test_code_based_verification.py b/posthog/api/test/test_code_based_verification.pyindex 3fef17685d71..116ae2380bd5 100644--- a/posthog/api/test/test_code_based_verification.py+++ b/posthog/api/test/test_code_based_verification.py@@ -99,7 +99,7 @@ class TestCodeBasedVerificationAPI(APIBaseTest):def test_expired_code_is_rejected(self):with freeze_time("2024-01-01T10:00:00") as frozen, enable_code_sending() as mock_send:code = self._trigger(mock_send)- frozen.move_to("2024-01-01T10:10:01") # > 10 minute TTL+ frozen.move_to("2024-01-01T10:30:01") # > 30 minute TTLresponse = self.client.post(VERIFY_URL, {"code": code})self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)self.assertEqual(response.json()["code"], "invalid_code")diff --git a/posthog/helpers/two_factor_session.py b/posthog/helpers/two_factor_session.pyindex 810ad8c099d7..05da64f0ff25 100644--- a/posthog/helpers/two_factor_session.py+++ b/posthog/helpers/two_factor_session.py@@ -288,7 +288,7 @@ def is_sso_authentication_backend(request: HttpRequest):CODE_LENGTH = 6-CODE_TTL_SECONDS = 600 # 10 minutes+CODE_TTL_SECONDS = 1800 # 30 minutesCODE_MAX_ATTEMPTS = 5# Failed-attempt budget for a pending login is tracked in Redis so the cap is enforced atomically# (INCR) rather than via a raceable session read-modify-write, which parallel guesses could sidestep.diff --git a/posthog/tasks/email.py b/posthog/tasks/email.pyindex e6d25dac07cf..699c9f87c8d9 100644--- a/posthog/tasks/email.py+++ b/posthog/tasks/email.py@@ -22,6 +22,7 @@ from posthog.email import EMAIL_TASK_KWARGS, EmailMessage, is_email_availablefrom posthog.event_usage import groupsfrom posthog.geoip import get_geoip_propertiesfrom posthog.helpers.email_utils import sanitize_display_name, sanitize_message_body+from posthog.helpers.two_factor_session import CODE_TTL_SECONDSfrom posthog.models import Organization, OrganizationInvite, OrganizationMembership, PersonalAPIKey, Team, Userfrom posthog.models.activity_logging.activity_log import ActivityLogfrom posthog.models.comment import Comment@@ -484,7 +485,7 @@ def send_code_based_verification(user_id: int, code: str) -> None:template_context={"preheader": "Enter this code to verify your login.","code": code,- "expiration_minutes": 10,+ "expiration_minutes": CODE_TTL_SECONDS // 60,"site_url": settings.SITE_URL,},)