Make WordPress Core

Changeset 60240


Ignore:
Timestamp:
05/17/2025 01:29:20 PM (8 months ago)
Author:
SergeyBiryukov
Message:

Login and Registration: Check that $_POST value is a string in retrieve_password().

This prevents a fatal error from trim() if an array is passed instead.

Follow-up to [6643], [19056], [41782], [50129], [50140], [59595].

Props leedxw, dilipbheda, mukesh27, SergeyBiryukov.
Fixes #63433.

Location:
trunk
Files:
2 edited

Legend:

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

    r60178 r60240  
    31733173
    31743174    // Use the passed $user_login if available, otherwise use $_POST['user_login'].
    3175     if ( ! $user_login && ! empty( $_POST['user_login'] ) ) {
     3175    if ( ! $user_login && ! empty( $_POST['user_login'] ) && is_string( $_POST['user_login'] ) ) {
    31763176        $user_login = $_POST['user_login'];
    31773177    }
  • trunk/tests/phpunit/tests/user/retrievePassword.php

    r59312 r60240  
    8888        $this->assertWPError( retrieve_password() );
    8989    }
     90
     91    /**
     92     * Tests that a fatal error is not thrown when the login passed via `$_POST`
     93     * is an array instead of a string.
     94     *
     95     * The message that we should not see:
     96     * `TypeError: trim(): Argument #1 ($string) must be of type string, array given`.
     97     *
     98     * @ticket 62794
     99     */
     100    public function test_retrieve_password_does_not_throw_fatal_error_with_array_parameters() {
     101        $_POST['user_login'] = array( 'example' );
     102
     103        $error = retrieve_password();
     104        $this->assertWPError( $error, 'The result should be an instance of WP_Error.' );
     105
     106        $error_codes = $error->get_error_codes();
     107        $this->assertContains( 'empty_username', $error_codes, 'The "empty_username" error code should be present.' );
     108    }
    90109}
Note: See TracChangeset for help on using the changeset viewer.