Skip to content

Commit d49cecb

Browse files
committed
Privacy: Avoid PHP warnings for invalid request IDs.
When the checks in `wp_validate_user_request_key()` were consolidated in r49090, the `confirm_key` and `modified_timestamp` properties came to be read before the request was confirmed to exist. A confirmation link whose `request_id` is not a `user_request` post, as is common with bot probes of `wp-login.php?action=confirmaction`, therefore logged two "Attempt to read property on false" warnings before returning the `invalid_request` error. The error is now returned as soon as the lookup fails, so the returned errors are unchanged. Developed in #14991. Follow-up to r49090. Props bor0. See #51351. Fixes #66389. git-svn-id: https://develop.svn.wordpress.org/trunk@64997 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 1021d4d commit d49cecb

2 files changed

Lines changed: 25 additions & 3 deletions

File tree

‎src/wp-includes/user.php‎

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5126,12 +5126,17 @@ function wp_validate_user_request_key(
51265126
#[\SensitiveParameter]
51275127
$key
51285128
) {
5129-
$request_id = absint( $request_id );
5130-
$request = wp_get_user_request( $request_id );
5129+
$request_id = absint( $request_id );
5130+
$request = wp_get_user_request( $request_id );
5131+
5132+
if ( ! $request ) {
5133+
return new WP_Error( 'invalid_request', __( 'Invalid personal data request.' ) );
5134+
}
5135+
51315136
$saved_key = $request->confirm_key;
51325137
$key_request_time = $request->modified_timestamp;
51335138

5134-
if ( ! $request || ! $saved_key || ! $key_request_time ) {
5139+
if ( ! $saved_key || ! $key_request_time ) {
51355140
return new WP_Error( 'invalid_request', __( 'Invalid personal data request.' ) );
51365141
}
51375142

‎tests/phpunit/tests/auth.php‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -972,6 +972,23 @@ public function test_expired_phpass_user_activation_key_is_rejected() {
972972
$this->assertSame( 'invalid_key', $check->get_error_code() );
973973
}
974974

975+
/**
976+
* Ensures an ID that does not belong to a user request is rejected without warnings.
977+
*
978+
* @ticket 66389
979+
*/
980+
public function test_user_request_key_handling_for_missing_request() {
981+
$post_id = self::factory()->post->create();
982+
983+
$check = wp_validate_user_request_key( $post_id, 'invalid' );
984+
$this->assertWPError( $check );
985+
$this->assertSame( 'invalid_request', $check->get_error_code() );
986+
987+
$check = wp_validate_user_request_key( PHP_INT_MAX, 'invalid' );
988+
$this->assertWPError( $check );
989+
$this->assertSame( 'invalid_request', $check->get_error_code() );
990+
}
991+
975992
/**
976993
* @ticket 21022
977994
*/

0 commit comments

Comments
 (0)