Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions authentik/stages/authenticator_validate/challenge.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,9 +223,7 @@ def validate_challenge_webauthn(
request = stage_view.request
plan = cast(FlowPlan, stage_view.executor.plan)
challenge = plan.context.get(PLAN_CONTEXT_WEBAUTHN_CHALLENGE)
# TODO(ty): the fallback assumes the current stage is an AuthenticatorValidateStage. The
# identification stage passes its `webauthn_stage`, which is None when not configured, so
# a posted passkey there falls back to the IdentificationStage and raises AttributeError.
# Without an explicit stage, this is called from the AuthenticatorValidateStage itself
stage = stage or cast(AuthenticatorValidateStage, stage_view.executor.current_stage)

if "MinuteMaid" in request.META.get("HTTP_USER_AGENT", ""):
Expand Down
10 changes: 5 additions & 5 deletions authentik/stages/authenticator_webauthn/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from functools import lru_cache
from json import loads
from pathlib import Path
from typing import cast

from cryptography import x509
from django.core.cache import cache
Expand All @@ -13,7 +12,7 @@
from dramatiq.actor import actor
from fido2.attestation import verify_x509_chain
from fido2.cose import CoseKey
from fido2.mds3 import MetadataBlobPayload, MetadataStatement, filter_revoked
from fido2.mds3 import MetadataBlobPayload, filter_revoked
from fido2.utils import websafe_decode

from authentik.stages.authenticator_webauthn.models import (
Expand Down Expand Up @@ -86,9 +85,10 @@ def webauthn_mds_import(force=False):
if not filter_revoked(entry):
to_delete.append(str(aaguid))
continue
# TODO(ty): MDS3 entries may omit metadataStatement (parse_mds_blob skips those);
# such an entry with an aaguid would raise AttributeError and abort the whole import
metadata = cast(MetadataStatement, entry.metadata_statement)
# MDS3 entries may omit metadataStatement
metadata = entry.metadata_statement
if metadata is None:
continue
to_create_update.append(
WebAuthnDeviceType(
aaguid=str(aaguid),
Expand Down
3 changes: 3 additions & 0 deletions authentik/stages/identification/stage.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,9 @@ def _validate_passkey_response(self, passkey: dict) -> WebAuthnDevice:
current_stage: IdentificationStage = IdentificationStage.objects.get(
pk=self.stage.executor.current_stage.pk
)
# Passkeys are only offered when a WebAuthn stage is configured
if not current_stage.webauthn_stage:
raise ValidationError(_("Invalid device"), "invalid")
return validate_challenge_webauthn(
passkey, self.stage, self.stage.get_pending_user(), current_stage.webauthn_stage
)
Expand Down
18 changes: 18 additions & 0 deletions authentik/stages/identification/tests.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""identification tests"""

from json import loads
from unittest.mock import patch

from django.urls import reverse
from requests_mock import Mocker
Expand Down Expand Up @@ -107,6 +108,23 @@ def test_passkey_challenge_generation(self):
data = response.json()
self.assertIsNotNone(data.get("passkey_challenge"))

def test_passkey_without_webauthn_stage(self):
"""A posted passkey is rejected when no WebAuthn stage is configured"""
self.stage.webauthn_stage = None
self.stage.save()
url = reverse("authentik_api:flow-executor", kwargs={"flow_slug": self.flow.slug})
self.client.get(url)
with patch(
"authentik.stages.identification.stage.validate_challenge_webauthn",
return_value=self.device,
) as validate:
response = self.client.post(
url, {"passkey": {"id": "test"}}, content_type="application/json"
)
validate.assert_not_called()
self.assertEqual(response.status_code, 200)
self.assertIn("response_errors", response.json())

def test_passkey_no_uid_field_required(self):
"""Test that uid_field is not required when passkey is provided"""
# Get the challenge first to set up the session
Expand Down
Loading