Make WordPress Core

Changeset 64997


Ignore:
Timestamp:
10/29/2026 01:01:41 AM (4 weeks ago)
Author:
westonruter
Message:

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 ​https://github.com/WordPress/wordpress-develop/pull/14991.
Follow-up to r49090.

Props bor0.
See #51351.
Fixes #66389.

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/user.php

    r64436 r64997  
    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        }
  • trunk/tests/phpunit/tests/auth.php

    r64991 r64997  
    974974
    975975        /**
     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
     992        /**
    976993         * @ticket 21022
    977994         */
Note: See TracChangeset for help on using the changeset viewer.