Use random_bytes instead of mt_rand for sessionCreateId #46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
According to https://www.php.net/manual/function.mt-rand.php, mt_rand "must not be used for cryptographic purposes". But according to the source code: https://github.com/php/php-src/blob/e72b6f471aaabafc35ee5f7e1259ebd441da7d66/ext/random/engine_mt19937.c#L240 the default seed is generated by random_bytes, so it is secure to use mt_rand together with mt_srand. However, since mt_srand uses random_bytes, it makes more sense to just use random_bytes instead, which is secure according to the documentation without need to investigate the source code.
This commit also makes the session ID longer to contain more entropy.
mt_srand
uses 4 random bytes instead of 8, so if this little performance is required we can also change torandom_bytes(4)
instead.See also: walkor/workerman@c2dde2e