Skip to content

Commit

Permalink
Do not send deleted session cookie twice in the response
Browse files Browse the repository at this point in the history
  • Loading branch information
X-Coder264 committed Aug 14, 2022
1 parent ee9a83a commit 7dee7f0
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions EventListener/AbstractSessionListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public function onKernelResponse(ResponseEvent $event)

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

0 comments on commit 7dee7f0

Please sign in to comment.