-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
Harden 2FA/TOTP implementation according to rfc6238 #640
Labels
feature-request
Request for new features to be added
Comments
andreasbrett
added a commit
to andreasbrett/uptime-kuma
that referenced
this issue
Oct 10, 2021
generate TOTP secret using WebCrypto API (see louislam#640)
andreasbrett
added a commit
to andreasbrett/uptime-kuma
that referenced
this issue
Oct 10, 2021
override default values: window=1, window size=30 (see louislam#640)
This was referenced Oct 10, 2021
Learnt so much after reading this post! |
Can this be a problem that Pterodactyl in GHSA-5vfx-8w6m-h3v4 had too ? |
Looks like a different issue to me. |
3 parts have been merged, thanks! |
2 tasks
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is your feature request related to a problem? Please describe.
No, this is about following the RFC's recommendations
Describe the solution you'd like
Harden security for the TOTP solution by:
totp.verify
(notp)Additional context
The TOTP standard as described in rfc6238 defines some important recommendations for secure implementation of TOTP.
1. TOTP secret generation (see rfc6238 section 5.1)
The secret is currently generated using the standard
math.random
function (see code). This is explicitely not a cryptographically strong random number generator (see note here). Using Web Crypto API instead should respect the standard and produce less predictable secrets.2. Invalidating used tokens (see rfc6238 section 5.2)
Currently tokens can be used multiple times. The last used token should be stored (incl. timestamp) to check for re-use within the same window. Note that in this case the rfc standard phrases this as a MUST not just as a recommendation. With the current implementation a MitM could login without being noticed (as an intercepted token can be re-used).
3. Avoiding notp default values for token verification (see rfc6238 section 5.2)
Currently
totp.verifyToken
is called with 2 parameters only (token + key) leading notp to use default values for the number of lookahead windows and the window size (see code). Provide those options in the 3rd parameter to explicitely define settings recommended in the rfc. While the windows size is by default 30 seconds (and thus the recommended rfc value), the allowable margin is6
resulting in tokens being valid for +/- 6*30 seconds = 3 minutes.Google Authenticator uses an allowable margin of
1
so I'd suggest using this as it's IMHO the most used TOTP implementation globally. For reference see their libpam module's code. It states the number3
but they interpret this differently than notp does. notp checksallowable_margin
windows in the past andallowable_margin
windows in the future while Google checksallowable_margin
windows total (so for3
it is: the current window + 1 window in the past + 1 window in the future). Hence Google's3
is a1
in notp's interpretation.The text was updated successfully, but these errors were encountered: