Skip to content

Conversation

@yann-eugone
Copy link
Collaborator

@yann-eugone yann-eugone commented Dec 3, 2025

This PR deprecates the usage of openssl_random_pseudo_bytes in favor of the native random_bytes function.

Key Changes:

  1. Security Standard Upgrade (CSPRNG): Switched to random_bytes, which is currently considered the industry state-of-the-art for generating cryptographic entropy in PHP. Unlike OpenSSL, it is native to the language and provides a fail-closed mechanism (throws an Exception instead of returning weak data if entropy is insufficient).

  2. Length Accuracy: Implemented a calculation logic to ensure the generated hex string matches exactly the requested $length.

References & Resources:

Why this change is necessary
openssl_random_pseudo_bytes relies on the OpenSSL extension availability and historically required manual verification of the $crypto_strong boolean to avoid silent failures. random_bytes abstracts access to the OS's entropy source (e.g., /dev/urandom) securely and natively.

@yann-eugone yann-eugone changed the title Replace OpenSSL token generator with bin2hex + random_bytes PHP native functions Replace OpenSSL with native CSPRNG for token generation Dec 3, 2025
@yann-eugone yann-eugone merged commit dd030c0 into 4.x Dec 3, 2025
8 checks passed
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