Skip to content

Commit a48e180

Browse files
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. git-svn-id: https://develop.svn.wordpress.org/trunk@59595 602fd350-edb4-49c9-b593-d223f7449a82
1 parent c53397d commit a48e180

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

src/wp-includes/user.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,10 @@ function wp_signon( $credentials = array(), $secure_cookie = '' ) {
4848
'remember' => false,
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
}
5757
if ( ! empty( $_POST['rememberme'] ) ) {

tests/phpunit/tests/auth.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,28 @@ public function test_wp_signon_does_not_throw_deprecation_notices_with_default_p
634634
$this->assertContains( 'empty_password', $error_codes, 'The "empty_password" error code should be present.' );
635635
}
636636

637+
/**
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+
637659
/**
638660
* HTTP Auth headers are used to determine the current user.
639661
*

0 commit comments

Comments
 (0)