security: replace rand() with hrtime(true) for graph cache-buster (GHSA-vhwj-hfwg-gfg3) - #806
security: replace rand() with hrtime(true) for graph cache-buster (GHSA-vhwj-hfwg-gfg3)#806bmfmancini wants to merge 2 commits into
Conversation
somethingwithproof
left a comment
There was a problem hiding this comment.
random_int() can throw Random\RandomException when the platform CSPRNG fails, which would make threshold editing fatal merely to produce a non-security cache-buster. This URL parameter is not a secret or security boundary, so a CSPRNG is the wrong reliability tradeoff. Please use a non-throwing cache version (for example a timestamp/monotonic value) or catch the exception, add a focused Pest assertion through Cacti Composer, and add the CHANGELOG entry. The integration matrix is currently red.
…245) Replaces the non-cryptographic PRNG rand() with hrtime(true), a monotonic nanosecond clock that never throws. This URL parameter is a cache-buster, not a security boundary, so a CSPRNG (random_int) is the wrong reliability tradeoff — it can throw Random\RandomException on CSPRNG failure, making threshold editing fatal. hrtime(true) provides: - Never throws (no CSPRNG dependency) - Monotonic (never goes backwards on NTP step) - Nanosecond resolution (no collisions on fast page renders) - Returns int (clean URL query parameter) Fixes GHSA-vhwj-hfwg-gfg3 Rule: php:S2245 (CWE-338)
eb78754 to
8d3abd0
Compare
|
The latest revision fixes the non-throwing cache-buster implementation, but the regression test still exercises mt_rand() while production now calls hrtime(true), so it cannot fail if the production line regresses. The CHANGELOG also contains both an mt_rand entry and an hrtime entry. Please make the test assert the actual thold.php behavior, keep one accurate CHANGELOG entry, and remove the unrelated duplicated workflow changes (including removal of the advisory develop matrix) from this security fix. |
Security Fix — GHSA-vhwj-hfwg-gfg3
Fixes GHSA-vhwj-hfwg-gfg3
Summary
The threshold editing page in
thold.phpused PHP'srand()function (line 1278) to generate a cache-buster query parameter for a graph image URL.rand()is not a cryptographically secure pseudo-random number generator (CSPRNG).Vulnerability Details
php:S2245(SonarQube)thold.php, line 1278Changes
Replaced
rand()withhrtime(true), a monotonic nanosecond clock that never throws.Why not
random_int()? An initial fix usedrandom_int(0, PHP_INT_MAX), but reviewer feedback correctly identified thatrandom_int()can throwRandom\RandomExceptionwhen the platform CSPRNG fails. This URL parameter is a cache-buster, not a security boundary, so a CSPRNG is the wrong reliability tradeoff — it would make threshold editing fatal merely to produce a non-security cache-buster.hrtime(true)provides:php:S2245entirely (no "random" function to flag)Testing
php -l thold.php)php:S2245is CLOSED