Skip to content

Commit 47f2aa6

Browse files
Merge branch '5.4' into 6.0
* 5.4: Exclude from baseline generation deprecations triggered in legacy test [HttpFoundation] Update "[Session] Overwrite invalid session id" to only validate when files session storage is used [DoctrineBridge] Add missing break [FrameworkBundle] Lower JsonSerializableNormalizer priority
2 parents dab7c79 + e7793b7 commit 47f2aa6

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

Session/Storage/NativeSessionStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public function start(): bool
136136
}
137137

138138
$sessionId = $_COOKIE[session_name()] ?? null;
139-
if ($sessionId && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) {
139+
if ($sessionId && $this->saveHandler instanceof AbstractProxy && 'files' === $this->saveHandler->getSaveHandlerName() && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) {
140140
// the session ID in the header is invalid, create a new one
141141
session_id(session_create_id());
142142
}

Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,12 +284,31 @@ public function testGetBagsOnceSessionStartedIsIgnored()
284284
$this->assertEquals($storage->getBag('flashes'), $bag);
285285
}
286286

287-
public function testRegenerateInvalidSessionId()
287+
public function testRegenerateInvalidSessionIdForNativeFileSessionHandler()
288288
{
289289
$_COOKIE[session_name()] = '&~[';
290-
$started = (new NativeSessionStorage())->start();
290+
session_id('&~[');
291+
$storage = new NativeSessionStorage([], new NativeFileSessionHandler());
292+
$started = $storage->start();
291293

292294
$this->assertTrue($started);
293295
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
296+
$storage->save();
297+
298+
$_COOKIE[session_name()] = '&~[';
299+
session_id('&~[');
300+
$storage = new NativeSessionStorage([], new SessionHandlerProxy(new NativeFileSessionHandler()));
301+
$started = $storage->start();
302+
303+
$this->assertTrue($started);
304+
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
305+
$storage->save();
306+
307+
$_COOKIE[session_name()] = '&~[';
308+
session_id('&~[');
309+
$storage = new NativeSessionStorage([], new NullSessionHandler());
310+
$started = $storage->start();
311+
$this->assertTrue($started);
312+
$this->assertSame('&~[', session_id());
294313
}
295314
}

0 commit comments

Comments
 (0)