Skip to content

Commit

Permalink
Validate referrers to prevent off-domain redirects.
Browse files Browse the repository at this point in the history
Built from https://develop.svn.wordpress.org/trunk@25318


git-svn-id: http://core.svn.wordpress.org/trunk@25280 1a063a9b-81f0-0310-95a4-ce76da25c4cd
  • Loading branch information
nacin committed Sep 10, 2013
1 parent c8a7b53 commit cf3fddd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
4 changes: 2 additions & 2 deletions wp-includes/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -1296,7 +1296,7 @@ function wp_get_referer() {
$ref = wp_unslash( $_SERVER['HTTP_REFERER'] );

if ( $ref && $ref !== wp_unslash( $_SERVER['REQUEST_URI'] ) )
return wp_unslash( $ref );
return wp_validate_redirect( $ref, false );
return false;
}

Expand All @@ -1311,7 +1311,7 @@ function wp_get_referer() {
*/
function wp_get_original_referer() {
if ( !empty( $_REQUEST['_wp_original_http_referer'] ) )
return wp_unslash( $_REQUEST['_wp_original_http_referer'] );
return wp_validate_redirect( wp_unslash( $_REQUEST['_wp_original_http_referer'] ), false );
return false;
}

Expand Down
1 change: 1 addition & 0 deletions wp-includes/pluggable.php
Original file line number Diff line number Diff line change
Expand Up @@ -964,6 +964,7 @@ function wp_safe_redirect($location, $status = 302) {
* @return string redirect-sanitized URL
**/
function wp_validate_redirect($location, $default = '') {
$location = trim( $location );
// browsers will assume 'http' is your protocol, and will obey a redirect to a URL starting with '//'
if ( substr($location, 0, 2) == '//' )
$location = 'http:' . $location;
Expand Down

0 comments on commit cf3fddd

Please sign in to comment.