Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"OAuth signature does not match" error after upgrade to 0.4.2 #237

Closed
szaqal83 opened this issue Dec 6, 2023 · 3 comments · Fixed by #239
Closed

"OAuth signature does not match" error after upgrade to 0.4.2 #237

szaqal83 opened this issue Dec 6, 2023 · 3 comments · Fixed by #239
Milestone

Comments

@szaqal83
Copy link

szaqal83 commented Dec 6, 2023

After 2 days of checking I've found the problem, in short, version 0.4.x (0.4.2 for sure) added extra sanitize_text_field() in get_authorization_header() method of WP_REST_OAuth1 class (wp-content\plugins\rest-api-oauth1\lib\class-wp-rest-oauth1.php line 87) - version 0.3.0 didn't had it and it worked. This extra sanitization causes removal of padding equal sign (=) from oauth_signature string (base64 encoded) in auth header and this causes signature mismatch here (line 742):

if ( ! hash_equals( $signature, $consumer_signature ) )

at this point with extra sanitization vars look like:

$signature = "2jnndRHY0XmcoLAKQ57BTk3hFuY="
$consumer_signature = "UxNEGv4G7XLC8deayKGWTdUmt0"

without extra sanitization, changing line 87 mentioned above from return sanitize_text_field( wp_unslash( $_SERVER['HTTP_AUTHORIZATION'] ) ); to return wp_unslash( $_SERVER['HTTP_AUTHORIZATION'] );

they are:

$signature = "eo/0c0cV8mGq3srFuKowKTtuVBg="
$consumer_signature = "eo/0c0cV8mGq3srFuKowKTtuVBg="

and everything works fine.

@szaqal83
Copy link
Author

szaqal83 commented Dec 6, 2023

This sanitization breaks even more, auth header before sanitization (only wp_unslash() used) looks like:

'OAuth oauth_consumer_key="xyz", oauth_nonce="xyzxyzxyzxyzxyz", oauth_signature_method="HMAC-SHA1", oauth_timestamp="12345", oauth_version="1.0", oauth_callback="http%3A%2F%2Ftest.loc%2Fpoligon%2Foauth%2Foauth.php", oauth_signature="Kbgqrqyvfh978LNPxWy4KogSEHY%3D"'

after sanitization applied:

'OAuth oauth_consumer_key="xyz", oauth_nonce="xyzxyzxyzxyzxyz", oauth_signature_method="HMAC-SHA1", oauth_timestamp="12345", oauth_version="1.0", oauth_callback="httptest.locpoligonoauthoauth.php", oauth_signature="Kbgqrqyvfh978LNPxWy4KogSEHY"'

beside "%3D" (=) stripped from oauth_signature it also breaks oauth_callback URL.

@fergusbisset
Copy link

Thanks so much for this @szaqal83 :-)

@spacedmonkey spacedmonkey added this to the 0.4.4 milestone Dec 27, 2023
@scottfennell-toptal
Copy link

I see this issue was added to the 0.4.4 release. Any estimate when that release will occur?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants