From f08a1c1302ff55eb159e1147b804d7bfc4e900f4 Mon Sep 17 00:00:00 2001 From: Sergey Biryukov Date: Wed, 4 Sep 2019 17:12:24 +0000 Subject: [PATCH] Improve URL validation in `wp_validate_redirect()`. Merges [45971] to the 4.6 branch. Props vortfu, whyisjake, peterwilsoncc. Built from https://develop.svn.wordpress.org/branches/4.6@45978 git-svn-id: http://core.svn.wordpress.org/branches/4.6@45789 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/pluggable.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/wp-includes/pluggable.php b/wp-includes/pluggable.php index aa113c0dd2..3c3d2232ad 100644 --- a/wp-includes/pluggable.php +++ b/wp-includes/pluggable.php @@ -1297,6 +1297,14 @@ function wp_validate_redirect($location, $default = '') { if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) ) return $default; + if ( ! isset( $lp['host'] ) && ! empty( $lp['path'] ) && '/' !== $lp['path'][0] ) { + $path = ''; + if ( ! empty( $_SERVER['REQUEST_URI'] ) ) { + $path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' ); + } + $location = '/' . ltrim( $path . '/', '/' ) . $location; + } + // Reject if certain components are set but host is not. This catches urls like https:host.com for which parse_url does not set the host field. if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) { return $default;