Skip to content

Commit f6036f3

Browse files
committed
Ensure OAuth1 signature is created as per the spec
1 parent 161b675 commit f6036f3

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
551551

552552
$params = array_merge( $params, $oauth_params );
553553

554-
$base_request_uri = rawurlencode( get_home_url( null, parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) ) );
554+
$base_request_uri = get_home_url( null, parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH ) );
555555

556556
// get the signature provided by the consumer and remove it from the parameters prior to checking the signature
557557
$consumer_signature = rawurldecode( $params['oauth_signature'] );
@@ -567,7 +567,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
567567
$query_string = $this->create_signature_string( $params );
568568

569569
$token = (array) $token;
570-
$string_to_sign = $http_method . '&' . $base_request_uri . '&' . $query_string;
570+
$string_to_sign = $http_method . '&' . rawurlencode( $base_request_uri ) . '&' . rawurlencode( $query_string );
571571
$key_parts = array(
572572
$consumer->secret,
573573
( $token ? $token['secret'] : '' )
@@ -604,7 +604,7 @@ protected function check_oauth_signature( $consumer, $oauth_params, $token = nul
604604
* @return string Signature string
605605
*/
606606
public function create_signature_string( $params ) {
607-
return implode( '%26', $this->join_with_equals_sign( $params ) ); // join with ampersand
607+
return implode( '&', $this->join_with_equals_sign( $params ) ); // join with ampersand
608608
}
609609

610610
/**
@@ -624,8 +624,8 @@ public function join_with_equals_sign( $params, $query_params = array(), $key =
624624
if ( $key ) {
625625
$param_key = $key . '[' . $param_key . ']'; // Handle multi-dimensional array
626626
}
627-
$string = $param_key . '=' . $param_value; // join with equals sign
628-
$query_params[] = urlencode( $string );
627+
$string = rawurlencode( $param_key ) . '=' . rawurlencode( $param_value ); // join with equals sign
628+
$query_params[] = $string;
629629
}
630630
}
631631
return $query_params;

0 commit comments

Comments
 (0)