Make WordPress Core


Ignore:
Timestamp:
06/21/2013 06:07:47 AM (13 years ago)
Author:
nacin
Message:

Better validation of the URL used in core HTTP requests.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/comment.php

    r24301 r24480  
    16591659                return false;
    16601660
    1661         $response = wp_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) );
     1661        $response = wp_remote_head( $url, array( 'timeout' => 2, 'httpversion' => '1.0', 'reject_unsafe_urls' => true ) );
    16621662
    16631663        if ( is_wp_error( $response ) )
    … …  
    16721672
    16731673        // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    1674         $response = wp_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0' ) );
     1674        $response = wp_remote_get( $url, array( 'timeout' => 2, 'httpversion' => '1.0', 'reject_unsafe_urls' => true ) );
    16751675
    16761676        if ( is_wp_error( $response ) )
    … …  
    19071907        $options = array();
    19081908        $options['timeout'] = 4;
     1909        $options['reject_unsafe_urls'] = true;
    19091910        $options['body'] = array(
    19101911                'title' => $title,
    … …  
    19541955 *
    19551956 * @since 3.5.1
     1957 * @see wp_http_validate_url()
    19561958 *
    19571959 * @param string $source_uri
    … …  
    19591961 */
    19601962function pingback_ping_source_uri( $source_uri ) {
    1961         $uri = esc_url_raw( $source_uri, array( 'http', 'https' ) );
    1962         if ( ! $uri )
    1963                 return '';
    1964 
    1965         $parsed_url = @parse_url( $uri );
    1966         if ( ! $parsed_url )
    1967                 return '';
    1968 
    1969         if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) )
    1970                 return '';
    1971 
    1972         if ( false !== strpos( $parsed_url['host'], ':' ) )
    1973                 return '';
    1974 
    1975         $parsed_home = @parse_url( get_option( 'home' ) );
    1976 
    1977         $same_host = strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] );
    1978 
    1979         if ( ! $same_host ) {
    1980                 $host = trim( $parsed_url['host'], '.' );
    1981                 if ( preg_match( '#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host ) ) {
    1982                         $ip = $host;
    1983                 } else {
    1984                         $ip = gethostbyname( $host );
    1985                         if ( $ip === $host ) // Error condition for gethostbyname()
    1986                                 $ip = false;
    1987                 }
    1988                 if ( $ip ) {
    1989                         if ( '127.0.0.1' === $ip )
    1990                                 return '';
    1991                         $parts = array_map( 'intval', explode( '.', $ip ) );
    1992                         if ( 10 === $parts[0] )
    1993                                 return '';
    1994                         if ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
    1995                                 return '';
    1996                         if ( 192 === $parts[0] && 168 === $parts[1] )
    1997                                 return '';
    1998                 }
    1999         }
    2000 
    2001         if ( empty( $parsed_url['port'] ) )
    2002                 return $uri;
    2003 
    2004         $port = $parsed_url['port'];
    2005         if ( 80 === $port || 443 === $port || 8080 === $port )
    2006                 return $uri;
    2007 
    2008         if ( $parsed_home && $same_host && $parsed_home['port'] === $port )
    2009                 return $uri;
    2010 
    2011         return '';
     1963        return (string) wp_http_validate_url( $source_uri );
    20121964}
    20131965
Note: See TracChangeset for help on using the changeset viewer.