Skip to content
Permalink
Browse files Browse the repository at this point in the history
Improve URL validation in wp_validate_redirect().
Props vortfu, whyisjake, peterwilsoncc.
Built from https://develop.svn.wordpress.org/trunk@45971


git-svn-id: http://core.svn.wordpress.org/trunk@45782 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
SergeyBiryukov committed Sep 4, 2019
1 parent 187d747 commit c86ee39
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions wp-includes/pluggable.php
Expand Up @@ -1407,6 +1407,14 @@ function wp_validate_redirect( $location, $default = '' ) {
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
2 changes: 1 addition & 1 deletion wp-includes/version.php
Expand Up @@ -13,7 +13,7 @@
*
* @global string $wp_version
*/
$wp_version = '5.3-alpha-45964';
$wp_version = '5.3-alpha-45971';

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

1 comment on commit c86ee39

@roiconde
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.