Skip to content

Commit 19b4bf0

Browse files
bug #57585 [HttpFoundation] Fix MockArraySessionStorage to generate more conform ids (Seldaek)
This PR was merged into the 5.4 branch. Discussion ---------- [HttpFoundation] Fix MockArraySessionStorage to generate more conform ids | Q | A | ------------- | --- | Branch? | 5.4 | Bug fix? | yes | New feature? | no | Deprecations? | no | Issues | | License | MIT Per https://wiki.php.net/rfc/deprecations_php_8_4#sessionsid_length_and_sessionsid_bits_per_character the session id really shouldn't need more than 128bits of entropy, which this PR uses. While this code indeed does not need cryptographically secure level of entropy, it also doesn't really cost that much so I did it this way, as it's IMO good to avoid having cryptographically-insecure code out there where people might take inspiration from it. As an aside, uniqid might also end up being deprecated, so it's good to get rid of it anyway here https://wiki.php.net/rfc/deprecations_php_8_4#deprecate_uniqid And as another aside, I've had to override this code in the past because we had DB tables storing session ids not accepting the 64chars long session ids the old code produces, so producing shorter (32chars) ids is more compatible 👍🏻 Commits ------- 19debc1 Fix MockArraySessionStorage to generate more conform ids
2 parents 5ab86e7 + 19debc1 commit 19b4bf0

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

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

+1-4
Original file line numberDiff line numberDiff line change
@@ -226,14 +226,11 @@ public function getMetadataBag()
226226
/**
227227
* Generates a session ID.
228228
*
229-
* This doesn't need to be particularly cryptographically secure since this is just
230-
* a mock.
231-
*
232229
* @return string
233230
*/
234231
protected function generateId()
235232
{
236-
return hash('sha256', uniqid('ss_mock_', true));
233+
return bin2hex(random_bytes(16));
237234
}
238235

239236
protected function loadSession()

0 commit comments

Comments
 (0)