Make WordPress Core


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

Better validation of the URL used in HTTP redirects.

Merges [36444] to the 4.1 branch.

File:
1 edited

Legend:

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

    r30684 r36450  
    12531253    $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;
    12541254
    1255     $lp  = parse_url($test);
     1255    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
     1256    $lp = @parse_url($test);
    12561257
    12571258    // Give up if malformed URL
     
    12631264        return $default;
    12641265
    1265     // 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.
    1266     if ( isset($lp['scheme'])  && !isset($lp['host']) )
     1266    // 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.
     1267    if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
    12671268        return $default;
     1269    }
     1270
     1271    // Reject malformed components parse_url() can return on odd inputs.
     1272    foreach ( array( 'user', 'pass', 'host' ) as $component ) {
     1273        if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) {
     1274            return $default;
     1275        }
     1276    }
    12681277
    12691278    $wpp = parse_url(home_url());
Note: See TracChangeset for help on using the changeset viewer.