-
Notifications
You must be signed in to change notification settings - Fork 153
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
TOTP: Enforce single-use of TOTP one-time passwords. #517
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…ed token being valid if a newer token is used.
…matches that in `calc_totp()`. This ensures that the timestamp returned is the tick time, rather than the time during the tick that it passed.
…_valid_ticktime, due to 63cdf72
dd32
commented
Feb 10, 2023
15 tasks
iandunn
approved these changes
Feb 10, 2023
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.
Code looks good and all of the scenarios tested well for me 👍🏻
Co-authored-by: Ian Dunn <[email protected]>
Co-authored-by: Ian Dunn <[email protected]>
Trailing commas are not allowed in function calls in PHP 7.2 or earlier
20 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Per the TOTP spec, section 5.2:
Once a TOTP token is entered, it should not be able to be re-used, it's one-time.
This is a hardening ticket, making the TOTP provider comply with the spec.
For example:
Per spec, both windows logging in successfully shouldn't be allowed, window 2 should fail the TOTP code and be forced to wait for the next generated one.
For a an example of why this protection exists, If someone were to be looking over your shoulder as you type in your password and authcode, they should not be able to repeat the same on their own device and succeed at logging in, because you've already used your one-time code.
This PR takes it a step further, mostly out of convenience, by making any TOTP codes for previous-timestamp-ticks be invalid once you use the future code.
In this next scenario, both windows are logging in with unique TOTP codes, but with this change window 2 will be rejected as window 1 has already logged in with a newer one-time password.
That means if someone were standing beside you, saw the first TOTP code (with 5s remaining on it), and you waited
and entered the next code generated, they should still not be able to login during the grace period with that now "old" code.
In this next scenario, both logins will proceed and login:
There is no minimum wait between successful logins, only that the next login must be using a later-generated code.
There are edge-cases which this does break, but I don't believe is a concern. For example, if there is a shared user account, with multiple TOTP generators, and their clocks are out of sync, and multiple people try to login at the same time, some will fail.
Note: The login nonce prevents you having two windows open on the 2FA screen, you must start each test of the flow from the user/pass login screen.
See WordPress/wporg-two-factor#3