Skip to content

Commit e7793b7

Browse files
Merge branch '4.4' into 5.4
* 4.4: [HttpFoundation] Update "[Session] Overwrite invalid session id" to only validate when files session storage is used [DoctrineBridge] Add missing break
2 parents 6094095 + 4441dad commit e7793b7

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
@@ -146,7 +146,7 @@ public function start()
146146
}
147147

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

Tests/Session/Storage/NativeSessionStorageTest.php

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

290-
public function testRegenerateInvalidSessionId()
290+
public function testRegenerateInvalidSessionIdForNativeFileSessionHandler()
291291
{
292292
$_COOKIE[session_name()] = '&~[';
293-
$started = (new NativeSessionStorage())->start();
293+
session_id('&~[');
294+
$storage = new NativeSessionStorage([], new NativeFileSessionHandler());
295+
$started = $storage->start();
294296

295297
$this->assertTrue($started);
296298
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
299+
$storage->save();
300+
301+
$_COOKIE[session_name()] = '&~[';
302+
session_id('&~[');
303+
$storage = new NativeSessionStorage([], new SessionHandlerProxy(new NativeFileSessionHandler()));
304+
$started = $storage->start();
305+
306+
$this->assertTrue($started);
307+
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
308+
$storage->save();
309+
310+
$_COOKIE[session_name()] = '&~[';
311+
session_id('&~[');
312+
$storage = new NativeSessionStorage([], new NullSessionHandler());
313+
$started = $storage->start();
314+
$this->assertTrue($started);
315+
$this->assertSame('&~[', session_id());
297316
}
298317
}

0 commit comments

Comments
 (0)