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.

feat(auth): add passkey-2fa toggle to user admin (#60568)

Alex Lider5ac3152df76a
diff --git a/posthog/admin/admins/user_admin.py b/posthog/admin/admins/user_admin.py
index c34cea49d84b..571ff45690c2 100644
--- a/posthog/admin/admins/user_admin.py
+++ b/posthog/admin/admins/user_admin.py
@@ -49,6 +49,14 @@ class UserChangeForm(DjangoUserChangeForm):
return is_staff
+ def clean_passkeys_enabled_for_2fa(self):
+ # Mirror the API-side guard in UserSerializer.validate_passkeys_enabled_for_2fa:
+ # only allow enabling if the user has a verified passkey.
+ value = bool(self.cleaned_data.get("passkeys_enabled_for_2fa", False))
+ if value and not WebauthnCredential.objects.filter(user=self.instance, verified=True).exists():
+ raise ValidationError("Cannot enable passkeys for 2FA — this user has no verified passkey.")
+ return value
+
@admin.register(User)
class UserAdmin(DjangoUserAdmin):
@@ -81,6 +89,7 @@ class UserAdmin(DjangoUserAdmin):
"strapi_id",
"revoke_sessions_link",
"two_factor_status",
+ "passkeys_enabled_for_2fa",
"allow_impersonation",
)
},
diff --git a/posthog/admin/test_admin.py b/posthog/admin/test_admin.py
index 7e9103ef1a21..58350158aa20 100644
--- a/posthog/admin/test_admin.py
+++ b/posthog/admin/test_admin.py
@@ -7,7 +7,7 @@ from django.test import RequestFactory
from posthog.admin import _OAUTH_ADMIN_MODEL_NAMES, install_admin_app_list_overrides
from posthog.admin.admins.event_ingestion_restriction_config import EventIngestionRestrictionConfigAdmin
-from posthog.admin.admins.user_admin import UserAdmin
+from posthog.admin.admins.user_admin import UserAdmin, UserChangeForm
from posthog.admin.inlines.organization_member_inline import OrganizationMemberForUserInline, OrganizationMemberInline
from posthog.models import User
from posthog.models.event_ingestion_restriction_config import EventIngestionRestrictionConfig
@@ -111,6 +111,14 @@ class TestUserAdmin(BaseTest):
assert self.search_user_ids("missing-distinct-id") == []
+ def test_clean_passkeys_enabled_for_2fa_rejects_when_user_has_no_verified_passkey(self) -> None:
+ from django.core.exceptions import ValidationError
+
+ form = UserChangeForm(instance=self.user)
+ form.cleaned_data = {"passkeys_enabled_for_2fa": True}
+ with self.assertRaises(ValidationError):
+ form.clean_passkeys_enabled_for_2fa()
+
class TestPluginAttachmentInline(BaseTest):
def test_parsed_json_escapes_html_in_values(self):