Skip to content

stages/authenticator_validate: reject malformed WebAuthn assertions as an invalid device - #27479

Merged
BeryJu merged 1 commit into
goauthentik:mainfrom
ryanpesek:stages/authenticator_validate-malformed-webauthn
Dec 1, 2026
Merged

BeryJu merged 1 commit into
goauthentik:mainfrom
ryanpesek:stages/authenticator_validate-malformed-webauthn

Conversation

@ryanpesek

Copy link
Copy Markdown
Contributor

Details

What does this PR change?

validate_challenge_webauthn() only caught InvalidJSONStructure from parse_authentication_credential_json(). When a credential field isn't valid base64url, py_webauthn raises InvalidAuthenticationResponse instead. For response.userHandle it doesn't wrap the error at all, so a bare ValueError (binascii.Error) comes through. Both reached the flow executor, which answered with the flow error and created a system_exception event.

It now catches WebAuthnException and ValueError around the parse and answers "Invalid device", as it already did for InvalidJSONStructure. The WebAuthn setup stage catches the same pair around verify_registration_response(). This covers both callers: the authenticator validation stage and the identification stage's passkey login.

Why is this change needed?

Anyone can post an assertion to a passwordless flow without logging in first. A malformed one is a client error, but it currently creates a system_exception event.

How was this tested?

  • New tests in authentik/stages/authenticator_validate/tests/test_webauthn.py, which fail without the fix:
    • test_validate_challenge_malformed: validate_challenge_webauthn() with a rawId, clientDataJSON or authenticatorData that isn't base64url, a signature that isn't ASCII, and a userHandle that isn't base64url or isn't ASCII. Each raises a ValidationError, "Invalid device" with the code invalid.
    • test_validate_challenge_malformed_userless: a passwordless flow gets a malformed assertion and answers with the stage's challenge and the "Invalid device" error.
  • The tests of authentik/stages/authenticator_validate, authentik/stages/authenticator_webauthn and authentik/stages/identification: 98 passed.
  • black, ruff, and mypy are clean for the changed files.

Linked issues


Checklist

  • The project has been linted, built, and tested (make all)
  • The documentation has been updated and formatted (make docs)
  • I have read the AI usage policy.

@ryanpesek
ryanpesek requested a review from a team as a code owner November 3, 2026 04:16
@netlify

netlify Bot commented Nov 3, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit 6dc3be0
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6ae960349747801d2cecf1f9
😎 Deploy Preview https://deploy-preview-27479--authentik-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@codecov

codecov Bot commented Nov 3, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 93.76%. Comparing base (7074c89) to head (c7bfeb6).
⚠️ Report is 2 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main   #27479      +/-   ##
==========================================
+ Coverage   93.74%   93.76%   +0.01%     
==========================================
  Files        1262     1262              
  Lines       91440    91465      +25     
  Branches     5752     5752              
==========================================
+ Hits        85724    85759      +35     
+ Misses       5630     5620      -10     
  Partials       86       86              
Flag Coverage Δ
conformance 29.26% <3.70%> (-0.01%) ⬇️
e2e 33.70% <3.70%> (+0.93%) ⬆️
integration 26.62% <3.70%> (-0.31%) ⬇️
rust 62.37% <ø> (ø)
unit 94.96% <100.00%> (+<0.01%) ⬆️
unit-migrate 94.97% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

…s an invalid device

validate_challenge_webauthn() only caught InvalidJSONStructure from
parse_authentication_credential_json(). py_webauthn raises
InvalidAuthenticationResponse when a credential field isn't valid base64url,
and a bare ValueError (binascii.Error) when userHandle isn't, so such an
assertion, for example a forged passwordless login, failed the flow with the
error screen and a system_exception event instead of a validation error.

Catch WebAuthnException and ValueError around the parse, as the WebAuthn
setup stage does around verify_registration_response(). This covers both
callers: the authenticator validation stage and the identification stage's
passkey login.
@BeryJu
BeryJu force-pushed the stages/authenticator_validate-malformed-webauthn branch from 6dc3be0 to c7bfeb6 Compare December 1, 2026 17:29
@BeryJu BeryJu added backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 backport/version-2026.11 Add this label to PRs to backport changes to version-2026.11 labels Dec 1, 2026
@BeryJu
BeryJu merged commit 3931139 into goauthentik:main Dec 1, 2026
164 checks passed
@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.8 created: #28392

@authentik-cherry-pick

Copy link
Copy Markdown
Contributor

🍒 Cherry-pick to version-2026.11 created: #28393

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/version-2026.8 Add this label to PRs to backport changes to version-2026.8 backport/version-2026.11 Add this label to PRs to backport changes to version-2026.11

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants