-
Notifications
You must be signed in to change notification settings - Fork 166
Use Redis for one-time passcode sending rate limits #7725
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
Changes from all commits
cda6f9a
79b8eec
92d4422
38453c2
846346f
7ea58d4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,19 +15,14 @@ def exceeded_otp_send_limit? | |
| end | ||
|
|
||
| def max_requests_reached? | ||
| return throttle.throttled? if IdentityConfig.store.redis_throttle_otp_rate_limiter_read_enabled | ||
|
|
||
| entry_for_current_phone.otp_send_count > otp_maxretry_times | ||
| throttle.throttled? | ||
| end | ||
|
|
||
| def rate_limit_period_expired? | ||
| return throttle.expired? if IdentityConfig.store.redis_throttle_otp_rate_limiter_read_enabled | ||
| otp_last_sent_at.present? && (otp_last_sent_at + otp_findtime) < Time.zone.now | ||
| throttle.expired? | ||
| end | ||
|
|
||
| def reset_count_and_otp_last_sent_at | ||
| entry_for_current_phone.update(otp_last_sent_at: Time.zone.now, otp_send_count: 0) | ||
|
|
||
| throttle.reset! | ||
| end | ||
|
|
||
|
|
@@ -36,30 +31,21 @@ def lock_out_user | |
| end | ||
|
|
||
| def increment | ||
| # DO NOT MEMOIZE | ||
| @entry = OtpRequestsTracker.atomic_increment(entry_for_current_phone.id) | ||
| throttle.increment! | ||
| nil | ||
| end | ||
|
|
||
| def otp_last_sent_at | ||
| if IdentityConfig.store.redis_throttle_otp_rate_limiter_read_enabled | ||
| throttle.attempted_at | ||
| else | ||
| entry_for_current_phone.otp_last_sent_at | ||
| end | ||
| throttle.attempted_at | ||
| end | ||
|
|
||
| def throttle | ||
| @throttle ||= Throttle.new(throttle_type: :phone_otp, target: throttle_key) | ||
| end | ||
|
|
||
| private | ||
|
|
||
| attr_reader :phone, :user, :phone_confirmed | ||
|
|
||
| # rubocop:disable Naming/MemoizedInstanceVariableName | ||
| def entry_for_current_phone | ||
| @entry ||= OtpRequestsTracker.find_or_create_with_phone_and_confirmed(phone, phone_confirmed) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same note about this method not being used anywhere and could be removed from
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just to clarify, are we planning to drop the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, plan is to drop everything related to OtpRequestsTracker in this, and drop the table if we're content with the functionality. |
||
| end | ||
| # rubocop:enable Naming/MemoizedInstanceVariableName | ||
|
|
||
| def otp_findtime | ||
| IdentityConfig.store.otp_delivery_blocklist_findtime.minutes | ||
| end | ||
|
|
@@ -72,10 +58,6 @@ def phone_fingerprint | |
| @phone_fingerprint ||= Pii::Fingerprinter.fingerprint(PhoneFormatter.format(phone)) | ||
| end | ||
|
|
||
| def throttle | ||
| @throttle ||= Throttle.new(throttle_type: :phone_otp, target: throttle_key) | ||
| end | ||
|
|
||
| def throttle_key | ||
| "#{phone_fingerprint}:#{phone_confirmed}" | ||
| end | ||
|
|
||
This file was deleted.
Uh oh!
There was an error while loading. Please reload this page.