Skip to content

Commit 05abe9a

Browse files
Merge branch '5.4' into 6.0
* 5.4: Fix merge [Mime] Throw exception when body in Email attach method is not ok [VarDumper][VarExporter] Deal with DatePeriod->include_end_date on PHP 8.2 [Cache] Throw when "redis_sentinel" is used with a non-Predis "class" option fix merge Bootstrap 4 fieldset for row errors [Form] Fix same choice loader with different choice values [Filesystem] Safeguard (sym)link calls Fix dumping extension config without bundle [HttpClient] Honor "max_duration" when replacing requests with async decorators [HttpClient] Add missing HttpOptions::setMaxDuration() [HttpFoundation] [Session] Overwrite invalid session id
2 parents c9c86b0 + 6b0d0e4 commit 05abe9a

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Session/Storage/NativeSessionStorage.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,12 @@ public function start(): bool
135135
throw new \RuntimeException(sprintf('Failed to start the session because headers have already been sent by "%s" at line %d.', $file, $line));
136136
}
137137

138+
$sessionId = $_COOKIE[session_name()] ?? null;
139+
if ($sessionId && !preg_match('/^[a-zA-Z0-9,-]{22,}$/', $sessionId)) {
140+
// the session ID in the header is invalid, create a new one
141+
session_id(session_create_id());
142+
}
143+
138144
// ok to try and start the session
139145
if (!session_start()) {
140146
throw new \RuntimeException('Failed to start the session.');

Tests/Session/Storage/NativeSessionStorageTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,4 +283,13 @@ public function testGetBagsOnceSessionStartedIsIgnored()
283283

284284
$this->assertEquals($storage->getBag('flashes'), $bag);
285285
}
286+
287+
public function testRegenerateInvalidSessionId()
288+
{
289+
$_COOKIE[session_name()] = '&~[';
290+
$started = (new NativeSessionStorage())->start();
291+
292+
$this->assertTrue($started);
293+
$this->assertMatchesRegularExpression('/^[a-zA-Z0-9,-]{22,}$/', session_id());
294+
}
286295
}

0 commit comments

Comments
 (0)