Skip to content

stage/authenticator*: expand attempt throttling to email- and sms-based 2FA - #21751

Merged
PeshekDotDev merged 9 commits into
goauthentik:mainfrom
atereshkin:mfa-throttle
May 7, 2026
Merged

PeshekDotDev merged 9 commits into
goauthentik:mainfrom
atereshkin:mfa-throttle

Conversation

@atereshkin

Copy link
Copy Markdown
Contributor

Details

This expands attempt throttling logic that's already in use for TOTP and static codes to email- and sms-based 2FA.
Additional parameters are added on the Authenticator Validation stage that control throttling speed.
One important omission is that this PR does not address the (already existing) issue of displaying throttling-specific error messages. This will be taken care of in a follow-up PR that will change code validation logic away from trying every device.


Checklist

  • Local tests pass (ak test authentik/)
  • The code has been formatted (make lint-fix)

If an API change has been made

  • The API schema and clients have been updated (make gen)

If changes to the frontend have been made

  • The code has been formatted (make web)

If applicable

  • The documentation has been updated
  • The documentation has been formatted (make docs)

@atereshkin
atereshkin requested review from a team as code owners April 21, 2026 14:34
@netlify

netlify Bot commented Apr 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-integrations ready!

Name Link
🔨 Latest commit d5441ce
🔍 Latest deploy log https://app.netlify.com/projects/authentik-integrations/deploys/69f0be3ed39cea000882759f
😎 Deploy Preview https://deploy-preview-21751--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.

@netlify

netlify Bot commented Apr 21, 2026

Copy link
Copy Markdown

✅ Deploy Preview for authentik-storybook ready!

Name Link
🔨 Latest commit 808bcce
🔍 Latest deploy log https://app.netlify.com/projects/authentik-storybook/deploys/69e78af21704520008ee934f
😎 Deploy Preview https://deploy-preview-21751--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 Apr 21, 2026 •

Copy link
Copy Markdown

✅ Deploy Preview for authentik-docs ready!

Name Link
🔨 Latest commit d5441ce
🔍 Latest deploy log https://app.netlify.com/projects/authentik-docs/deploys/69f0be3e2bb22f0008f8dc44
😎 Deploy Preview https://deploy-preview-21751--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 Apr 21, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.52607% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 93.14%. Comparing base (6d57854) to head (d5441ce).
⚠️ Report is 154 commits behind head on main.

Files with missing lines Patch % Lines
...es/authenticator_validate/tests/test_throttling.py 99.12% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #21751      +/-   ##
==========================================
+ Coverage   92.21%   93.14%   +0.92%     
==========================================
  Files        1034     1017      -17     
  Lines       59985    58277    -1708     
  Branches     2695      327    -2368     
==========================================
- Hits        55317    54281    -1036     
+ Misses       4595     3996     -599     
+ Partials       73        0      -73     
Flag Coverage Δ
conformance 36.58% <8.05%> (-0.41%) ⬇️
e2e 42.45% <14.69%> (-0.45%) ⬇️
integration 33.04% <8.05%> (-0.88%) ⬇️
rust 0.00% <ø> (-60.56%) ⬇️
unit 92.01% <99.52%> (+0.08%) ⬆️
unit-migrate 92.04% <99.52%> (+0.02%) ⬆️

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.

atereshkin and others added 3 commits April 28, 2026 13:36
atereshkin and others added 3 commits April 28, 2026 17:03
…_validate/index.mdx

Co-authored-by: Dominic R <[email protected]>
Signed-off-by: Alexander Tereshkin <[email protected]>
…_validate/index.mdx

Co-authored-by: Dominic R <[email protected]>
Signed-off-by: Alexander Tereshkin <[email protected]>
…_validate/index.mdx

Co-authored-by: Dominic R <[email protected]>
Signed-off-by: Alexander Tereshkin <[email protected]>
: nothing}
</div>
</ak-form-group>
<ak-form-group label="${msg("Throttling settings")}">

@dominic-r dominic-r Apr 28, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth extracting and deduping this

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something like this:

    private renderThrottlingComponent(msg: string, field: string, value = 1) {
        return html`
            <ak-form-element-horizontal label=${msg} required name=${field}>
                <input
                    type="number"
                    step="0.1"
                    value=${value}
                    class="pf-c-form-control pf-m-monospace"
                    autocomplete="off"
                    spellcheck="false"
                    required
                />
            </ak-form-element-horizontal>
        `;
    }

And then you can ${renderThrottlingComponent(msg("Email OTP throttling factor"), "emailOtpThrottlingFactor", this.instance?.emailOtpThrottlingFactor)} for each of the types. Warm my heart and put those into a table and build them with a map(). :-)

def component(self) -> str:
return "ak-stage-authenticator-validate-form"

def get_throttling_factor(self, device_class: DeviceClasses) -> float | None:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't we just do this instead of a giant if block?

def get_throttling_factor(self, device_class: DeviceClasses) -> float | None:
    mapping = {
        DeviceClasses.EMAIL: self.email_otp_throttling_factor,
        DeviceClasses.SMS: self.sms_otp_throttling_factor,
        DeviceClasses.TOTP: self.totp_otp_throttling_factor,
        DeviceClasses.STATIC: self.static_otp_throttling_factor,
    }
    return mapping.get(device_class)

@dominic-r dominic-r left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm docs

@gergosimonyi gergosimonyi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There should definitely be a follow-up refactoring ThrottlingMixin to be used with anything rather than devices only. The mixin leaves much to be desired: strategies, upper limit, etc.

That is not the aim of this PR though, and I believe no additional complexity is introduced that raises the difficulty of such a refactor.

One note: please edit the comment at the top of the mixin. It is not accurate after this PR, namely this is no longer a strict requirement:

[...] Subclasses must
implement :meth:get_throttle_factor [...]

@PeshekDotDev
PeshekDotDev merged commit 93abd2e into goauthentik:main May 7, 2026
152 of 155 checks passed
kensternberg-authentik added a commit that referenced this pull request May 7, 2026
* main: (25 commits)
  lifecycle/aws: bump aws-cdk from 2.1119.0 to 2.1120.0 in /lifecycle/aws (#22105)
  web: bump @sentry/browser from 10.50.0 to 10.51.0 in /web in the sentry group across 1 directory (#22106)
  ci: bump taiki-e/install-action from 2.75.30 to 2.76.0 in /.github/actions/setup (#22108)
  core, web: update translations (#22129)
  stage/authenticator*: expand attempt throttling to email- and sms-based 2FA (#21751)
  translate: Updates for project authentik and language pt_PT (#22122)
  translate: Updates for project authentik and language no_NO (#22120)
  stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#22128)
  translate: Updates for project authentik and language ja_JP (#22118)
  translate: Updates for project authentik and language ru_RU (#22119)
  translate: Updates for project authentik and language tr_TR (#22125)
  translate: Updates for project authentik and language pl_PL (#22124)
  translate: Updates for project authentik and language pt_BR (#22111)
  translate: Updates for project authentik and language it_IT (#22123)
  translate: Updates for project authentik and language zh-Hans (#22121)
  translate: Updates for project authentik and language cs_CZ (#22115)
  translate: Updates for project authentik and language fr_FR (#22117)
  translate: Updates for project authentik and language fi_FI (#22114)
  translate: Updates for project authentik and language de_DE (#22113)
  translate: Updates for project authentik and language es_ES (#22116)
  ...
kensternberg-authentik added a commit that referenced this pull request May 7, 2026
* main: (30 commits)
  locale: fix de_DE locale placeholder (#22130)
  website/docs: stages cleanup (#21558)
  website: bump the build group in /website with 3 updates (#22104)
  web: bump basic-ftp from 5.3.0 to 5.3.1 in /web (#22131)
  web: bump knip from 6.7.0 to 6.9.0 in /web (#22107)
  lifecycle/aws: bump aws-cdk from 2.1119.0 to 2.1120.0 in /lifecycle/aws (#22105)
  web: bump @sentry/browser from 10.50.0 to 10.51.0 in /web in the sentry group across 1 directory (#22106)
  ci: bump taiki-e/install-action from 2.75.30 to 2.76.0 in /.github/actions/setup (#22108)
  core, web: update translations (#22129)
  stage/authenticator*: expand attempt throttling to email- and sms-based 2FA (#21751)
  translate: Updates for project authentik and language pt_PT (#22122)
  translate: Updates for project authentik and language no_NO (#22120)
  stages/authenticator_webauthn: Update FIDO MDS3 & Passkey aaguid blobs (#22128)
  translate: Updates for project authentik and language ja_JP (#22118)
  translate: Updates for project authentik and language ru_RU (#22119)
  translate: Updates for project authentik and language tr_TR (#22125)
  translate: Updates for project authentik and language pl_PL (#22124)
  translate: Updates for project authentik and language pt_BR (#22111)
  translate: Updates for project authentik and language it_IT (#22123)
  translate: Updates for project authentik and language zh-Hans (#22121)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants