Skip to content
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
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
14 changes: 7 additions & 7 deletions app/controllers/concerns/idv/verify_info_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,16 @@ def aamva_disallowed_for_service_provider?
end

def resolution_throttle
@resolution_throttle ||= Throttle.new(
@resolution_throttle ||= RateLimit.new(
user: current_user,
throttle_type: :idv_resolution,
rate_limit_type: :idv_resolution,
)
end

def ssn_throttle
@ssn_throttle ||= Throttle.new(
@ssn_throttle ||= RateLimit.new(
target: Pii::Fingerprinter.fingerprint(pii[:ssn]),
throttle_type: :proof_ssn,
rate_limit_type: :proof_ssn,
)
end

Expand Down Expand Up @@ -105,14 +105,14 @@ def idv_failure(result)
end
end

def idv_failure_log_throttled(throttle_type)
if throttle_type == :proof_ssn
def idv_failure_log_throttled(rate_limit_type)
if rate_limit_type == :proof_ssn
irs_attempts_api_tracker.idv_verification_rate_limited(throttle_context: 'multi-session')
analytics.throttler_rate_limit_triggered(
throttle_type: :proof_ssn,
step_name: STEP_NAME,
)
elsif throttle_type == :idv_resolution
elsif rate_limit_type == :idv_resolution
irs_attempts_api_tracker.idv_verification_rate_limited(throttle_context: 'single-session')
analytics.throttler_rate_limit_triggered(
throttle_type: :idv_resolution,
Expand Down
36 changes: 18 additions & 18 deletions app/controllers/concerns/rate_limit_concern.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,30 @@ module RateLimitConcern

def confirm_not_rate_limited
rate_limited = false
%i[idv_resolution idv_doc_auth proof_address proof_ssn].each do |throttle_type|
if rate_limit_redirect!(throttle_type)
%i[idv_resolution idv_doc_auth proof_address proof_ssn].each do |rate_limit_type|
if rate_limit_redirect!(rate_limit_type)
rate_limited = true
break
end
end
rate_limited
end

def rate_limit_redirect!(throttle_type)
if idv_attempter_rate_limited?(throttle_type)
track_rate_limited_event(throttle_type)
rate_limited_redirect(throttle_type)
def rate_limit_redirect!(rate_limit_type)
if idv_attempter_rate_limited?(rate_limit_type)
track_rate_limited_event(rate_limit_type)
rate_limited_redirect(rate_limit_type)
return true
end
end

def track_rate_limited_event(throttle_type)
analytics_args = { throttle_type: throttle_type }
def track_rate_limited_event(rate_limit_type)
analytics_args = { throttle_type: rate_limit_type }
throttle_context = 'single-session'

if throttle_type == :proof_address
if rate_limit_type == :proof_address
analytics_args[:step_name] = :phone
elsif throttle_type == :proof_ssn
elsif rate_limit_type == :proof_ssn
analytics_args[:step_name] = 'verify_info'
throttle_context = 'multi-session'
end
Expand All @@ -35,8 +35,8 @@ def track_rate_limited_event(throttle_type)
analytics.throttler_rate_limit_triggered(**analytics_args)
end

def rate_limited_redirect(throttle_type)
case throttle_type
def rate_limited_redirect(rate_limit_type)
case rate_limit_type
when :idv_resolution
redirect_to idv_session_errors_failure_url
when :idv_doc_auth
Expand All @@ -48,17 +48,17 @@ def rate_limited_redirect(throttle_type)
end
end

def idv_attempter_rate_limited?(throttle_type)
if throttle_type == :proof_ssn
def idv_attempter_rate_limited?(rate_limit_type)
if rate_limit_type == :proof_ssn
return unless pii_ssn
Throttle.new(
RateLimit.new(
target: Pii::Fingerprinter.fingerprint(pii_ssn),
throttle_type: :proof_ssn,
rate_limit_type: :proof_ssn,
).throttled?
else
Throttle.new(
RateLimit.new(
user: idv_session_user,
throttle_type: throttle_type,
rate_limit_type: rate_limit_type,
).throttled?
end
end
Expand Down
9 changes: 6 additions & 3 deletions app/controllers/idv/capture_doc_status_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,14 @@ def document_capture_session_uuid
end

def throttled?

@amirbey amirbey Jul 5, 2023

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice to get rid of this 🥳

throttle.throttled?
rate_limiter.throttled?
end

def throttle
@throttle ||= Throttle.new(user: document_capture_session.user, throttle_type: :idv_doc_auth)
def rate_limiter
@rate_limiter ||= RateLimit.new(
user: document_capture_session.user,
rate_limit_type: :idv_doc_auth,
)
end

def user_has_establishing_in_person_enrollment?
Expand Down
14 changes: 7 additions & 7 deletions app/controllers/idv/gpo_verify_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def index
!gpo_mail.mail_spammed? &&
!gpo_mail.profile_too_old?

if throttle.throttled?
if rate_limiter.throttled?
render_throttled
elsif pii_locked?
redirect_to capture_password_url
Expand All @@ -34,8 +34,8 @@ def pii
def create
@gpo_verify_form = build_gpo_verify_form

throttle.increment!
if throttle.throttled?
rate_limiter.increment!
if rate_limiter.throttled?
render_throttled
return
end
Expand Down Expand Up @@ -85,10 +85,10 @@ def prepare_for_personal_key
idv_session.address_confirmed!
end

def throttle
@throttle ||= Throttle.new(
def rate_limiter
@rate_limiter ||= RateLimit.new(
user: current_user,
throttle_type: :verify_gpo_key,
rate_limit_type: :verify_gpo_key,
)
end

Expand All @@ -98,7 +98,7 @@ def render_throttled
throttle_type: :verify_gpo_key,
)

@expires_at = throttle.expires_at
@expires_at = rate_limiter.expires_at
render :throttled

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

to be changed in follow up ticket/PR?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was avoiding changing anything route-related. Could this be changed by changing just the name of the template file? I still think it should be in a followup PR.

end

Expand Down
12 changes: 6 additions & 6 deletions app/controllers/idv/hybrid_handoff_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ def hybrid_flow_chosen?
end

def handle_phone_submission
throttle.increment!
return throttled_failure if throttle.throttled?
rate_limiter.increment!
return throttled_failure if rate_limiter.throttled?
idv_session.phone_for_mobile_flow = params[:doc_auth][:phone]
flow_session[:flow_path] = 'hybrid'
telephony_result = send_link
Expand Down Expand Up @@ -144,10 +144,10 @@ def build_form
)
end

def throttle
@throttle ||= Throttle.new(
def rate_limiter
@rate_limiter ||= RateLimit.new(
user: current_user,
throttle_type: :idv_send_link,
rate_limit_type: :idv_send_link,
)
end

Expand Down Expand Up @@ -180,7 +180,7 @@ def throttled_failure
'errors.doc_auth.send_link_throttle',
timeout: distance_of_time_in_words(
Time.zone.now,
[throttle.expires_at, Time.zone.now].compact.max,
[rate_limiter.expires_at, Time.zone.now].compact.max,
except: :seconds,
),
)
Expand Down
8 changes: 4 additions & 4 deletions app/controllers/idv/phone_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def new
async_state = step.async_state

# It's possible that create redirected here after a success and left the
# throttle maxed out. Check for success before checking throttle.
# rate_limiter maxed out. Check for success before checking rate_limiter.
return async_state_done(async_state) if async_state.done?

render 'shared/wait' and return if async_state.in_progress?
Expand Down Expand Up @@ -58,8 +58,8 @@ def create

private

def throttle
@throttle ||= Throttle.new(user: current_user, throttle_type: :proof_address)
def rate_limiter
@rate_limiter ||= RateLimit.new(user: current_user, rate_limit_type: :proof_address)
end

def redirect_to_next_step
Expand Down Expand Up @@ -171,7 +171,7 @@ def async_state_done(async_state)
)

if async_state.result[:success]
throttle.reset!
rate_limiter.reset!
redirect_to_next_step and return
end
handle_proofing_failure
Expand Down
12 changes: 6 additions & 6 deletions app/controllers/idv/phone_errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class PhoneErrorsController < ApplicationController
before_action :ignore_form_step_wait_requests

def warning
@remaining_attempts = throttle.remaining_count
@remaining_attempts = rate_limiter.remaining_count

if idv_session.previous_phone_step_params
@phone = idv_session.previous_phone_step_params[:phone]
Expand All @@ -20,24 +20,24 @@ def warning
end

def timeout
@remaining_step_attempts = throttle.remaining_count
@remaining_step_attempts = rate_limiter.remaining_count
track_event(type: :timeout)
end

def jobfail
@remaining_attempts = throttle.remaining_count
@remaining_attempts = rate_limiter.remaining_count
track_event(type: :jobfail)
end

def failure
@expires_at = throttle.expires_at
@expires_at = rate_limiter.expires_at
track_event(type: :failure)
end

private

def throttle
Throttle.new(user: idv_session.current_user, throttle_type: :proof_address)
def rate_limiter
RateLimit.new(user: idv_session.current_user, rate_limit_type: :proof_address)
end

def confirm_idv_phone_step_needed
Expand Down
32 changes: 16 additions & 16 deletions app/controllers/idv/session_errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,48 +13,48 @@ def exception
end

def warning
throttle = Throttle.new(
rate_limiter = RateLimit.new(
user: idv_session_user,
throttle_type: :idv_resolution,
rate_limit_type: :idv_resolution,
)

@remaining_attempts = throttle.remaining_count
log_event(based_on_throttle: throttle)
@remaining_attempts = rate_limiter.remaining_count
log_event(based_on_throttle: rate_limiter)
end

def state_id_warning
log_event
end

def failure
throttle = Throttle.new(
rate_limiter = RateLimit.new(
user: idv_session_user,
throttle_type: :idv_resolution,
rate_limit_type: :idv_resolution,
)
@expires_at = throttle.expires_at
@expires_at = rate_limiter.expires_at
@sp_name = decorated_session.sp_name
log_event(based_on_throttle: throttle)
log_event(based_on_throttle: rate_limiter)
end

def ssn_failure
throttle = nil
rate_limiter = nil

if ssn_from_doc
throttle = Throttle.new(
rate_limiter = RateLimit.new(
target: Pii::Fingerprinter.fingerprint(ssn_from_doc),
throttle_type: :proof_ssn,
rate_limit_type: :proof_ssn,
)
@expires_at = throttle.expires_at
@expires_at = rate_limiter.expires_at
end

log_event(based_on_throttle: throttle)
log_event(based_on_throttle: rate_limiter)
render 'idv/session_errors/failure'
end

def throttled
throttle = Throttle.new(user: idv_session_user, throttle_type: :idv_doc_auth)
log_event(based_on_throttle: throttle)
@expires_at = throttle.expires_at
rate_limiter = RateLimit.new(user: idv_session_user, rate_limit_type: :idv_doc_auth)
log_event(based_on_throttle: rate_limiter)
@expires_at = rate_limiter.expires_at
end

private
Expand Down
4 changes: 2 additions & 2 deletions app/controllers/users/two_factor_authentication_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -265,9 +265,9 @@ def exceeded_otp_send_limit?
end

def phone_confirmation_throttle
@phone_confirmation_throttle ||= Throttle.new(
@phone_confirmation_throttle ||= RateLimit.new(
user: current_user,
throttle_type: :phone_confirmation,
rate_limit_type: :phone_confirmation,
)
end

Expand Down
14 changes: 7 additions & 7 deletions app/controllers/users/verify_personal_key_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ def new
personal_key: '',
)

if throttle.throttled?
if rate_limiter.throttled?
render_throttled
else
render :new
end
end

def create
throttle.increment!
if throttle.throttled?
rate_limiter.increment!
if rate_limiter.throttled?
render_throttled
else
result = personal_key_form.submit
Expand All @@ -45,10 +45,10 @@ def create

private

def throttle
@throttle ||= Throttle.new(
def rate_limiter
@rate_limiter ||= RateLimit.new(
user: current_user,
throttle_type: :verify_personal_key,
rate_limit_type: :verify_personal_key,
)
end

Expand All @@ -59,7 +59,7 @@ def render_throttled

irs_attempts_api_tracker.personal_key_reactivation_rate_limited

@expires_at = throttle.expires_at
@expires_at = rate_limiter.expires_at
render :throttled
end

Expand Down
Loading