-
-
Notifications
You must be signed in to change notification settings - Fork 9.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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
src/Symfony/Component/Security/Http/EventListener/RememberMeListener.php
Show resolved
Hide resolved
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 in https://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 invalidate all 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!
src/Symfony/Component/Security/Http/Firewall/ContextListener.php
Outdated
Show resolved
Hide resolved
df166fa
to
3a7445e
Compare
PR and description updated:
|
3a7445e
to
822b844
Compare
d665748
to
1069c3d
Compare
src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bridge/Doctrine/Security/RememberMe/DoctrineTokenProvider.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php
Outdated
Show resolved
Hide resolved
2e591bc
to
3a6b88c
Compare
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.
Thank you.
I did my best reviewing this. I just had some minor comments and suggestions.
src/Symfony/Bridge/Doctrine/SchemaListener/RememberMeTokenProviderDoctrineSchemaSubscriber.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/RememberMe/DecoratedRememberMeHandler.php
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Bundle/SecurityBundle/DependencyInjection/Security/Factory/RememberMeFactory.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/Authenticator/RememberMeAuthenticator.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Http/EventListener/CheckRememberMeConditionsListener.php
Show resolved
Hide resolved
5edac9b
to
e26d6c4
Compare
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 ready to go 👍
...Bundle/SecurityBundle/DependencyInjection/Compiler/ReplaceDecoratedRememberMeHandlerPass.php
Outdated
Show resolved
Hide resolved
...Bundle/SecurityBundle/DependencyInjection/Compiler/ReplaceDecoratedRememberMeHandlerPass.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Signature/Exception/ExpiredSignatureException.php
Outdated
Show resolved
Hide resolved
src/Symfony/Component/Security/Core/Signature/Exception/InvalidSignatureException.php
Outdated
Show resolved
Hide resolved
e26d6c4
to
1174f00
Compare
Thanks for the detailed review @chalasr :) |
1174f00
to
232abe9
Compare
232abe9
to
1567041
Compare
Thank 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 posting scheb/2fa#75 for visibility :-) where a live app, upgraded to |
As I mentioned on scheb/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. |
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.