Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c4b72b

Browse files
committed
[HttpFoundation][Session] Ignore invalid session id.
1 parent ce4a1a9 commit 8c4b72b

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

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

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

155+
$sessionName = session_name();
156+
$sessionId = $_COOKIE[$sessionName] ?? null;
157+
// validate according to https://www.php.net/manual/fr/function.session-start.php
158+
if ($sessionId && !preg_match('/^[a-zA-Z0-9,\-]{1,123}$/', $sessionId)) {
159+
unset($_COOKIE[$sessionName]);
160+
}
161+
155162
// ok to try and start the session
156163
if (!session_start()) {
157164
throw new \RuntimeException('Failed to start the session.');

0 commit comments

Comments
 (0)