[SecurityBundle] Fix Security::login() across firewalls#64338
Merged
nicolas-grekas merged 1 commit intoMay 23, 2026
symfony:6.4symfony/symfony:6.4from
ousamabenyounes:fix/issue-53499ousamabenyounes/symfony:fix/issue-53499Copy head branch name to clipboard
Merged
[SecurityBundle] Fix Security::login() across firewalls#64338nicolas-grekas merged 1 commit intosymfony:6.4symfony/symfony:6.4from ousamabenyounes:fix/issue-53499ousamabenyounes/symfony:fix/issue-53499Copy head branch name to clipboard
nicolas-grekas merged 1 commit into
symfony:6.4symfony/symfony:6.4from
ousamabenyounes:fix/issue-53499ousamabenyounes/symfony:fix/issue-53499Copy head branch name to clipboard
Conversation
110d8c9 to
91a9a9b
Compare
Member
|
Thank you @ousamabenyounes. |
This was referenced May 27, 2026
Merged
Merged
Merged
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Security::login()is supposed to authenticate a user into the firewall passed as the third argument, but when that firewall differs from the one currently handling the request the new token ends up persisted under the current firewall's session key (_security_<currentFirewall>) instead of the target firewall's (_security_<targetFirewall>).Root cause:
ContextListener::onKernelResponse()keys its session write off$request->attributes->get('_security_firewall_run'), which is the current firewall's session key. AfterSecurity::login()minted a token for a different firewall, that listener writes the foreign token to the current firewall's bucket — so the user looks logged in to the wrong firewall.Fix: when the target firewall differs from the current one, write the new token directly to the target firewall's session key (
_security_<context>, mirroring whatKernelBrowser::loginUser()does) and remove the_security_firewall_runrequest attribute so the current firewall'sContextListenerdoes not overwrite its own bucket with the foreign token. The current firewall's existing token is therefore untouched.The fix is a no-op when
Security::login()is called for the firewall already handling the request, when the target firewall is stateless, or when the target firewall config cannot be resolved (e.g. on legacy setups without the newsecurity.firewall_config_locatorlocator) — preserving full BC.A new
security.firewall_config_locatorServiceLocator (keyed by firewall name) is wired inSecurityExtensionand injected intosecurity.helper, alongside the existingsecurity.user_checker_locatorpattern.Reproduces with
Tests/Functional/SecurityTest::testLoginBetweenStatefulFirewalls.TDD verification
6.4withSecurity.php/SecurityExtension.php/security.phpreverted):