Skip to content

Commit c9434c9

Browse files
committed
fix!: we force PHP defaults of session.sid_bits_per_character/session.sid_length
They are deprecated in PHP 8.4.
1 parent 8b034b8 commit c9434c9

File tree

2 files changed

+26
-57
lines changed

2 files changed

+26
-57
lines changed

system/Session/Handlers/FileHandler.php

+13-20
Original file line numberDiff line numberDiff line change
@@ -309,32 +309,25 @@ public function gc($max_lifetime)
309309

310310
/**
311311
* Configure Session ID regular expression
312+
*
313+
* To make life easier, we force the PHP defaults. Because PHP9 forces them.
314+
* See https://wiki.php.net/rfc/deprecations_php_8_4#sessionsid_length_and_sessionsid_bits_per_character
312315
*/
313316
protected function configureSessionIDRegex()
314317
{
315318
$bitsPerCharacter = (int) ini_get('session.sid_bits_per_character');
316-
$SIDLength = (int) ini_get('session.sid_length');
317-
318-
if (($bits = $SIDLength * $bitsPerCharacter) < 160) {
319-
// Add as many more characters as necessary to reach at least 160 bits
320-
$SIDLength += (int) ceil((160 % $bits) / $bitsPerCharacter);
321-
ini_set('session.sid_length', (string) $SIDLength);
322-
}
323-
324-
switch ($bitsPerCharacter) {
325-
case 4:
326-
$this->sessionIDRegex = '[0-9a-f]';
327-
break;
319+
$sidLength = (int) ini_get('session.sid_length');
328320

329-
case 5:
330-
$this->sessionIDRegex = '[0-9a-v]';
331-
break;
332-
333-
case 6:
334-
$this->sessionIDRegex = '[0-9a-zA-Z,-]';
335-
break;
321+
// We force the PHP defaults.
322+
if (PHP_VERSION_ID < 90000) {
323+
if ($bitsPerCharacter !== 4) {
324+
ini_set('session.sid_bits_per_character', '4');
325+
}
326+
if ($sidLength !== 32) {
327+
ini_set('session.sid_length', '32');
328+
}
336329
}
337330

338-
$this->sessionIDRegex .= '{' . $SIDLength . '}';
331+
$this->sessionIDRegex = '[0-9a-f]{32}';
339332
}
340333
}

system/Session/Session.php

+13-37
Original file line numberDiff line numberDiff line change
@@ -316,49 +316,25 @@ protected function configure()
316316
/**
317317
* Configure session ID length
318318
*
319-
* To make life easier, we used to force SHA-1 and 4 bits per
320-
* character on everyone. And of course, someone was unhappy.
321-
*
322-
* Then PHP 7.1 broke backwards-compatibility because ext/session
323-
* is such a mess that nobody wants to touch it with a pole stick,
324-
* and the one guy who does, nobody has the energy to argue with.
325-
*
326-
* So we were forced to make changes, and OF COURSE something was
327-
* going to break and now we have this pile of shit. -- Narf
319+
* To make life easier, we force the PHP defaults. Because PHP9 forces them.
320+
* See https://wiki.php.net/rfc/deprecations_php_8_4#sessionsid_length_and_sessionsid_bits_per_character
328321
*/
329322
protected function configureSidLength()
330323
{
331-
$bitsPerCharacter = (int) (ini_get('session.sid_bits_per_character') !== false
332-
? ini_get('session.sid_bits_per_character')
333-
: 4);
334-
335-
$sidLength = (int) (ini_get('session.sid_length') !== false
336-
? ini_get('session.sid_length')
337-
: 40);
338-
339-
if (($sidLength * $bitsPerCharacter) < 160) {
340-
$bits = ($sidLength * $bitsPerCharacter);
341-
// Add as many more characters as necessary to reach at least 160 bits
342-
$sidLength += (int) ceil((160 % $bits) / $bitsPerCharacter);
343-
ini_set('session.sid_length', (string) $sidLength);
344-
}
324+
$bitsPerCharacter = (int) ini_get('session.sid_bits_per_character');
325+
$sidLength = (int) ini_get('session.sid_length');
345326

346-
// Yes, 4,5,6 are the only known possible values as of 2016-10-27
347-
switch ($bitsPerCharacter) {
348-
case 4:
349-
$this->sidRegexp = '[0-9a-f]';
350-
break;
351-
352-
case 5:
353-
$this->sidRegexp = '[0-9a-v]';
354-
break;
355-
356-
case 6:
357-
$this->sidRegexp = '[0-9a-zA-Z,-]';
358-
break;
327+
// We force the PHP defaults.
328+
if (PHP_VERSION_ID < 90000) {
329+
if ($bitsPerCharacter !== 4) {
330+
ini_set('session.sid_bits_per_character', '4');
331+
}
332+
if ($sidLength !== 32) {
333+
ini_set('session.sid_length', '32');
334+
}
359335
}
360336

361-
$this->sidRegexp .= '{' . $sidLength . '}';
337+
$this->sidRegexp = '[0-9a-f]{32}';
362338
}
363339

364340
/**

0 commit comments

Comments
 (0)