Skip to content

Commit 827e43a

Browse files
committed
Ensure strings are compared with hash_equals
For time-constant string comparison, we need to use a better comparison than PHP's built-in `===` operator. WordPress has the hash_equals function to do this, available since 3.9.2. Thanks to @sarciszewski for reporting this responsibly, and apologies to him for our late response.
1 parent 45197ec commit 827e43a

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lib/class-wp-json-authentication-oauth1.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ public function check_token( $token, $consumer_key ) {
287287
return $consumer;
288288
}
289289

290-
if ( $token['consumer'] !== $consumer->ID ) {
290+
if ( ! hash_equals( $token['consumer'], $consumer->ID ) ) {
291291
return new WP_Error( 'json_oauth1_consumer_mismatch', __( 'Token is not registered for the given consumer' ), array( 'status' => 401 ) );
292292
}
293293

@@ -559,7 +559,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
559559

560560
$signature = base64_encode( hash_hmac( $hash_algorithm, $string_to_sign, $key, true ) );
561561

562-
if ( $signature !== $consumer_signature ) {
562+
if ( ! hash_equals( $signature, $consumer_signature ) ) {
563563
return new WP_Error( 'json_oauth1_signature_mismatch', __( 'OAuth signature does not match' ), array( 'status' => 401 ) );
564564
}
565565

0 commit comments

Comments
 (0)