Make WordPress Core


Ignore:
Timestamp:
01/09/2025 07:41:47 PM (6 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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.