Skip to content

stages/authenticator_validate: refactor authenticator validation stage to prevent cross-device-type response validation as well as allow multiple devices of the same type - #22369

Open
atereshkin wants to merge 4 commits into
goauthentik:mainfrom
atereshkin:authenticator-validation-per-device

Conversation

@atereshkin

@atereshkin atereshkin commented May 14, 2026 •

Copy link
Copy Markdown
Contributor

Details

At the heart of this change is the introduction of a "device challenger" hierarchy (parallel to device hierarchy) to codify the challenge lifecycle behaviors (generate -> initiate (send) -> validate). I am not sure "challenger" is a great name, but introducing yet another thing called "lifecycle" didn't seem like good idea and "validator" is too narrow. The main advantage this gives, other than tidier code organization and more explicit data flow, is the ability to control for each device type individually whether we issue a challenge per-device or a single challenge for the entire device type. That way we can allow the user to have multiple phone numbers attached (#6732) while still checking every TOTP device at once.
It also eliminates the previously existing but undesirable behavior of validating challenge responses across different authenticator device types.
Additionally, the server no longer trusts the client about any properties of the challenge. The server looks that up in the flow context by the challenge uid that the client has selected.

This alters the behavior of the authenticator validation stage with respect to login_failed signal: the signal is now sent on every validation error as long as a user is known (either we are validating second factor or we have determined the device during validation). Previously this was inconsistent across device types and there was no signal if e.g. an error was caught earlier in the validation (e.g. empty code supplied).


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)
  • The API schema and clients have been updated (make gen)
  • The code has been formatted (make web)

Closes #25265

@atereshkin
atereshkin requested review from a team as code owners May 14, 2026 17:19
@netlify

netlify Bot commented May 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit c821ccc
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/6a06d28df52f8e00088d5316
😎 Deploy Preview https://deploy-preview-22369--authentik-storybook.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.

@netlify

netlify Bot commented May 14, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit c821ccc
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/6a06d28d993e810008cbb9c6
😎 Deploy Preview https://deploy-preview-22369--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 May 14, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 95.62172% with 25 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.28%. Comparing base (d1c02c2) to head (9ad3e56).
⚠️ Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
authentik/stages/authenticator_validate/stage.py 88.31% 9 Missing ⚠️
...ik/stages/authenticator_validate/challenge/base.py 94.04% 5 Missing ⚠️
...tik/stages/authenticator_validate/challenge/duo.py 90.62% 3 Missing ⚠️
...k/stages/authenticator_validate/challenge/email.py 86.36% 3 Missing ⚠️
authentik/stages/identification/stage.py 82.35% 3 Missing ⚠️
...tages/authenticator_validate/challenge/webauthn.py 96.82% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #22369      +/-   ##
==========================================
- Coverage   93.28%   92.28%   -1.00%     
==========================================
  Files        1032     1040       +8     
  Lines       60052    60294     +242     
  Branches      400      400              
==========================================
- Hits        56018    55643     -375     
- Misses       4034     4651     +617     
Flag Coverage Δ
conformance 36.61% <32.22%> (+<0.01%) ⬆️
e2e 41.28% <45.53%> (-0.58%) ⬇️
integration 32.55% <24.86%> (-0.50%) ⬇️
rust 0.00% <ø> (ø)
unit 91.36% <95.27%> (-0.84%) ⬇️
unit-migrate 58.32% <51.83%> (-33.93%) ⬇️

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

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

@netlify

netlify Bot commented May 15, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit c821ccc
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/6a06d28d12aa7b0008149a5f
😎 Deploy Preview https://deploy-preview-22369--authentik-integrations.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.

This branch has not been deployed

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

Labels

None yet

Projects

None yet

3 participants