Use random_bytes() when generating OAuth nonces.
mt_rand() is not cryptographically secure. This probably doesn't matter that much in most cases because it only affects BitBucket API interactions that already happen over HTTPS, but why not use a better option when it's available? Closes #233
This commit is contained in:
parent
f11ffce720
commit
ea633a91b3
|
|
@ -80,7 +80,19 @@ if ( !class_exists('Puc_v4p4_OAuthSignature', false) ):
|
|||
*/
|
||||
private function nonce() {
|
||||
$mt = microtime();
|
||||
$rand = mt_rand();
|
||||
|
||||
$rand = null;
|
||||
if ( is_callable('random_bytes') ) {
|
||||
try {
|
||||
$rand = random_bytes(16);
|
||||
} catch (Exception $ex) {
|
||||
//Fall back to mt_rand (below).
|
||||
}
|
||||
}
|
||||
if ( $rand === null ) {
|
||||
$rand = mt_rand();
|
||||
}
|
||||
|
||||
return md5($mt . '_' . $rand);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue