Skip to content

Commit 0c81ee9

Browse files
committed
Merge branch '4.4' into 5.4
* 4.4: 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 2bd5bb1 + 3c731fd commit 0c81ee9

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
@@ -146,6 +146,36 @@ public function start()
146146
}
147147

148148
$sessionId = $_COOKIE[session_name()] ?? null;
149+
/*
150+
* Explanation of the session ID regular expression: `/^[a-zA-Z0-9,-]{22,250}$/`.
151+
*
152+
* ---------- Part 1
153+
*
154+
* The part `[a-zA-Z0-9,-]` is related to the PHP ini directive `session.sid_bits_per_character` defined as 6.
155+
* See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character.
156+
* Allowed values are integers such as:
157+
* - 4 for range `a-f0-9`
158+
* - 5 for range `a-v0-9`
159+
* - 6 for range `a-zA-Z0-9,-`
160+
*
161+
* ---------- Part 2
162+
*
163+
* The part `{22,250}` is related to the PHP ini directive `session.sid_length`.
164+
* See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-length.
165+
* Allowed values are integers between 22 and 256, but we use 250 for the max.
166+
*
167+
* Where does the 250 come from?
168+
* - The length of Windows and Linux filenames is limited to 255 bytes. Then the max must not exceed 255.
169+
* - The session filename prefix is `sess_`, a 5 bytes string. Then the max must not exceed 255 - 5 = 250.
170+
*
171+
* ---------- Conclusion
172+
*
173+
* The parts 1 and 2 prevent the warning below:
174+
* `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.`
175+
*
176+
* The part 2 prevents the warning below:
177+
* `PHP Warning: SessionHandler::read(): open(filepath, O_RDWR) failed: No such file or directory (2).`
178+
*/
149179
if ($sessionId && $this->saveHandler instanceof AbstractProxy && 'files' === $this->saveHandler->getSaveHandlerName() && !preg_match('/^[a-zA-Z0-9,-]{22,250}$/', $sessionId)) {
150180
// the session ID in the header is invalid, create a new one
151181
session_id(session_create_id());

0 commit comments

Comments
 (0)