Make WordPress Core


Ignore:
Timestamp:
01/22/2013 10:30:08 PM (13 years ago)
Author:
nacin
Message:

Validate pingback source URIs. Less verbose errors.

File:
1 edited

Legend:

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

    r23325 r23329  
    19541954}
    19551955
     1956/**
     1957 * Default filter attached to pingback_ping_source_uri to validate the pingback's Source URI
     1958 *
     1959 * @since 3.5.1
     1960 *
     1961 * @param string $source_uri
     1962 * @return string
     1963 */
     1964function pingback_ping_source_uri( $source_uri ) {
     1965    $uri = esc_url_raw( $source_uri, array( 'http', 'https' ) );
     1966    if ( ! $uri )
     1967        return '';
     1968
     1969    $parsed_url = @parse_url( $uri );
     1970    if ( ! $parsed_url )
     1971        return '';
     1972
     1973    if ( isset( $parsed_url['user'] ) || isset( $parsed_url['pass'] ) )
     1974        return '';
     1975
     1976    if ( false !== strpos( $parsed_url['host'], ':' ) )
     1977        return '';
     1978
     1979    $parsed_home = @parse_url( get_option( 'home' ) );
     1980
     1981    $same_host = strtolower( $parsed_home['host'] ) === strtolower( $parsed_url['host'] );
     1982
     1983    if ( ! $same_host ) {
     1984        $host = trim( $parsed_url['host'], '.' );
     1985        if ( preg_match( '#^\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}$#', $host ) ) {
     1986            $ip = $host;
     1987        } else {
     1988            $ip = gethostbyname( $host );
     1989            if ( $ip === $host ) // Error condition for gethostbyname()
     1990                $ip = false;
     1991        }
     1992        if ( $ip ) {
     1993            if ( '127.0.0.1' === $ip )
     1994                return '';
     1995            $parts = array_map( 'intval', explode( '.', $ip ) );
     1996            if ( 10 === $parts[0] )
     1997                return '';
     1998            if ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
     1999                return '';
     2000            if ( 192 === $parts[0] && 168 === $parts[1] )
     2001                return '';
     2002        }
     2003    }
     2004
     2005    if ( empty( $parsed_url['port'] ) )
     2006        return $uri;
     2007
     2008    $port = $parsed_url['port'];
     2009    if ( 80 === $port || 443 === $port || 8080 === $port )
     2010        return $uri;
     2011
     2012    if ( $parsed_home && $same_host && $parsed_home['port'] === $port )
     2013        return $uri;
     2014
     2015    return '';
     2016}
     2017
     2018/**
     2019 * Default filter attached to xmlrpc_pingback_error.
     2020 *
     2021 * Returns a generic pingback error code unless the error code is 48,
     2022 * which reports that the pingback is already registered.
     2023 *
     2024 * @since 3.5.1
     2025 * @link http://www.hixie.ch/specs/pingback/pingback#TOC3
     2026 *
     2027 * @param IXR_Error $ixr_error
     2028 * @return IXR_Error
     2029 */
     2030function xmlrpc_pingback_error( $ixr_error ) {
     2031    if ( $ixr_error->code === 48 )
     2032        return $ixr_error;
     2033    return new IXR_Error( 0, '' );
     2034}
     2035
    19562036//
    19572037// Cache
Note: See TracChangeset for help on using the changeset viewer.