Make WordPress Core

Changeset 40689


Ignore:
Timestamp:
05/16/2017 08:37:34 AM (9 years ago)
Author:
swissspidy
Message:

Improve redirect handling

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-http.php

    r39212 r40689  
    307307        $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) );
    308308
     309        // Validate redirected URLs.
     310        if ( function_exists( 'wp_kses_bad_protocol' ) && $r['reject_unsafe_urls'] ) {
     311            $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) );
     312        }
     313
    309314        if ( $r['stream'] ) {
    310315            $options['filename'] = $r['filename'];
     
    464469        if ( $original->status_code === 302 ) {
    465470            $options['type'] = Requests::GET;
     471        }
     472    }
     473
     474    /**
     475     * Validate redirected URLs.
     476     *
     477     * @since 4.7.5
     478     *
     479     * @throws Requests_Exception On unsuccessful URL validation
     480     * @param string $location URL to redirect to.
     481     */
     482    public static function validate_redirects( $location ) {
     483        if ( ! wp_http_validate_url( $location ) ) {
     484            throw new Requests_Exception( __('A valid URL was not provided.'), 'wp_http.redirect_failed_validation' );
    466485        }
    467486    }
Note: See TracChangeset for help on using the changeset viewer.