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

LG-14078: Rate-limit backup code attempts based on IP+user ID #11094

Merged
merged 1 commit into from
Aug 16, 2024

Conversation

aduth
Copy link
Contributor

@aduth aduth commented Aug 16, 2024

🎫 Ticket

LG-14078

🛠 Summary of changes

Adds additional rate-limiting to the backup code sign-in MFA submission to limit attempts based on a combination of user and IP address.

Related: #10982

📜 Testing Plan

It will be helpful to adjust local configuration to simplify testing, e.g.

backup_code_user_id_per_ip_attempt_window_exponential_factor: 4
backup_code_user_id_per_ip_attempt_window_in_minutes: 60
backup_code_user_id_per_ip_attempt_window_max_minutes: 1_440
backup_code_user_id_per_ip_max_attempts: 4

With this configuration, it's expected that the lockout would max at 24 hours, which would quickly be hit with an exponential factor of 4:

(1..4).to_a.map { |i| [i, (4 ** (i - 1)).hours] }
# [[1, 1 hour], [2, 4 hours], [3, 16 hours], [4, 64 hours]]

Throughout testing, you can reset your local throttle cache by flushing the Redis store, using rails console:

REDIS_THROTTLE_POOL.with { |client| client.flushdb }

Verify that you cannot make any backup code submissions past your 4th, and you're locked out for 24 hours:

  1. Prerequisite: Have an account with backup codes. It doesn't matter if you know what they are.
  2. Go to http://localhost:3000
  3. Sign in
  4. If not prompted to MFA, click "Forget all browsers" from account dashboard, confirm, sign out, then start again
  5. When prompted for MFA, if not prompted for backup code, click "Choose another authentication method" and select backup codes
  6. When prompted for backup code, enter an incorrect code 4 times (if using the configuration above)
  7. See error message "You tried too many time, please try again in [~24 hours]."

👀 Screenshots

Screenshot 2024-08-16 at 7 57 22 AM

changelog: Internal, Rate Limiting, Enforce additional user IP rate-limiting on backup code submission
@aduth aduth requested a review from a team August 16, 2024 12:05
Copy link
Contributor

@kevinsmaster5 kevinsmaster5 left a comment

Choose a reason for hiding this comment

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

Rate limit is working on local.
LGTM

@aduth aduth merged commit c44f12a into main Aug 16, 2024
2 checks passed
@aduth aduth deleted the aduth-lg-14078-rate-limit-backup-codes branch August 16, 2024 17:06
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