Skip to content

Commit

Permalink
bug #29094 Add samesite attribute to session cookie after session mig…
Browse files Browse the repository at this point in the history
…ration (rpkamp)

This PR was merged into the 4.2-dev branch.

Discussion
----------

Add samesite attribute to session cookie after session migration

| Q             | A
| ------------- | ---
| Branch?       | master
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #29092
| License       | MIT
| Doc PR        | N/A

Commits
-------

df90300 Add samesite attribute to session cookie after session migration
  • Loading branch information
nicolas-grekas committed Nov 6, 2018
2 parents 23a0b2d + df90300 commit 8cd0538
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,13 @@ public function regenerate($destroy = false, $lifetime = null)
// @see https://bugs.php.net/bug.php?id=70013
$this->loadSession();

if (null !== $this->emulateSameSite) {
$originalCookie = SessionUtils::popSessionCookie(session_name(), session_id());
if (null !== $originalCookie) {
header(sprintf('%s; SameSite=%s', $originalCookie, $this->emulateSameSite));
}
}

return $isRegenerated;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
open
validateId
read
doRead:
read
destroy
close
open
validateId
read
doRead:
read

write
doWrite: foo|s:3:"bar";
close
Array
(
[0] => Content-Type: text/plain; charset=utf-8
[1] => Cache-Control: max-age=0, private, must-revalidate
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax
)
shutdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

require __DIR__.'/common.inc';

use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;

$storage = new NativeSessionStorage(array('cookie_samesite' => 'lax'));
$storage->setSaveHandler(new TestSessionHandler());
$storage->start();

$_SESSION = array('foo' => 'bar');

$storage->regenerate(true);

ob_start(function ($buffer) { return preg_replace('~_sf2_meta.*$~m', '', str_replace(session_id(), 'random_session_id', $buffer)); });

0 comments on commit 8cd0538

Please sign in to comment.