devise-two-factor icon indicating copy to clipboard operation
devise-two-factor copied to clipboard

When using lockable, failed_attempts is incremented by two after failed login attempt

Open mwalsher opened this issue 10 years ago • 10 comments

When using devise-two-factor with devise lockable, there are somehow two calls being made to validate/valid_for_authentication? - the latter of which is doing the failed_attempts increment.

The first failed_attempts increment happens within this block, and the latter seems to be happening after the authenticate! method is finished executing.

if validate(resource) { !resource.otp_required_for_login ||
  resource.valid_otp?(params[scope]['otp_attempt']) }
  super
end

My devise initializer is configuring the warden strategy as follows:

config.warden do |manager|
  manager.default_strategies(:scope => :user).unshift :two_factor_authenticatable
end

My user model is set up with devise as follows:

devise :two_factor_authenticatable, :otp_secret_encryption_key => ENV['RSA_KEY_PW'], otp_secret_length: 64
devise :registerable, :recoverable, :invitable, :trackable, :timeoutable, :lockable

mwalsher avatar May 01 '15 18:05 mwalsher

When using lockable devise increments the failed_attempts counter by one right in the beginning of the authentication even though the authentication has not yet failed nor succeed. It happens in lib/devise/models/lockable.rb method valid_for_authentication?

mmustala avatar Jun 25 '15 07:06 mmustala

To be more accurate it is the current_user and user_signed_in? helpers that are trying to authenticate the user from the request data. If none of those helpers are called during the authentication action then the failed_attempts counter is not increased.

mmustala avatar Jun 25 '15 09:06 mmustala

@ShaneWilton could you look at this when you get a chance? This is a rather tricky bug.

olivierlacan avatar Aug 10 '15 13:08 olivierlacan

@mwalsher, @mmustala, @ShaneWilton guys, any update on that?

marcelamiach avatar Mar 13 '17 23:03 marcelamiach

Two years elapsed, any progress?

FX-HAO avatar Sep 27 '17 10:09 FX-HAO

Any progress? Been hitting a wall and was wondering if it was me or devise or devise-two-factor

Mikewa33 avatar Mar 07 '18 03:03 Mikewa33

another issue #127 still not fixed :(

SimonVillage avatar Apr 17 '18 01:04 SimonVillage

I'm facing the same issue as well. Our hacky fix was just to double the maximum_attempts to what we really want. (ie. we want to lock after 10 failed attempts, so we set maximum_attempts to 20)

StevenJL avatar Jun 24 '20 22:06 StevenJL

Any update on this issue? I've been doubling the maximum_attempts to hack my way in as @StevenJL.

canberkvarli avatar Nov 02 '22 16:11 canberkvarli