Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function start()
}

$sessionId = $_COOKIE[session_name()] ?? null;
if ($sessionId && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) {
if ($sessionId && $this->saveHandler instanceof AbstractProxy && 'files' === $this->saveHandler->getSaveHandlerName() && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) {
// the session ID in the header is invalid, create a new one
session_id(session_create_id());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,31 @@ public function testGetBagsOnceSessionStartedIsIgnored()
$this->assertEquals($storage->getBag('flashes'), $bag);
}

public function testRegenerateInvalidSessionId()
public function testRegenerateInvalidSessionIdForNativeFileSessionHandler()
{
$_COOKIE[session_name()] = '&~[';
$started = (new NativeSessionStorage())->start();
session_id('&~[');
$storage = new NativeSessionStorage([], new NativeFileSessionHandler());
$started = $storage->start();

$this->assertTrue($started);
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
$storage->save();

$_COOKIE[session_name()] = '&~[';
session_id('&~[');
$storage = new NativeSessionStorage([], new SessionHandlerProxy(new NativeFileSessionHandler()));
$started = $storage->start();

$this->assertTrue($started);
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
$storage->save();

$_COOKIE[session_name()] = '&~[';
session_id('&~[');
$storage = new NativeSessionStorage([], new NullSessionHandler());
$started = $storage->start();
$this->assertTrue($started);
$this->assertSame('&~[', session_id());
}
}