[HttpFoundation] Do not send Set-Cookie header twice for deleted session cookie #47273
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.
In a user logout flow
\Symfony\Component\Security\Http\EventListener\SessionLogoutListener
gets triggered which invalidates the user session by callingsession_regenerate_id(true)
which calls\Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler::destroy
which callssetcookie($this->sessionName, '', $params);
. Callingsetcookie
with the second argument (the value) being an empty string signals to PHP that we want to send aSet-Cookie
HTTP header to the client so that the client deletes the cookie (aka the expiry time of the cookie gets set to some time in the past) and PHP also sets the value of that cookie todeleted
-> https://github.com/php/php-src/blob/php-8.1.9/ext/standard/head.c#L124The
\Symfony\Component\HttpKernel\EventListener\AbstractSessionListener
class did not handle this case as\Symfony\Component\HttpKernel\EventListener\AbstractSessionListener::onKernelResponse
method would call$response->headers->clearCookie()
without calling thepopSessionCookie
method which would then add this same cookie again which would then result in twoSet-Cookie
headers being sent to the client for the same cookie.