Make 2FA persistent by using the database #86
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.
Problem
There is a limitation in the current state of the library in which the 2FA stays alive whilst the current session is alive. That means that
remember_me
functionalities and cookie-based approaches do not have the choice to provide long-term 2FA authentication and the OTP will be asked as soon as the session is expired.Fix
By using a database column, we can give the choice of a persistent 2FA without being dependent on the session's lifespan. The column is a timestamp and it will be populated with the current time as soon as the OTP is provided and there is a
remember_me
cookie set in the user's browser.The new
twoFactorAuthStillValid
will check if the user enabled theremember
functionality and will pass the check by comparing the timestamp taken on the login with the current_time plus thelifetime
of the config.Bugs and considerations
Keep in mind that the check in line #229 in
Google2FA.php
just checks for the defaultremember_me
cookie of Laravel and there is no validation that the cookie is indeed valid.This PR doesn't play well with
lifetime=0
(as you can see in thetwoFactorAuthStillValid
method) and it would need a hacky way to make it for eternity by passing a large amount of time (like 100 years or something). I will leave this up to you.Final Notes
These changes will allow to the lifetime of the 2FA to be greater than the session's lifetime.
This way, users can stay "2FA authenticated" for a greater amount of time and not be limited by the session's lifespan.