Skip to content

Commit 83f5a99

Browse files
committed
Fix signature check for sub-folder WP installs
Signature checking duplicates the WP install folder when building the request URI. For example, if you have a WordPress running on "www.example.com/wp", the signature checker will use URLs like "www.example.com/wp/wp/...". This commit removes the WordPress base directory from the checked path. See !32, #34, #27
1 parent 4ca54cf commit 83f5a99

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,12 @@ 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+
$request_path = parse_url( $_SERVER['REQUEST_URI'], PHP_URL_PATH );
555+
$wp_base = get_home_url( null, '/', 'relative' );
556+
if ( substr( $request_path, 0, strlen( $wp_base ) ) === $wp_base ) {
557+
$request_path = substr( $request_path, strlen( $wp_base ) );
558+
}
559+
$base_request_uri = rawurlencode( get_home_url( null, $request_path ) );
555560

556561
// get the signature provided by the consumer and remove it from the parameters prior to checking the signature
557562
$consumer_signature = rawurldecode( $params['oauth_signature'] );

0 commit comments

Comments
 (0)