Make WordPress Core

Changeset 56804

Timestamp:
10/09/2023 02:47:57 PM (10 months ago)
Author:
kadamwhite
Message:

REST API: Correct parsing of password from Authorization header when processing Application Password credentials.

Exit early when parsing Application Password credentials if Authorization header value does not contain at least one colon. The Authorization Basic header must use a colon to separate the username and password components per RFC 7617, so a username-only string is malformed and should not be processed.

Split Authorization header only on the first colon, properly handling passwords containing colons.

Resolves PHP 8.0 warning when list() was called on an exploded credentials array containing only one element.

Props kalpeshh, shooper, sc0ttkclark, jrf, mukesh27, oglekler, nicolefurlan.
Fixes #57512.

Location:
trunk
Files:
2 edited

Legend:

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

    r56635 r56804  
    127127    $userpass = base64_decode( $token );
    128128
    129     list( $user, $pass ) = explode( ':', $userpass );
     129    // There must be at least one colon in the string.
     130    if ( ! str_contains( $userpass, ':' ) ) {
     131        return;
     132    }
     133
     134    list( $user, $pass ) = explode( ':', $userpass, 2 );
    130135
    131136    // Now shove them in the proper keys where we're expecting later on.
  • trunk/tests/phpunit/tests/auth.php

    r56454 r56804  
    845845        );
    846846    }
     847
     848
     849
     850
     851
     852
     853
     854
     855
     856
     857
     858
     859
     860
     861
     862
     863
     864
     865
     866
     867
     868
     869
     870
     871
     872
     873
     874
     875
     876
     877
     878
     879
     880
     881
     882
     883
     884
     885
     886
     887
     888
    847889}
Note: See TracChangeset for help on using the changeset viewer.