Skip to content

Commit 1d17f20

Browse files
committed
Merge branch '6.0' into 6.1
* 6.0: ignore the cached body when comparing e-mails for equality fix PHP syntax to be compatible with 7.2 and 7.3 [HttpFoundation] Add session ID regex comment [Workflow] Fix typo in MethodMarkingStore Fix CS
2 parents 6d5d6c5 + 183d99d commit 1d17f20

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

Session/Storage/NativeSessionStorage.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,36 @@ public function start(): bool
136136
}
137137

138138
$sessionId = $_COOKIE[session_name()] ?? null;
139+
/*
140+
* Explanation of the session ID regular expression: `/^[a-zA-Z0-9,-]{22,250}$/`.
141+
*
142+
* ---------- Part 1
143+
*
144+
* The part `[a-zA-Z0-9,-]` is related to the PHP ini directive `session.sid_bits_per_character` defined as 6.
145+
* See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character.
146+
* Allowed values are integers such as:
147+
* - 4 for range `a-f0-9`
148+
* - 5 for range `a-v0-9`
149+
* - 6 for range `a-zA-Z0-9,-`
150+
*
151+
* ---------- Part 2
152+
*
153+
* The part `{22,250}` is related to the PHP ini directive `session.sid_length`.
154+
* See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-length.
155+
* Allowed values are integers between 22 and 256, but we use 250 for the max.
156+
*
157+
* Where does the 250 come from?
158+
* - The length of Windows and Linux filenames is limited to 255 bytes. Then the max must not exceed 255.
159+
* - The session filename prefix is `sess_`, a 5 bytes string. Then the max must not exceed 255 - 5 = 250.
160+
*
161+
* ---------- Conclusion
162+
*
163+
* The parts 1 and 2 prevent the warning below:
164+
* `PHP Warning: SessionHandler::read(): Session ID is too long or contains illegal characters. Only the A-Z, a-z, 0-9, "-", and "," characters are allowed.`
165+
*
166+
* The part 2 prevents the warning below:
167+
* `PHP Warning: SessionHandler::read(): open(filepath, O_RDWR) failed: No such file or directory (2).`
168+
*/
139169
if ($sessionId && $this->saveHandler instanceof AbstractProxy && 'files' === $this->saveHandler->getSaveHandlerName() && !preg_match('/^[a-zA-Z0-9,-]{22,250}$/', $sessionId)) {
140170
// the session ID in the header is invalid, create a new one
141171
session_id(session_create_id());

0 commit comments

Comments
 (0)