Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork9.6k
[Security] Rework the remember me system#40145
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
stof commentedFeb 10, 2021 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
|
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
You can invalidate tokens by including properties in the signature. If any signature property changes, all previously made remember me tokens are invalidated. The difference being short-lived login links vs long-lived remember me tokens is an interesting one! I see the current persistent tokens are using the logic as explained inhttps://stackoverflow.com/a/244907/1149495 I'll see if I can find other examples/references about persistent remember me cookies and whether using signature properties can fulfill this (or we need to reintroduce a persistent token handler). |
As Wouter said, the signature properties could be used to invalidate tokens... but it could only be used to invalidateall tokens (e.g. by adding some However, I will also say that the new system will make it easier for "everyone else" to have a more secure remember me system: we can document how to setup a system that would truly invalidate remember me tokens (via the signature properties) on log out (though, again, it would invalidate all remember me tokens for that user). |
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.
This looks incredibly promising!
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
df166fa
to3a7445e
ComparePR and description updated:
|
3a7445e
to822b844
Compared665748
to1069c3d
Comparesrc/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
2e591bc
to3a6b88c
CompareThere 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.
Thank you.
I did my best reviewing this. I just had some minor comments and suggestions.
src/Symfony/Bridge/Doctrine/SchemaListener/RememberMeTokenProviderDoctrineSchemaSubscriber.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/SecurityBundle/RememberMe/DecoratedRememberMeHandler.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Http/EventListener/CheckRememberMeConditionsListener.phpShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
5edac9b
toe26d6c4
CompareThere 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.
This looks ready to go 👍
...Bundle/SecurityBundle/DependencyInjection/Compiler/ReplaceDecoratedRememberMeHandlerPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
...Bundle/SecurityBundle/DependencyInjection/Compiler/ReplaceDecoratedRememberMeHandlerPass.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Signature/Exception/ExpiredSignatureException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
src/Symfony/Component/Security/Core/Signature/Exception/InvalidSignatureException.php OutdatedShow resolvedHide resolved
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
e26d6c4
to1174f00
CompareThanks for the detailed review@chalasr :) |
1174f00
to232abe9
Compare232abe9
to1567041
CompareThank you@wouterj. |
@wouterj Congratulations for having this merged! 🥳 Thank you for all of your work and thank you to everyone who gave feedback on this thread. I believe it's a great step forward! |
cross postingscheb/2fa#75 for visibility :-) where a live app, upgraded to |
As I mentioned onscheb/2fa#75, just to let the people here know, that's nothing to worry about since I've been in the loop from the beginning of this PR here and I have an (unfinished) branch preparred to make scheb/2fa-bundle compatible with Symfony 5.3. Whoever wants to test Symfony 5.3 with 2fa-bundle is welcome to use that branch. |
Sorry :-) was too eager to test ... thanks everyone for the hard work - this looks amazing! |
What was the reason to serialise |
@zerkms Would you mind opening a new issue for this topic? Only few people monitor comments of already closed PRs. |
Uh oh!
There was an error while loading.Please reload this page.
As I said in#39308, I want to change the remember me system in Symfony 5.3. The remember me system has a couple big "problems":
ContextListener
. TheRememberMeFactory
adds asetRememberMe()
method call to the DI config and the context listener calls methods on this. This is very coupled, instead of the decoupled nature of the rest of security.The changes
SignatureHasher
in the 3rd commit.RememberMeAuthenticator
to the login link system, which I think improves a lot and at least improves problem (2) - as the conditionals (RememberMeAuthenticator
) is split from the cookie creation (RememberMeHandlerInterface
).TokenDeauthenticatedEvent
) to theContextListener
to avoid direct coupling - solving problem (1).This removes any usage of remember me services, which can be deprecated along with the rest of the security system.
Usage
As with the authenticator manager:Nothing changes in the configuration
Usage of persistent token providers has been improved. First, configuration is provided (setting up services is no longer needed):
Furthermore, a schema listener is created. Whenever the doctrine token provider is used,
make:migration
/doctrine:schema:update
will automatically create the required table.Some advanced usage of Remember me is also improved a lot (there is no real "before" here, consider looking at scheb/2fa to get an idea of the before). A few use-cases I took into account:
RememberMeHandlerInterface
and usecreateRememberMeCookie($user)
. This will make sure the remember me cookie is set on the final response (using theResponseListener
)RememberMeListener
previously was responsible for both determining if a cookie must be set and setting the cookie. This is now split in 2 listeners (checking is done byRememberMeConditionsListener
). IfRememberMeBadge
is enabled, the cookie is set and otherwise it isn't. This allows e.g. SchebTwoFactorBundle to create a listener that catches whether remember me was requested, but suppress it until the 2nd factor is completed.Todo
ContextListener
. This forces to inject both the firewall and the global event dispatcher at the moment.cc@scheb@weaverryan as you both initiated this PR by sharing the problems with the current design.