From 81a5ef373a7061ea32d684aacdae53d8e5840580 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Tue, 16 May 2017 08:41:33 +0000 Subject: [PATCH] Improve redirect handling Merges[40689] to the 4.7 branch. Built from https://develop.svn.wordpress.org/branches/4.6@40691 git-svn-id: http://core.svn.wordpress.org/branches/4.6@40554 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/class-http.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/wp-includes/class-http.php b/wp-includes/class-http.php index 5a3075846c..979957571c 100644 --- a/wp-includes/class-http.php +++ b/wp-includes/class-http.php @@ -310,6 +310,11 @@ class WP_Http { // 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']; } @@ -470,6 +475,18 @@ class WP_Http { } } + /** + * Validate redirected URLs. + * + * @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. *