Make WordPress Core


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

Better validation of the URL used in HTTP redirects.

Merges [36444] to the 4.4 branch.

File:
1 edited

Legend:

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

    r35735 r36447  
    13341334        $test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;
    13351335
    1336         $lp  = parse_url($test);
     1336        // @-operator is used to prevent possible warnings in PHP < 5.3.3.
     1337        $lp = @parse_url($test);
    13371338
    13381339        // Give up if malformed URL
     
    13441345                return $default;
    13451346
    1346         // 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.
    1347         if ( isset($lp['scheme'])  && !isset($lp['host']) )
     1347        // 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.
     1348        if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
    13481349                return $default;
     1350        }
     1351
     1352        // Reject malformed components parse_url() can return on odd inputs
     1353        foreach ( array( 'user', 'pass', 'host' ) as $component ) {
     1354                if ( isset( $lp[ $component ] ) && strpbrk( $lp[ $component ], ':/?#@' ) ) {
     1355                        return $default;
     1356                }
     1357        }
    13491358
    13501359        $wpp = parse_url(home_url());
Note: See TracChangeset for help on using the changeset viewer.