Make WordPress Core


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

Better validation of the URL used in HTTP redirects.

Merges [36444] to the 3.7 branch.

File:
1 edited

Legend:

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

    r30416 r36454  
    977977    $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;
    978978
    979     $lp  = parse_url($test);
     979    // @-operator is used to prevent possible warnings in PHP < 5.3.3.
     980    $lp = @parse_url($test);
    980981
    981982    // Give up if malformed URL
     
    987988        return $default;
    988989
    989     // 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.
    990     if ( isset($lp['scheme'])  && !isset($lp['host']) )
     990    // 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.
     991    if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
    991992        return $default;
     993    }
     994
     995    // Reject malformed components parse_url() can return on odd inputs.
     996    foreach ( array( 'user', 'pass', 'host' ) as $component ) {
     997        if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) {
     998            return $default;
     999        }
     1000    }
    9921001
    9931002    $wpp = parse_url(home_url());
Note: See TracChangeset for help on using the changeset viewer.