Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/services/idv/send_phone_confirmation_otp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@ def initialize(user:, idv_session:)
def call
otp_rate_limiter.reset_count_and_otp_last_sent_at if user.no_longer_locked_out?

# The pattern for checking the rate limiter, incrementing, then checking again was introduced
# in this change: https://github.com/18F/identity-idp/pull/2216
#
# This adds protection against a race condition that would result in sending a large number
# of OTPs and/or needlessly making atomic increments to the rate limit counter if
# a bad actor sends many requests at the same time.
#
return too_many_otp_sends_response if rate_limit_exceeded?
otp_rate_limiter.increment
return too_many_otp_sends_response if rate_limit_exceeded?
Expand Down