-
Notifications
You must be signed in to change notification settings - Fork 77
Make sure to only allow single usage of a 2FA code #277
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
This was discussed quite recently in #276. Short version: There is currently no out-of-the-box mechanic to keep track of used authentication codes and prevent reuse. For custom implementations, it could be achieved by listening to the newly introduced "check" events and throwing an exception, when a reused code is detected. I'd be open to make this part of the bundle, though I'd be reluctant to introduce a complicate storage mechanism or new dependency to the bundle. Relying on For a proper implementation I'd likely add another listener like |
Yeah. My idea was to create a Listener for the And then also add a listener to that event that throws the That way users can implement their own way of handling the non-unique usage without having to catch the exception - like sending an email that the code was used twice or displaying that in the UI or whatever else they deem appropriate - but the exception will be thrown in the end (unless the users remove that listener deliberately) Does that sound like a feasible way? |
I like the customization with that approach. But I'd introduce a new event to signal the reuse of a code, e.g. Open questions:
|
I'd prefer to go with the new generic event for "code checking" as it seems to be more specific. And not being triggered by the backup-codes sounds like a feature. Those should be one time usage anyhow. Or is that currently not implemented that way? 🙈
I would throw a
I was thinking about adding a
By adding EventHandlers/-Subscribers that listen to the Does that sound plausible? Yes! the documentation needs to be amended as well then |
code-organization-wise I'd see that all within the
Only the exception I'D see in |
👍 Yes, it is implemented, so that backup codes are invalidated, once they're used. But people do all kinds of stuff 🤷♂. But I agree, backup codes don't need to be covered by this feature, as the nature of backup codes is different than regular authentication codes.
👍
👍 Sounds good. Though I think this should become option
Would work for me. Though I'm wondering if we could provide an easier way to replace the default listener with a custom implementation. Some configuration option.
Absolutely :)
You can use the existing class The new event would likely need to go here, btw.:
Agreed. Though should be next to the other event listener in the
Also in the
Yes, makes sense.
Should be next to |
I better get going then... |
No need to rush :) |
Right now it is possible to use a 2FA code several times as long as the code itself isn't expired.
According to NIST though that should not be possible.
If I see that correctly (please correct me!) there is currently no way of getting this behaviour out of the box from this package.
Would it not be an idea to provide a simple implementation of this behaviour using an existing caching method to implement this? I was thinking about providing a
Psr\Cache\CacheItemPoolInterface
or aSymfony\Contracts\Cache\CacheInterface
in the package-config and when that is available to use that for ensuring single use of the code.I will have to implement it either way, would it be of interest to do that in a way that it can be added to the package?
The text was updated successfully, but these errors were encountered: