8000 [HttpFoundation] Update "[Session] Overwrite invalid session id" to o… · symfony/symfony@12460fa · GitHub
[go: up one dir, main page]

Skip to content

Commit 12460fa

Browse files
alexpottnicolas-grekas
authored andcommitted
[HttpFoundation] Update "[Session] Overwrite invalid session id" to only validate when files session storage is used
1 parent d686e38 commit 12460fa

File tree

2 files changed

+22
-3
lines changed

2 files changed

+22
-3
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ public function start()
153153
}
154154

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

src/Symfony/Component/HttpFoundation/Tests/Session/Storage/NativeSessionStorageTest.php

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

297-
public function testRegenerateInvalidSessionId()
297+
public function testRegenerateInvalidSessionIdForNativeFileSessionHandler()
298298
{
299299
$_COOKIE[session_name()] = '&~[';
300-
$started = (new NativeSessionStorage())->start();
300+
session_id('&~[');
301+
$storage = new NativeSessionStorage([], new NativeFileSessionHandler());
302+
$started = $storage->start();
301303

302304
$this->assertTrue($started);
303305
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
306+
$storage->save();
307+
308+
$_COOKIE[session_name()] = '&~[';
309+
session_id('&~[');
310+
$storage = new NativeSessionStorage([], new SessionHandlerProxy(new NativeFileSessionHandler()));
311+
$started = $storage->start();
312+
313+
$this->assertTrue($started);
314+
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
315+
$storage->save();
316+
317+
$_COOKIE[session_name()] = '&~[';
318+
session_id('&~[');
319+
$storage = new NativeSessionStorage([], new NullSessionHandler());
320+
$started = $storage->start();
321+
$this->assertTrue($started);
322+
$this->assertSame('&~[', session_id());
304323
}
305324
}

0 commit comments

Comments
 (0)
0