Make WordPress Core


Ignore:
Timestamp:
02/02/2016 04:59:00 PM (10 years ago)
Author:
ocean90
Message:

Better validation of the URL used in HTTP redirects.

Merges [36444] to the 4.3 branch.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/4.3/src/wp-includes/pluggable.php

    r34118 r36448  
    13131313    $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;
    13141314
    1315     $lp  = parse_url($test);
     1315    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
     1316    $lp = @parse_url($test);
    13161317
    13171318    // Give up if malformed URL
     
    13231324        return $default;
    13241325
    1325     // Reject if scheme is set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
    1326     if ( isset($lp['scheme'])  && !isset($lp['host']) )
     1326    // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field.
     1327    if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
    13271328        return $default;
     1329    }
     1330
     1331    // Reject malformed components parse_url() can return on odd inputs.
     1332    foreach ( array( 'user', 'pass', 'host' ) as $component ) {
     1333        if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) {
     1334            return $default;
     1335        }
     1336    }
    13281337
    13291338    $wpp = parse_url(home_url());
Note: See TracChangeset for help on using the changeset viewer.