Make WordPress Core

Changeset 59595


Ignore:
Timestamp:
01/09/2025 07:41:47 PM (5 months ago)
Author:
SergeyBiryukov
Message:

Login and Registration: Check that the $_POST values are strings in wp_signon().

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

Follow-up to [6643], [58093].

Props leedxw, audrasjb, SergeyBiryukov.
Fixes #62794.

Location:
trunk
Files:
2 edited

Legend:

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

    r59377 r59595  
    4949        );
    5050
    51         if ( ! empty( $_POST['log'] ) ) {
     51        if ( ! empty( $_POST['log'] ) && is_string( $_POST['log'] ) ) {
    5252            $credentials['user_login'] = wp_unslash( $_POST['log'] );
    5353        }
    54         if ( ! empty( $_POST['pwd'] ) ) {
     54        if ( ! empty( $_POST['pwd'] ) && is_string( $_POST['pwd'] ) ) {
    5555            $credentials['user_password'] = $_POST['pwd'];
    5656        }
  • trunk/tests/phpunit/tests/auth.php

    r58653 r59595  
    636636
    637637    /**
     638     * Tests that a warning or a fatal error is not thrown when the login or password
     639     * passed via `$_POST` is an array instead of a string.
     640     *
     641     * The messages that we should not see:
     642     * `Warning: wp_strip_all_tags() expects parameter #1 ($text) to be a string, array given`.
     643     * `TypeError: trim(): Argument #1 ($string) must be of type string, array given`.
     644     *
     645     * @ticket 62794
     646     */
     647    public function test_wp_signon_does_not_throw_fatal_errors_with_array_parameters() {
     648        $_POST['log'] = array( 'example' );
     649        $_POST['pwd'] = array( 'example' );
     650
     651        $error = wp_signon();
     652        $this->assertWPError( $error, 'The result should be an instance of WP_Error.' );
     653
     654        $error_codes = $error->get_error_codes();
     655        $this->assertContains( 'empty_username', $error_codes, 'The "empty_username" error code should be present.' );
     656        $this->assertContains( 'empty_password', $error_codes, 'The "empty_password" error code should be present.' );
     657    }
     658
     659    /**
    638660     * HTTP Auth headers are used to determine the current user.
    639661     *
Note: See TracChangeset for help on using the changeset viewer.