Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8cd0538

Browse files
bug #29094 Add samesite attribute to session cookie after session migration (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
2 parents 23a0b2d + df90300 commit 8cd0538

File tree

3 files changed

+45
-0
lines changed

3 files changed

+45
-0
lines changed

src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ public function regenerate($destroy = false, $lifetime = null)
222222
// @see https://bugs.php.net/bug.php?id=70013
223223
$this->loadSession();
224224

225+
if (null !== $this->emulateSameSite) {
226+
$originalCookie = SessionUtils::popSessionCookie(session_name(), session_id());
227+
if (null !== $originalCookie) {
228+
header(sprintf('%s; SameSite=%s', $originalCookie, $this->emulateSameSite));
229+
}
230+
}
231+
225232
return $isRegenerated;
226233
}
227234

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
open
2+
validateId
3+
read
4+
doRead:
5+
read
6+
destroy
7+
close
8+
open
9+
validateId
10+
read
11+
doRead:
12+
read
13+
14+
write
15+
doWrite: foo|s:3:"bar";
16+
close
17+
Array
18+
(
19+
[0] => Content-Type: text/plain; charset=utf-8
20+
[1] => Cache-Control: max-age=0, private, must-revalidate
21+
[2] => Set-Cookie: sid=random_session_id; path=/; secure; HttpOnly; SameSite=lax
22+
)
23+
shutdown
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?php
2+
3+
require __DIR__.'/common.inc';
4+
5+
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
6+
7+
$storage = new NativeSessionStorage(array('cookie_samesite' => 'lax'));
8+
$storage->setSaveHandler(new TestSessionHandler());
9+
$storage->start();
10+
11+
$_SESSION = array('foo' => 'bar');
12+
13+
$storage->regenerate(true);
14+
15+
ob_start(function ($buffer) { return preg_replace('~_sf2_meta.*$~m', '', str_replace(session_id(), 'random_session_id', $buffer)); });

0 commit comments

Comments
 (0)