Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add limitless counting failed login function #184

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hairgai
Copy link

@hairgai hairgai commented Apr 25, 2019

Hi.

This function is adding limitless counting 'failed login'.
I think, if stopped counting 'failed login' after reached limit, we can't tell the reason of lock either user's action or brute force attack, so I added.

If you don't need, please close this PR
Thanks.

If stopped counting 'failed login' after reached limit,
we can't tell the reason of lock either user's action or brute force attack.
@@ -63,13 +66,14 @@ def define_brute_force_protection_fields
module InstanceMethods
# Called by the controller to increment the failed logins counter.
# Calls 'login_lock!' if login retries limit was reached.
def register_failed_login!
def register_failed_login!(password)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is the password parameter necessary here? The method simply registers a failed login attempt, its behavior should not depend on the provided password.

Can we just reverse the order of increment call and return unless login_unlocked?. Will that have the desired effect?

Copy link
Member

Choose a reason for hiding this comment

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

As mentioned, passing the password to this callback is unnecessary at best, and malicious at worst.

@@ -14,6 +14,8 @@ def self.included(base)
:consecutive_login_retries_amount_limit, # how many failed logins allowed.
:login_lock_time_period, # how long the user should be banned.
# in seconds. 0 for permanent.
:limitless_counting_failed_login, # When true, continue to count failed login
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think another config option is needed here. Is there a reason why someone would want to disable this option?

Copy link
Member

@joshbuker joshbuker left a comment

Choose a reason for hiding this comment

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

I'll take another look at this later, some significant concerns with this particular implementation however.


return unless send(config.failed_logins_count_attribute_name) >= config.consecutive_login_retries_amount_limit
sorcery_adapter.increment(config.failed_logins_count_attribute_name) unless valid_password?(password)
Copy link
Member

@joshbuker joshbuker Jun 5, 2021

Choose a reason for hiding this comment

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

I suspect this might open the window to timing attacks, especially considering the trip time to a DB may be significant in certain setups.

Edit: Example of a potential attack:

  1. Brute force a login until it locks
  2. Continue brute force attack, monitoring the response time for each request
  3. Upon a request that takes ~50-100ms less than average, you know you've hit a correct password
  4. To verify that it wasn't a network hiccup, Try two other known bad passwords, and the suspected valid password a few times, compare the averages. If valid, it should average (whatever the trip time to the DB is) faster.

@@ -63,13 +66,14 @@ def define_brute_force_protection_fields
module InstanceMethods
# Called by the controller to increment the failed logins counter.
# Calls 'login_lock!' if login retries limit was reached.
def register_failed_login!
def register_failed_login!(password)
Copy link
Member

Choose a reason for hiding this comment

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

As mentioned, passing the password to this callback is unnecessary at best, and malicious at worst.

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.

3 participants