Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use random_bytes instead of mt_rand for sessionCreateId #46

Merged
merged 1 commit into from
Sep 6, 2023

Conversation

ouuan
Copy link
Contributor

@ouuan ouuan commented Sep 6, 2023

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 to random_bytes(4) instead.

See also: walkor/workerman@c2dde2e

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.
@joanhey joanhey merged commit dedfc6c into joanhey:master Sep 6, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants