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)
#2
@
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);
}
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
Maybe even better:
if ( empty($location) || empty($lp['host']) || !in_array($lp['host'], $allowed_hosts) ) $location = bb_get_option('uri');