: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): match passkey session lookup to the model backend (#113790)
Tom Piccirello7e6afd9cc098
diff --git a/posthog/api/test/test_webauthn.py b/posthog/api/test/test_webauthn.pyindex 8b9978ae5c74..6e60a9c7221a 100644--- a/posthog/api/test/test_webauthn.py+++ b/posthog/api/test/test_webauthn.py@@ -14,6 +14,7 @@ from rest_framework.exceptions import AuthenticationFailedfrom webauthn.helpers import bytes_to_base64urlfrom posthog.api.webauthn import WEBAUTHN_REGISTRATION_CHALLENGE_KEY, WebAuthnLoginViewSet, user_uuid_to_handle+from posthog.auth import WebauthnBackendfrom posthog.models import Organization, Userfrom posthog.models.identity_provider_config import IdentityProviderConfigfrom posthog.models.linked_identity_provider_config import LinkedIdentityProviderConfig@@ -256,6 +257,12 @@ class TestWebAuthnLogin(APIBaseTest):self.assertEqual(me_response.status_code, status.HTTP_200_OK)self.assertEqual(me_response.json()["email"], self.user.email)+ def test_backend_does_not_restore_session_for_inactive_user(self):+ # A queryset update skips the pre_save signal that revokes sessions on deactivation.+ User.objects.filter(pk=self.user.pk).update(is_active=False)++ self.assertIsNone(WebauthnBackend().get_user(self.user.pk))+@patch("posthog.api.webauthn.refuse_blocked_account",side_effect=AuthenticationFailed("We couldn't sign you in.", code="access_blocked"),diff --git a/posthog/auth.py b/posthog/auth.pyindex e1b61f37fa2b..a4074f505075 100644--- a/posthog/auth.py+++ b/posthog/auth.py@@ -1598,7 +1598,7 @@ class WebauthnBackend(BaseBackend):Required by Django's authentication system to load the user on subsequent requests."""try:- return User.objects.get(pk=user_id)+ return User.objects.get(pk=user_id, is_active=True)except User.DoesNotExist:return None