Skip to content

Commit 76d77e9

Browse files
committed
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
1 parent e88a48a commit 76d77e9

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

Diff for: wp-includes/class-http.php

+19
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,11 @@ public function request( $url, $args = array() ) {
306306
// Ensure redirects follow browser behaviour.
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'];
311316
}
@@ -466,6 +471,20 @@ public static function browser_redirect_compatibility( $location, $headers, $dat
466471
}
467472
}
468473

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' );
485+
}
486+
}
487+
469488
/**
470489
* Tests which transports are capable of supporting the request.
471490
*

Diff for: wp-includes/version.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
*
55
* @global string $wp_version
66
*/
7-
$wp_version = '4.8-beta1-40677';
7+
$wp_version = '4.8-beta1-40689';
88

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

0 commit comments

Comments
 (0)