[HttpFoundation] Do not send Set-Cookie header twice for deleted session cookie #47273
+78
−0
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.


In a user logout flow
\Symfony\Component\Security\Http\EventListener\SessionLogoutListenergets triggered which invalidates the user session by callingsession_regenerate_id(true)which calls\Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler::destroywhich callssetcookie($this->sessionName, '', $params);. Callingsetcookiewith the second argument (the value) being an empty string signals to PHP that we want to send aSet-CookieHTTP 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\AbstractSessionListenerclass did not handle this case as\Symfony\Component\HttpKernel\EventListener\AbstractSessionListener::onKernelResponsemethod would call$response->headers->clearCookie()without calling thepopSessionCookiemethod which would then add this same cookie again which would then result in twoSet-Cookieheaders being sent to the client for the same cookie.