[Bug 44007] New: Limit attempts and resends on the two-factor authentication second step
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 Bug ID: 44007 Summary: Limit attempts and resends on the two-factor authentication second step Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Authentication Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: martin.renvoize@openfifth.co.uk CC: dpavlin@rot13.org Target Milestone: --- The staff login second step accepts any number of OTP guesses, and the "Send the code by email" endpoint can be called repeatedly. TOTP codes are also replayable within their validity window. This matters more once users can enrol by email only (Bug 44006), where the emailed code is their sole second factor. Proposed: - cap failed OTP attempts per login session, then require a fresh login - add a cooldown between email sends - review the validity window used for emailed codes (currently the global mfa_range, about 90 seconds, which is tight for email delivery) Test plan: 1. Enable 2FA and enrol a user. 2. At the second step, enter wrong codes repeatedly: after the cap the session is rejected and a new login is required. 3. Press "Send the code by email" repeatedly: sends within the cooldown are refused. 4. A correct code within the limits still logs in. -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Depends on| |44006 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44006 [Bug 44006] Allow staff to enrol in two-factor authentication using email instead of an authenticator app -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 210566 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210566&action=edit Bug 44007: Limit attempts and resends on the two-factor authentication second step The second step of the staff login accepted any number of wrong codes, and codes could be requested by email repeatedly. This patch: - counts wrong codes per login session and, after 5, discards the session so a new login is required. The login screen says why, and the failure is logged when AuthFailureLog is enabled. - refuses to send another code by email for 60 seconds after one was sent in the same session, for both the login fallback and the email enrolment (HTTP 429 too_many_requests). The cooldown only starts once a code was actually sent, so a failed send can be retried. The limits are constants in Koha::Auth::TwoFactorAuth. The validity window of emailed codes (global mfa_range) is not changed. To test: 1. Apply the patch (and Bug 44005 and Bug 44006), restart_all. 2. Enable TwoFactorAuthentication and TwoFactorAuthenticationEmailFallback and enrol a staff user. 3. Log in, and at the second step enter wrong codes: after the 5th you are returned to the login form with "Too many invalid two-factor codes. Please log in again." 4. Log in again: a correct code still works. 5. At the second step press "Send the code by email" twice in a row: the second is refused with a "please wait" message, and works again after a minute. 6. Repeat the second check for the email choice when enrolling. 7. prove t/db_dependent/Auth.t t/db_dependent/api/v1/two_factor_auth.t Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #210566|0 |1 is obsolete| | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 --- Comment #2 from David Nind <david@davidnind.com> --- Created attachment 210805 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=210805&action=edit Bug 44007: Limit attempts and resends on the two-factor authentication second step The second step of the staff login accepted any number of wrong codes, and codes could be requested by email repeatedly. This patch: - counts wrong codes per login session and, after 5, discards the session so a new login is required. The login screen says why, and the failure is logged when AuthFailureLog is enabled. - refuses to send another code by email for 60 seconds after one was sent in the same session, for both the login fallback and the email enrolment (HTTP 429 too_many_requests). The cooldown only starts once a code was actually sent, so a failed send can be retried. The limits are constants in Koha::Auth::TwoFactorAuth. The validity window of emailed codes (global mfa_range) is not changed. To test: 1. Apply the patch (and Bug 44005 and Bug 44006), restart_all. 2. Enable TwoFactorAuthentication and TwoFactorAuthenticationEmailFallback and enrol a staff user. 3. Log in, and at the second step enter wrong codes: after the 5th you are returned to the login form with "Too many invalid two-factor codes. Please log in again." 4. Log in again: a correct code still works. 5. At the second step press "Send the code by email" twice in a row: the second is refused with a "please wait" message, and works again after a minute. 6. Repeat the second check for the email choice when enrolling. 7. prove t/db_dependent/Auth.t t/db_dependent/api/v1/two_factor_auth.t Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk CC| |david@davidnind.com --- Comment #3 from David Nind <david@davidnind.com> --- Testing notes (using KTD): 1. Apply the patch and dependencies. 2. Update the database: updatedatabase 3. Rebuild everything: yarn build (not sure if required) 4. Restart everything: restart_all 5. Set up two-factor authentication for the staff patron (I used the koha user). 6. Add a valid email address that you can access to the staff patron's account. 7. Set up Koha so that you can send email [1]. [1] Set up an SMTP server ========================== To test sending emails using a Google account: 1. Set up an App password for your Google Account 2. Configure a new 'SMTP Server' under 'Administration > SMTP servers' using the following settings, where `User name` = your Google email address and `Password` = your APP password, not your Google account password, set this server as default Host: smtp.gmail.com Port: 587 Timeout: 5 SSL: STARTTLS User name: GOOGLEACCOUNTUSER Password: GOOGLEAPPPASSWORD -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44007 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|martin.renvoize@openfifth.c |dcook@prosentient.com.au |o.uk | -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org