Repository navigation
Limit the wrong two-factor codes a customer may try - #1100
Merged
Merged
Conversation
After the password step, the second step accepted any number of codes in the same session, so a six-digit code could be guessed by trying them in turn, in the storefront and in the panels. After five wrong codes the waiting sign-in is dropped and the customer signs in with the password again. The count starts again on each password step and after a code passes.
… session The limit lived in the session: parallel requests of one sign-in each read the same count, and each password step started it again, so with an authenticator app the guessing went on in rounds of five. The second step also never looked at the login lockout. A new ITwoFactorSignInService checks the code under a lock on the customer, reads the customer again, refuses a locked-out one and counts wrong codes on the customer, where a new password step does not clear them. The fifth wrong code locks the customer out for the store's lockout length (30 minutes when none is set) and drops the waiting sign-in; the password step already refuses a locked-out customer. A code that passes clears the count. The storefront and the panels use it, and the session counter and its resource are gone.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
After the password step, the second step accepted any number of codes. A six-digit code could be guessed by trying codes in turn, in the storefront and in the admin, store and vendor panels. A wrong code raised
CustomerLoginFailedEvent, but lockout is off by default and the second step did not look at it.Changes
ITwoFactorSignInService(Grand.Business.Core) withTwoFactorSignInService(Grand.Business.Authentication):CheckCoderuns the code check of one customer at a time underIResourceLock(keyTwoFactorSignIn:{customerId}), reads the customer again, refuses a locked-out customer (CannotLoginUntilDateUtc), and counts wrong codes on the customer in the user fieldTwoFactorWrongCodes.MaxWrongCodes) locks the customer out forCustomerSettings.FailedPasswordLockoutMinutes, or 30 minutes (the installer's value) when the store set none. A code that passes clears the count; a new password step does not.CustomerLoginFailedEventis published from the service with the customer read under the lock, so its handler writes the lockout fields back from current data.AccountControllerandBaseLoginController: the POST of the second step uses the service. On lockout the waiting sign-in is dropped and the form showsAccount.Login.WrongCredentials.LockedOut; the password step already refuses a locked-out customer.Notes
Tests
TwoFactorSignInServiceTests: right code passes; a wrong code is counted on the customer and reported; the fifth locks out; a locked-out customer is refused even with the right code; the count survives a new password step and a passing code clears it; lockout without a configured length; the check runs under the customer's lock.LoginControllerTwoFactorTests,AccountControllerTwoFactorReturnUrlTestsmoved to the service.Grand.Business.Authentication.Tests(410),Grand.Web.Admin.Tests(2110),Grand.Web.Tests(655),Grand.Web.Store.Tests(245),Grand.Web.Vendor.Tests(53) pass.