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

Verify user registering a device #57

Merged
merged 2 commits into from
Feb 27, 2025

Conversation

atlasrealm
Copy link
Contributor

Disclaimer: very new to this, so please let me know what you'd like me to add.

fixes #51

This PR makes sure otp_login is called when registering a new device, which means the user is 2fa verified afterwards. Currently otp_login is only called on login. This behaviour is common across 2fa packages.

Copy link

codecov bot commented Feb 21, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.0%. Comparing base (e32901c) to head (88a993b).
Report is 21 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main      #57   +/-   ##
=======================================
  Coverage   100.0%   100.0%           
=======================================
  Files          13       13           
  Lines         683      690    +7     
  Branches       56       57    +1     
=======================================
+ Hits          683      690    +7     

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

@@ -132,6 +132,7 @@ def post(self, *args, **kwargs):
logger = _get_pywebauthn_logger()
with rewrite_exceptions(logger=logger):
device = helper.register_complete(user=user, state=state, data=data)
otp_login(self.request, device)
Copy link
Member

Choose a reason for hiding this comment

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

Issue: this would override whatever MFA device was used to verify the current session (if the session was verified at all) which I think would be unexpected.

We should only do this if the session is not currently verified (if not request.user.is_verified())

Copy link
Contributor Author

Choose a reason for hiding this comment

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

To push back a bit, personally I'd expect the override. The override also happens in django-two-factor-auth. In my opinion, it also results in better UX when adding a new passkey and then deleting the old one that you logged in with in the first place. (If there's no override you need to be logged out or disallowed to delete it).

That said, I'll leave it up to you to decide. Just let me know if you are sure about this and I will implement.

Copy link
Member

Choose a reason for hiding this comment

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

Why do you think the override should happen? Aside from it being the default behavior of django-two-factor-auth

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel the flow should not be dependent on how or if you are 2fa authenticated at that point. Makes it more predictable for users.

Also what I said about removing an active auth method above.

But most important is that you get 2fa authenticated when you are not, so I can live with either solution.

@Stormheg
Copy link
Member

I've opted to stay on the cautious side and only mark the session as MFA verified when a user is not MFA verified yet. I've added a commit to that effect.

Thanks for PR @AlmerCarbonEquity, it should make it into a release soon. Gearing up to prepare a new release soon.

@Stormheg Stormheg merged commit 9115734 into Stormbase:main Feb 27, 2025
11 checks passed
Stormheg added a commit that referenced this pull request Feb 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

call otp_login on registering passkey
2 participants