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

Annotate sign-in reCAPTCHA from 2-factor attempts #11801

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

vrajmohan
Copy link
Contributor

@vrajmohan vrajmohan commented Jan 24, 2025

changelog: Upcoming Features, Recaptcha, Annotate sign-in reCAPTCHA from 2-factor attempts

🎫 Ticket

Link to the relevant ticket:
Annotate sign-in reCAPTCHA after fully authenticated

🛠 Summary of changes

  1. Store the recaptcha_assessment_id in session.
  2. Annotate with INITIATED_TWO_FACTOR when attempting any MFA method if there is a recaptcha_assessment_id in session.
  3. Annotate with PASSED_TWO_FACTOR or FAILED_TWO_FACTOR depending on success when completing any MFA method if there is a recaptcha_assessment_id in session.
  4. Recording the recaptcha_annotation along with the pre-existing event whenever an annotation is made.

📜 Testing Plan

Provide a checklist of steps to confirm the changes.

@vrajmohan
Copy link
Contributor Author

Some open questions:

  1. Annotate on all MFA results - annotate on failures as well as it is an easy lift
  2. What is the value of an INITITATED_TWO_FACTOR annotation?
  3. Use plain :recaptcha_assessment_id in session as there's no value in a more specific namespace
  4. Should the session value be deleted upon use?
  5. Value in annotation argument to RecaptchaAnnotator

@vrajmohan vrajmohan force-pushed the vm-annotate-recaptcha-on-authentication branch 2 times, most recently from 0683bf1 to d109870 Compare January 25, 2025 00:13
@aduth
Copy link
Contributor

aduth commented Jan 27, 2025

What is the value of an INITITATED_TWO_FACTOR annotation?

From what I recall, it's used by Google to interpret as a failed or abandoned attempt if the user never subsequently succeeds . The documentation says "old assessment with ENUM_VALUES.INITIATED_TWO_FACTOR reason that has not been overwritten with PASSED_TWO_FACTOR is treated as an abandoned 2FA flow".

Should the session value be deleted upon use?

I think it's best to clean up if we don't intend to use it again (including browser back button, etc.), particularly if we're going to store it in session and not in user_session (the latter having a more predictable clean-up mechanism).

@vrajmohan
Copy link
Contributor Author

Deleting the annotation id after use would prevent us from annotating a subsequent PASSED_TWO_FACTOR after a FAILED_TWO_FACTOR annotation. (I acknowledge that FAILED_TWO_FACTOR is scope creep for this story.) We could definitely delete after a PASSED_TWO_FACTOR, as I see less benefit in accounting for the other way (ie PASSED_TWO_FACTOR followed by FAILED_TWO_FACTOR).

@vrajmohan vrajmohan force-pushed the vm-annotate-recaptcha-on-authentication branch 3 times, most recently from 0fc407b to fe271ca Compare January 31, 2025 23:34
@vrajmohan vrajmohan marked this pull request as ready for review February 3, 2025 15:47
@vrajmohan vrajmohan requested a review from aduth February 3, 2025 15:47
@aduth aduth requested a review from a team February 3, 2025 16:06
@@ -19,6 +19,7 @@ class AnalyticsEventsDocumenter
pending_profile_idv_level
proofing_components
profile_history
recaptcha_annotation
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this to avoid errors on missing documentation for the analytics method call? I'd expect we'd update the analytics method signatures to include this property if it's something we expect will be logged.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IMO, the recaptcha_annotation is of lesser interest in the events being logged and I was leveraging the **extra argument in the signatures of all the affected events.

If we think it is important and want to add the documentation, I can do so.

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's relevant to be documented.

@vrajmohan vrajmohan requested review from a team and aduth February 3, 2025 17:04
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

Is this missing INITIATED_TWO_FACTOR for phone MFAs?

@@ -217,6 +221,7 @@ def track_authentication_attempt
success = current_user.present? &&
!user_locked_out?(user) &&
(recaptcha_response.success? || log_captcha_failures_only?)
session[:recaptcha_assessment_id] = recaptcha_assessment_id if recaptcha_assessment_id
Copy link
Contributor

Choose a reason for hiding this comment

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

To leave open the option of using reCAPTCHA for other, non-sign-in features, I think it could be wise to add a qualifier here, similar to what we do with user_session[:phone_recaptcha_assessment_id] (e.g. session[:sign_in_recaptcha_assessment_id]).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was my open question #3:

Use plain :recaptcha_assessment_id in session as there's no value in a more specific namespace

Will Google assign different assessment ids for the same device session?

My thought was to create a ticket to move user_session[:phone_recaptcha_assessment_id] also to use session[:recaptcha_assessment_id].

Copy link
Contributor

@aduth aduth Feb 4, 2025

Choose a reason for hiding this comment

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

They're separate assessments, and we'd want to annotate them separately. I don't think we want to consolidate the values.

@vrajmohan
Copy link
Contributor Author

Is this missing INITIATED_TWO_FACTOR for phone MFAs?

I was confused between otp_verification and totp_verification. Looking deeper...

@vrajmohan vrajmohan requested a review from aduth February 4, 2025 17:18
Copy link
Contributor

@aduth aduth left a comment

Choose a reason for hiding this comment

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

LGTM

changelog: Upcoming Features, Recaptcha, Annotate sign-in reCAPTCHA from 2-factor attempts
@vrajmohan vrajmohan force-pushed the vm-annotate-recaptcha-on-authentication branch from 0a0f87a to bc2e633 Compare February 4, 2025 20:16
@vrajmohan vrajmohan merged commit bf298a0 into main Feb 4, 2025
2 checks passed
@vrajmohan vrajmohan deleted the vm-annotate-recaptcha-on-authentication branch February 4, 2025 21:04
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.

2 participants