Skip to content

[HttpKernel] Set session cookie only when not empty #44657

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

alexander-schranz
Copy link
Contributor

@alexander-schranz alexander-schranz commented Dec 15, 2021

Q A
Branch? 5.4 for bug fixes
Bug fix? yes
New feature? no
Deprecations? no
Tickets Fix #44616
License MIT
Doc PR symfony/symfony-docs#...

A session is normally not written when empty so we need to check for empty before set the session cookie.

TODO:

  • Test

@@ -151,7 +151,8 @@ public function onKernelResponse(ResponseEvent $event)
$request = $event->getRequest();
$requestSessionCookieId = $request->cookies->get($sessionName);

if ($requestSessionCookieId && $session->isEmpty()) {
$isSessionEmpty = $session->isEmpty();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need in 6.0 be replaced with the new logic:

if ($requestSessionCookieId && ($session instanceof Session ? $session->isEmpty() : empty($session->all()))) {

@carsonbot
Copy link

Hey!

I think @mtarld has recently worked with this code. Maybe they can help review this?

Cheers!

Carsonbot

@@ -160,7 +161,7 @@ public function onKernelResponse(ResponseEvent $event)
$sessionCookieHttpOnly,
$sessionCookieSameSite
);
} elseif ($sessionId !== $requestSessionCookieId) {
} elseif ($sessionId !== $requestSessionCookieId && !$isSessionEmpty) {
Copy link
Member

@nicolas-grekas nicolas-grekas Dec 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should even not write the session in the backend when it's empty?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a value is removed we need to write it to remove that value from the session bag.

@carsonbot carsonbot changed the title Set session cookie only when not empty [HttpKernel] Set session cookie only when not empty Dec 28, 2021
@alexander-schranz
Copy link
Contributor Author

for making things simpler for me I moving this changes to #44634

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants