Make WordPress Core

Ticket #25840: 25840.3.diff

File 25840.3.diff, 2.3 KB (added by dd32, 11 years ago)
  • src/wp-includes/class-http.php

     
    519519                if ( $check['host'] == 'localhost' || $check['host'] == $home['host'] )
    520520                        return apply_filters('block_local_requests', false);
    521521
    522                 if ( !defined('WP_ACCESSIBLE_HOSTS') )
    523                         return true;
     522                static $wp_accessible_hosts;
     523                if ( null == $wp_accessible_hosts ) {
     524                        if ( defined( 'WP_ACCESSIBLE_HOSTS' ) )
     525                                $wp_accessible_hosts = preg_split( '|,\s*|', WP_ACCESSIBLE_HOSTS );
     526                        else
     527                                $wp_accessible_hosts = array();
     528                }
    524529
    525                 static $accessible_hosts;
    526                 static $wildcard_regex = false;
    527                 if ( null == $accessible_hosts ) {
    528                         $accessible_hosts = preg_split('|,\s*|', WP_ACCESSIBLE_HOSTS);
     530                /**
     531                 * Filter the list of accessible hosts.
     532                 *
     533                 * @since 3.8
     534                 *
     535                 * @param array $wp_accessible_hosts List of accessible hosts.
     536                 * @param string $uri The URL being accessed.
     537                 * @param array $check The pasesed URL being accessed.
     538                 */
     539                $accessible_hosts = apply_filters( 'wp_http_accessible_hosts', $wp_accessible_hosts, $uri, $check );
    529540
    530                         if ( false !== strpos(WP_ACCESSIBLE_HOSTS, '*') ) {
    531                                 $wildcard_regex = array();
    532                                 foreach ( $accessible_hosts as $host )
    533                                         $wildcard_regex[] = str_replace( '\*', '.+', preg_quote( $host, '/' ) );
    534                                 $wildcard_regex = '/^(' . implode('|', $wildcard_regex) . ')$/i';
    535                         }
     541                // Check if there's an exact match
     542                if ( in_array( $accessible_hosts, $check['host'] ) )
     543                        return false; // do not block
     544
     545                // Check to see if there's a wildcard match
     546                foreach ( $accessible_hosts as $host ) {
     547                        // Skip non-wildcard entries
     548                        if ( false === strpos( $host, '*' ) )
     549                                continue;
     550
     551                        $regex = str_replace( '\*', '.+', preg_quote( $host, '!' ) );
     552                        if ( preg_match( '!^(' . $regex . ')$!i', $check['host'] ) )
     553                                return false; // do not block
    536554                }
    537555
    538                 if ( !empty($wildcard_regex) )
    539                         return !preg_match($wildcard_regex, $check['host']);
    540                 else
    541                         return !in_array( $check['host'], $accessible_hosts ); //Inverse logic, If it's in the array, then we can't access it.
    542 
     556                // Otherwise, block the request
     557                return true;
    543558        }
    544559
    545560        static function make_absolute_url( $maybe_relative_path, $url ) {