Email: Compare token with hash_equals() to mitigate timing attacks.

Props timothyblynjacobs
See #46
See https://make.wordpress.org/meta/2019/10/25/security-review-of-authentication-tokens/
This commit is contained in:
Ian Dunn 2019-10-25 13:47:59 -07:00
parent 838a490776
commit 35fa99324e
No known key found for this signature in database
GPG key ID: 99B971B50343CBCB

View file

@ -128,7 +128,11 @@ function is_valid_authentication_token( $pledge_id, $action, $unverified_token )
return false;
}
if ( $valid_token && $valid_token['expiration'] > time() && $unverified_token === $valid_token['value'] ) {
if ( ! is_string( $unverified_token ) || TOKEN_LENGTH !== strlen( $unverified_token ) ) {
return false;
}
if ( $valid_token && $valid_token['expiration'] > time() && hash_equals( $valid_token['value'], $unverified_token ) ) {
$verified = true;
// Tokens should not be reusable, to increase security.