Skip to:
Content

bbPress.org

Opened 17 years ago

Closed 17 years ago

#1162 closed defect (bug) (fixed)

bb_safe_redirect can end up redirecting to empty uri (blank page)

Reported by: _ck_ Owned by: sambauers
Priority: high Milestone: 0.9.0.6
Component: General - Administration Version: 0.9
Severity: major Keywords:
Cc:

Description

On login/logout bbPress apparently tries to use the browser referer to return the user to where they were. Some improvements were made in bbPress 0.9 to use the site uri incase the referer was not a valid http address.

However there is still a bug. A user with a malformed referer field, done by norton/outpost/etc. will be sent to a blank page.

ie.

Field blocked by Outpost Firewall (http://www.agnitum.com)

Will consistently be sent to a blank page. After login/login.

I believe this is the problem

	if ( isset($lp['host']) && !in_array($lp['host'], $allowed_hosts) )
		$location = bb_get_option('uri');               

$location is only set when both conditions are met. Untested but more robust:

	if ( empty($location) || (isset($lp['host']) && !in_array($lp['host'], $allowed_hosts)) )
		$location = bb_get_option('uri');               

Change History (4)

#1 @_ck_
17 years ago

Maybe even better:

if ( empty($location) || empty($lp['host']) || !in_array($lp['host'], $allowed_hosts) )
		$location = bb_get_option('uri');           


#2 @_ck_
17 years ago

Here is a full version of an improved bb_safe_redirect for bbPress 0.9 I have come up with after studying bbPress 1.0 and WordPress 2.8.2

function bb_safe_redirect($location, $status = 302) {
	// Need to look at the URL the way it will end up in wp_redirect()
	$location = trim(wp_sanitize_redirect($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; }

	// In php 5 parse_url may fail if the URL query part contains http://, bug #38143
	$test = ( $cut = strpos($location, '?') ) ? substr( $location, 0, $cut ) : $location;

	$lp  = parse_url($test);
	$wpp = parse_url(bb_get_option('uri'));

	$allowed_hosts = (array) apply_filters('allowed_redirect_hosts', array($wpp['host']), isset($lp['host']) ? $lp['host'] : '');

	if ( empty($location) || empty($lp['host']) || !in_array($lp['host'], $allowed_hosts) ) { $location = bb_get_option('uri'); }

	wp_redirect($location, $status);
}

#3 @sambauers
17 years ago

  • Milestone0.9.0.6
  • Owner set to sambauers
  • Status newassigned

#4 @sambauers
17 years ago

  • Resolutionfixed
  • Status assignedclosed

(In [2329]) branches 0.9: Better bb_safe_redirect(), fixes #1162, props _ck_

Note: See TracTickets for help on using tickets.