-
Notifications
You must be signed in to change notification settings - Fork 119
Missing time instant verification #63
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
Comments
Persisting records is something that should be implementation specific which puts it outside the scope of a TOTP library. One project might choose to store records in a database. Another project might choose to hold such temporary records an in-memory cache. As such, this project shouldn't (and doesn't) dictate how that is done. If should be noted that previously used TOTP codes don't have to be stored forever. By nature, they are only good for a specific amount of time. You control that amount of time when configuring your
I completely agree that code reuse should be restricted, and long-term persistence is especially important when you consider disallowing reuse of recovery codes. That being said, it is still a implementation-specific decision. This library doesn't have external dependencies on a database and should not. |
I completely agree. But a TOTP library should at least expose the record - because let's suppose I want to persist the Also, when I know that the user used a code at interval
I don't want to store previously used TOTP. That makes no sense, as above: if the current interval is The only secure way to implement is to persist the |
Ok, I am tracking with you now. It could work something like below (which is a modification of If null is returned, the code was invalid. If a non-null value is returned, that is the
Admittedly, it could return a more complex object comprised of a success flag and the bucket, but this would get the job done. Also, the method name is a bit of a misnomer since it returns a Long. |
Don't return a null Long. Instead return an Optional<Long>.
https://docs.oracle.com/javase/8/docs/api/java/util/Optional.html
Best regards,
Doug Huber
|
I got asked by a colleague if this is a good library to use, and I'm sorry to conclude it is not secure due to its missing replay protections. This library only verifies if the code is correct (within allowable time window), but does not care if the same (or a later) code has been already provided or not.
Typically, I'd expect the high-level API to be
returning the ID of the successful bucket or some special value if the code is invalid. (Maybe there's a better way to do that in Java, I'm not a Java guy :) But you get the idea.)
The key is that the backend DB should store the bucket for the last successful TOTP code - and never accept any from the same or previous buckets (since they could be replayed etc.). Currently, there's no way of knowing if the coming TOTP code is being replayed or not.
Unfortunately, due to this I cannot recommend the library for production. Which is a pity since I like its features.
The text was updated successfully, but these errors were encountered: