Make WordPress Core

Changeset 24915


Ignore:
Timestamp:
07/31/2013 06:44:57 AM (11 years ago)
Author:
nacin
Message:

Additional checks when evaluating the safety of an HTTP request, to avoid false negatives.

  • Check if the host is considered a safe redirect host.
  • Check if the host is another domain in a multisite installation.
  • Add a filter to control this.

This only occurs when the DNS resolution of a domain points elsewhere in an internal network, but only internally (and has its own public IP outside the network). This could be considered a bad configuration.

fixes #24646.

Location:
trunk/wp-includes
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/default-filters.php

    r24848 r24915  
    196196add_filter( 'pingback_ping_source_uri', 'pingback_ping_source_uri'            );
    197197add_filter( 'xmlrpc_pingback_error',    'xmlrpc_pingback_error'               );
     198
     199add_filter( 'http_request_host_is_external', 'allowed_http_request_hosts', 10, 2 );
    198200
    199201// Actions
  • trunk/wp-includes/http.php

    r24895 r24915  
    452452        }
    453453        if ( $ip ) {
    454             if ( '127.0.0.1' === $ip )
    455                 return false;
    456454            $parts = array_map( 'intval', explode( '.', $ip ) );
    457             if ( 10 === $parts[0] )
    458                 return false;
    459             if ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
    460                 return false;
    461             if ( 192 === $parts[0] && 168 === $parts[1] )
    462                 return false;
     455            if ( '127.0.0.1' === $ip
     456                || ( 10 === $parts[0] )
     457                || ( 172 === $parts[0] && 16 <= $parts[1] && 31 >= $parts[1] )
     458                || ( 192 === $parts[0] && 168 === $parts[1] )
     459            ) {
     460                // If host appears local, reject unless specifically allowed.
     461                if ( ! apply_filters( 'http_request_host_is_external', false, $host, $url ) )
     462                    return false;
     463            }
    463464        }
    464465    }
     
    476477    return false;
    477478}
     479
     480/**
     481 * Whitelists allowed redirect hosts for safe HTTP requests as well.
     482 *
     483 * Attached to the http_request_host_is_external filter.
     484 *
     485 * @since 3.6.0
     486 *
     487 * @param bool $is_external
     488 * @param string $host
     489 * @return bool
     490 */
     491function allowed_http_request_hosts( $is_external, $host ) {
     492    if ( ! $is_external && wp_validate_redirect( 'http://' . $host ) )
     493        $is_external = true;
     494    return $is_external;
     495}
     496
     497/**
     498 * Whitelists any domain in a multisite installation for safe HTTP requests.
     499 *
     500 * Attached to the http_request_host_is_external filter.
     501 *
     502 * @since 3.6.0
     503 *
     504 * @param bool $is_external
     505 * @param string $host
     506 * @return bool
     507 */
     508function ms_allowed_http_request_hosts( $is_external, $host ) {
     509    global $wpdb, $current_site;
     510    static $queried = array();
     511    if ( $is_external )
     512        return $is_external;
     513    if ( $host === $current_site->domain )
     514        return true;
     515    if ( isset( $queried[ $host ] ) )
     516        return $queried[ $host ];
     517    $queried[ $host ] = (bool) $wpdb->get_var( $wpdb->prepare( "SELECT domain FROM $wpdb->blogs WHERE domain = %s LIMIT 1", $host ) );
     518    return $queried[ $host ];
     519}
  • trunk/wp-includes/ms-default-filters.php

    r21823 r24915  
    6565// If the network upgrade hasn't run yet, assume ms-files.php rewriting is used.
    6666add_filter( 'default_site_option_ms_files_rewriting', '__return_true' );
     67
     68// Whitelist multisite domains for HTTP requests
     69add_filter( 'http_request_host_is_external', 'ms_allowed_http_request_hosts', 20, 2 );
Note: See TracChangeset for help on using the changeset viewer.