Use of predictable RNG for password generation in pkp/pkp-lib
Reported on
Jul 5th 2023
Description
pkp-lib implements a password-generation function with the following line of code being integral to its functionality:
for (...) {
$password .= mt_rand(1, 4) == 4 ? $numbers[mt_rand(0, strlen($numbers) - 1)] : $letters[mt_rand(0, strlen($letters) - 1)];
}
This relies upon mt_rand(low, high);
to generate a secure value that nobody should be able to predict; mt_rand
is considered unsafe and contains a disclosure in its documentation noting that Randomizer-based functions should be used in the event of unpredictability being at all important.
There have been several instances of mt_rand
being exploited, with this blog post providing a decent outline of how an adversary can derive future mt_rand
outcomes with little more than two previous values.
Additionally, the function is seeded using mt_srand
here, where the current time is used as the seed of the mersenne twister function - meaning that an attacker with knowledge of the time that the function was seeded (or can guess that time) is also able to predict all future outcomes of the function, and hence future outcomes of generatePassword($length)
.
Impact
Allowing attackers to predict passwords/tokens provides them with simple access to users' accounts (+1, +2) and access tokens, all of which would have catastrophic impact for affected victims.
Thanks for reporting; this is filed and fixed here: https://github.com/pkp/pkp-lib/issues/9138
Hi Alec,
Great work on getting this fixed, would it be possible to know which CVE-ID has been reserved for this report?