You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
minor #46825 [HttpFoundation] Add session ID regex comment (BrokenSourceCode)
This PR was squashed before being merged into the 4.4 branch.
Discussion
----------
[HttpFoundation] Add session ID regex comment
| Q | A
| ------------- | ---
| Branch? | 4.4
| Bug fix? | no
| New feature? | no
| Deprecations? | no
| License | MIT
A comment intended to explain the session ID regular expression.
Related links:
- #46777
- #46790
Commits
-------
4908090 [HttpFoundation] Add session ID regex comment
Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpFoundation/Session/Storage/NativeSessionStorage.php
+30Lines changed: 30 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -153,6 +153,36 @@ public function start()
153
153
}
154
154
155
155
$sessionId = $_COOKIE[session_name()] ?? null;
156
+
/*
157
+
* Explanation of the session ID regular expression: `/^[a-zA-Z0-9,-]{22,250}$/`.
158
+
*
159
+
* ---------- Part 1
160
+
*
161
+
* The part `[a-zA-Z0-9,-]` is related to the PHP ini directive `session.sid_bits_per_character` defined as 6.
162
+
* See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-bits-per-character.
163
+
* Allowed values are integers such as:
164
+
* - 4 for range `a-f0-9`
165
+
* - 5 for range `a-v0-9`
166
+
* - 6 for range `a-zA-Z0-9,-`
167
+
*
168
+
* ---------- Part 2
169
+
*
170
+
* The part `{22,250}` is related to the PHP ini directive `session.sid_length`.
171
+
* See https://www.php.net/manual/en/session.configuration.php#ini.session.sid-length.
172
+
* Allowed values are integers between 22 and 256, but we use 250 for the max.
173
+
*
174
+
* Where does the 250 come from?
175
+
* - The length of Windows and Linux filenames is limited to 255 bytes. Then the max must not exceed 255.
176
+
* - The session filename prefix is `sess_`, a 5 bytes string. Then the max must not exceed 255 - 5 = 250.
177
+
*
178
+
* ---------- Conclusion
179
+
*
180
+
* The parts 1 and 2 prevent the warning below:
181
+
* `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.`
182
+
*
183
+
* The part 2 prevents the warning below:
184
+
* `PHP Warning: SessionHandler::read(): open(filepath, O_RDWR) failed: No such file or directory (2).`
0 commit comments