Skip to content

Commit c72f365

Browse files
Improve URL validation in wp_validate_redirect().
Merges [45971] to the 4.8 branch. Props vortfu, whyisjake, peterwilsoncc. git-svn-id: https://develop.svn.wordpress.org/branches/4.8@45976 602fd350-edb4-49c9-b593-d223f7449a82
1 parent fb1553e commit c72f365

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

src/wp-includes/pluggable.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1333,6 +1333,14 @@ function wp_validate_redirect($location, $default = '') {
13331333
if ( isset($lp['scheme']) && !('http' == $lp['scheme'] || 'https' == $lp['scheme']) )
13341334
return $default;
13351335

1336+
if ( ! isset( $lp['host'] ) && ! empty( $lp['path'] ) && '/' !== $lp['path'][0] ) {
1337+
$path = '';
1338+
if ( ! empty( $_SERVER['REQUEST_URI'] ) ) {
1339+
$path = dirname( parse_url( 'http://placeholder' . $_SERVER['REQUEST_URI'], PHP_URL_PATH ) . '?' );
1340+
}
1341+
$location = '/' . ltrim( $path . '/', '/' ) . $location;
1342+
}
1343+
13361344
// 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.
13371345
if ( ! isset( $lp['host'] ) && ( isset( $lp['scheme'] ) || isset( $lp['user'] ) || isset( $lp['pass'] ) || isset( $lp['port'] ) ) ) {
13381346
return $default;

0 commit comments

Comments
 (0)