Skip to content

Commit 7dee7f0

Browse files
committed
Do not send deleted session cookie twice in the response
1 parent ee9a83a commit 7dee7f0

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

EventListener/AbstractSessionListener.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,11 @@ public function onKernelResponse(ResponseEvent $event)
158158

159159
$isSessionEmpty = $session->isEmpty() && empty($_SESSION); // checking $_SESSION to keep compatibility with native sessions
160160
if ($requestSessionCookieId && $isSessionEmpty) {
161+
// PHP internally sets the session cookie value to "deleted" when setcookie() is called with empty string $value argument
162+
// which happens in \Symfony\Component\HttpFoundation\Session\Storage\Handler\AbstractSessionHandler::destroy
163+
// when the session gets invalidated (for example on logout) so we must handle this case here too
164+
// otherwise we would send two Set-Cookie headers back with the response
165+
SessionUtils::popSessionCookie($sessionName, 'deleted');
161166
$response->headers->clearCookie(
162167
$sessionName,
163168
$sessionCookiePath,

0 commit comments

Comments
 (0)