Make WordPress Core

Changeset 40691


Ignore:
Timestamp:
05/16/2017 08:40:15 AM (8 years ago)
Author:
swissspidy
Message:

Improve redirect handling

Merges[40689] to the 4.7 branch.

Location:
branches/4.6
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/4.6

  • branches/4.6/src/wp-includes/class-http.php

    r38895 r40691  
    311311        $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) );
    312312
     313        // Validate redirected URLs.
     314        if ( function_exists( 'wp_kses_bad_protocol' ) && $r['reject_unsafe_urls'] ) {
     315            $options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) );
     316        }
     317
    313318        if ( $r['stream'] ) {
    314319            $options['filename'] = $r['filename'];
     
    468473        if ( $original->status_code === 302 ) {
    469474            $options['type'] = Requests::GET;
     475        }
     476    }
     477
     478    /**
     479     * Validate redirected URLs.
     480     *
     481     * @throws Requests_Exception On unsuccessful URL validation
     482     * @param string $location URL to redirect to.
     483     */
     484    public static function validate_redirects( $location ) {
     485        if ( ! wp_http_validate_url( $location ) ) {
     486            throw new Requests_Exception( __('A valid URL was not provided.'), 'wp_http.redirect_failed_validation' );
    470487        }
    471488    }
Note: See TracChangeset for help on using the changeset viewer.