Skip to content

Conversation

@jenshenny
Copy link
Member

A support request came in to reset their 2FA. I noticed that the admin action doesn't reset Webauthn devices so if a user has a passkey set up, the action won't completely reset their MFA.

@codecov
Copy link

codecov bot commented Dec 3, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 97.24%. Comparing base (164a40e) to head (2c6ad2d).
⚠️ Report is 8 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #6125   +/-   ##
=======================================
  Coverage   97.24%   97.24%           
=======================================
  Files         476      476           
  Lines        9785     9787    +2     
=======================================
+ Hits         9515     9517    +2     
  Misses        270      270           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

end

def disable_user_mfa
return unless user.no_mfa_devices?
Copy link
Member Author

Choose a reason for hiding this comment

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

For some reason, when calling destroy_all, the webauthn credential still persists in the association so destroying the last credential would not result in disabling mfa.

I called reset_mfa_attributes in the admin action itself, even though it is repetitive, it ensures the action actually correctly removed all MFA methods.

@jenshenny jenshenny marked this pull request as ready for review December 3, 2025 18:32
@jenshenny
Copy link
Member Author

Fix for CI: #6126

@jenshenny jenshenny force-pushed the reset-webauthn-admin branch from 56825c5 to 754a423 Compare December 8, 2025 00:10
def handle_record(user)
user.disable_totp!
user.disable_totp! if user.totp_enabled?
user.webauthn_credentials.destroy_all if user.webauthn_enabled?
Copy link
Member

Choose a reason for hiding this comment

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

Using destroy_all is going to trigger the disable_user_mfa & send_deletion_email callback for each webauthn device. Considering this is an admin action, should we switch this to be delete_all to skip the callbacks? (I suspect this will also resolve your comment below)

Copy link
Member

Choose a reason for hiding this comment

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

Should we consider moving the idea of resetting MFA (OTP + WebAuthN) into a User#reset_all_mfa method to better capture everything and test for it?

Copy link
Member

Choose a reason for hiding this comment

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

Should we also consider wrapping this all in a transaction?

Copy link
Member Author

Choose a reason for hiding this comment

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

The avo action is wrapped in a transaction so I think we're fine on that part.

I tried to move everything into reset_all_mfa , have a delete_all, and only send one email instead of one per device. However, the audits are subscribed to active_record.sql events and won't capture the delete_all webauthn cred records in the audit. It's going to take me a bit longer to implement getting these deleted records in the audit so I'm going to ship this as is to unblock the support request and come back to this after.

@jenshenny jenshenny force-pushed the reset-webauthn-admin branch from 754a423 to 2c6ad2d Compare December 9, 2025 14:17
@jenshenny jenshenny merged commit 43e57d3 into master Dec 9, 2025
19 checks passed
@jenshenny jenshenny deleted the reset-webauthn-admin branch December 9, 2025 14:26
@github-project-automation github-project-automation bot moved this from Ready to Merged in RubyGems.org Pull Requests Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Development

Successfully merging this pull request may close these issues.

2 participants