-
Notifications
You must be signed in to change notification settings - Fork 167
LG-7201 - Added attempt events - MFA submitted rate limited #6783
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
efde5ac
d305bc0
2a0211d
573ce03
b359731
3273907
7f695b6
ad561de
19096b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,11 +17,19 @@ def authenticate_user | |
| authenticate_user!(force: true) | ||
| end | ||
|
|
||
| def handle_second_factor_locked_user(type) | ||
| def handle_second_factor_locked_user(type:, context: nil) | ||
| analytics.multi_factor_auth_max_attempts | ||
| event = PushNotification::MfaLimitAccountLockedEvent.new(user: current_user) | ||
| PushNotification::HttpPush.deliver(event) | ||
| handle_max_attempts(type + '_login_attempts') | ||
|
|
||
| if context | ||
| if UserSessionContext.authentication_context?(context) | ||
| irs_attempts_api_tracker.mfa_login_rate_limited(type: type) | ||
| elsif UserSessionContext.confirmation_context?(context) | ||
| irs_attempts_api_tracker.mfa_enroll_rate_limited(type: type) | ||
| end | ||
| end | ||
| end | ||
|
|
||
| def handle_too_many_otp_sends | ||
|
|
@@ -108,13 +116,13 @@ def two_factor_authentication_method | |
| # Method will be renamed in the next refactor. | ||
| # You can pass in any "type" with a corresponding I18n key in | ||
| # two_factor_authentication.invalid_#{type} | ||
| def handle_invalid_otp(type: 'otp') | ||
| def handle_invalid_otp(type:, context: nil) | ||
| update_invalid_user | ||
|
|
||
| flash.now[:error] = invalid_otp_error(type) | ||
|
|
||
| if decorated_user.locked_out? | ||
| handle_second_factor_locked_user(type) | ||
| handle_second_factor_locked_user(context: context, type: type) | ||
| else | ||
| render_show_after_invalid | ||
| end | ||
|
|
@@ -124,6 +132,8 @@ def invalid_otp_error(type) | |
| case type | ||
| when 'otp' | ||
| t('two_factor_authentication.invalid_otp') | ||
| when 'totp' | ||
| t('two_factor_authentication.invalid_otp') | ||
|
||
| when 'personal_key' | ||
| t('two_factor_authentication.invalid_personal_key') | ||
| when 'piv_cac' | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -97,6 +97,16 @@ def mfa_enroll_piv_cac( | |
| ) | ||
| end | ||
|
|
||
| # @param [String] type - the type of multi-factor authentication used | ||
| # The user has exceeded the rate limit during enrollment | ||
| # and account has been locked | ||
| def mfa_enroll_rate_limited(type:) | ||
| track_event( | ||
| :mfa_enroll_rate_limited, | ||
| type: type, | ||
| ) | ||
| end | ||
|
|
||
| # Tracks when the user has attempted to enroll the TOTP MFA method to their account | ||
| # @param [Boolean] success | ||
| def mfa_enroll_totp(success:) | ||
|
|
@@ -158,8 +168,8 @@ def mfa_login_phone_otp_submitted(reauthentication:, success:) | |
| end | ||
|
|
||
| # Tracks when the user has attempted to log in with the piv cac MFA method to their account | ||
| # @param [String] subject_dn | ||
| # @param [Boolean] success | ||
| # @param [String] subject_dn | ||
|
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. IMHO I wouldn't fix this unless you need to edit something else in this PR anyway, but I think in the merge conflict this line got moved from above to below
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. So, the merge conflict removed the top two lines entirely 😨. I put them back in a commit, but noticed that the params were out of order, so I moved subject_dn below success on purpose, to match the function definition. Was that the right thing to do?
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. Oh, my bad! Yes, good catch. 👍 |
||
| # @param [Hash<Symbol,Array<Symbol>>] failure_reason | ||
| def mfa_login_piv_cac( | ||
| success:, | ||
|
|
@@ -174,6 +184,16 @@ def mfa_login_piv_cac( | |
| ) | ||
| end | ||
|
|
||
| # @param [String] type - the type of multi-factor authentication used | ||
| # The user has exceeded the rate limit during verification | ||
| # and account has been locked | ||
| def mfa_login_rate_limited(type:) | ||
| track_event( | ||
| :mfa_login_rate_limited, | ||
| type: type, | ||
| ) | ||
| end | ||
|
|
||
| # Tracks when the user has attempted to log in with the TOTP MFA method to access their account | ||
| # @param [Boolean] success | ||
| def mfa_login_totp(success:) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am weirdly delighted that we're able to get rid of the hard-coded 'otp' default here. 👏