Skip to content

Remember device for 30 days option #14194

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

Merged
merged 2 commits into from
Aug 29, 2023
Merged

Conversation

ristomcgehee
Copy link
Contributor

This gives the user the option to not have to provide 2nd factor authentication on a device for 30 days. A new cookie remember_device will contain a signed token that allows the user to skip two-factor authentication (assuming the token is valid). To minimize data being sent by the browser, this cookie is only sent for requests with the path accounts/login.

This is how the 2FA page looks:

With authenticator app and webauthn

image

With only webauthn

image

By default "Remember this device for 30 days" will not be checked.

I originally created a different PR for this issue (#13166) but since we decided to take a substantially different approach, I figured this merited a new, clean PR.

This change requires adding a TOKEN_REMEMBER_DEVICE_SECRET environment variable to the production configuration.

Closes #5867

I'll create a new issue for how these tokens can be revoked. One approach could be to invalidate the tokens when the user changes their password.

@ristomcgehee ristomcgehee requested a review from a team as a code owner July 23, 2023 19:07
Copy link
Member

@miketheman miketheman left a comment

Choose a reason for hiding this comment

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

Added comments inline - overall looks like a nice patch.

@miketheman miketheman added feature request security Security-related issues and pull requests 2FA labels Jul 25, 2023
Copy link
Member

@miketheman miketheman left a comment

Choose a reason for hiding this comment

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

I'm pretty good with this, but would appreciate a second review from @di as well.

Comment on lines +247 to +249
"REMEMBER_DEVICE_DAYS",
coercer=int,
default=30,
Copy link
Member

Choose a reason for hiding this comment

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

praise: ‏I like this even more, since then we don't even need to set a value unless we want to override the default of 30 days.

@miketheman miketheman requested a review from di July 25, 2023 16:28
@ewdurbin
Copy link
Member

random TOKEN_REMEMBER_DEVICE_SECRET values generated and set for both pypi and testpypi deployments, so this can be shipped whenever reviews are complete.

@ristomcgehee
Copy link
Contributor Author

@di It looks like this PR is waiting for your review. Btw, if you re-run the failed checks, they should pass (temporary github issue).

Copy link
Member

@di di left a comment

Choose a reason for hiding this comment

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

Thanks! FYI, translations need to be updated.

- Also cleaned up tests
- Also changed cookie to strict
@ewdurbin ewdurbin merged commit d9d0b46 into pypi:main Aug 29, 2023
@brainwane
Copy link
Contributor

Thanks, all!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2FA feature request security Security-related issues and pull requests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2FA: "trust this device for 30 days" option
5 participants