Skip to content
Permalink
Browse files Browse the repository at this point in the history
Improve redirect handling
Built from https://develop.svn.wordpress.org/trunk@40689


git-svn-id: http://core.svn.wordpress.org/trunk@40552 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
swissspidy committed May 16, 2017
1 parent e88a48a commit 76d77e9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
19 changes: 19 additions & 0 deletions wp-includes/class-http.php
Expand Up @@ -306,6 +306,11 @@ public function request( $url, $args = array() ) {
// Ensure redirects follow browser behaviour.
$options['hooks']->register( 'requests.before_redirect', array( get_class(), 'browser_redirect_compatibility' ) );

// Validate redirected URLs.
if ( function_exists( 'wp_kses_bad_protocol' ) && $r['reject_unsafe_urls'] ) {
$options['hooks']->register( 'requests.before_redirect', array( get_class(), 'validate_redirects' ) );
}

if ( $r['stream'] ) {
$options['filename'] = $r['filename'];
}
Expand Down Expand Up @@ -466,6 +471,20 @@ public static function browser_redirect_compatibility( $location, $headers, $dat
}
}

/**
* Validate redirected URLs.
*
* @since 4.7.5
*
* @throws Requests_Exception On unsuccessful URL validation
* @param string $location URL to redirect to.
*/
public static function validate_redirects( $location ) {
if ( ! wp_http_validate_url( $location ) ) {
throw new Requests_Exception( __('A valid URL was not provided.'), 'wp_http.redirect_failed_validation' );
}
}

/**
* Tests which transports are capable of supporting the request.
*
Expand Down
2 changes: 1 addition & 1 deletion wp-includes/version.php
Expand Up @@ -4,7 +4,7 @@
*
* @global string $wp_version
*/
$wp_version = '4.8-beta1-40677';
$wp_version = '4.8-beta1-40689';

/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
Expand Down

0 comments on commit 76d77e9

Please sign in to comment.