Skip to content
Permalink
Browse files

Improve URL validation in `wp_validate_redirect()`.

Merges [45971] to the 5.2 branch.
Props vortfu, whyisjake, peterwilsoncc.

git-svn-id: https://develop.svn.wordpress.org/branches/5.2@45972 602fd350-edb4-49c9-b593-d223f7449a82
  • Loading branch information...
SergeyBiryukov committed Sep 4, 2019
1 parent f5500f4 commit aec4f5713be368248aa51ba655bb82da68744f4f
Showing with 8 additions and 0 deletions.
  1. +8 −0 src/wp-includes/pluggable.php
@@ -1396,6 +1396,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;

0 comments on commit aec4f57

Please sign in to comment.
You can’t perform that action at this time.