Skip to content

Commit

Permalink
Improve URL validation in wp_validate_redirect().
Browse files Browse the repository at this point in the history
Merges [45971] to the 5.0 branch.
Props vortfu, whyisjake, peterwilsoncc.

git-svn-id: https://develop.svn.wordpress.org/branches/5.0@45974 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information
SergeyBiryukov committed Sep 4, 2019
1 parent 8ff16f0 commit 8d7e1d1
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,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;
Expand Down

0 comments on commit 8d7e1d1

Please sign in to comment.