Skip to:
Content

BuddyPress.org

Opened 13 years ago

Closed 13 years ago

#3280 closed defect (bug) (fixed)

Invalid URLs are incorrectly handled

Reported by: djpaul's profile DJPaul Owned by:
Milestone: 1.5 Priority: blocker
Severity: Version:
Component: Core Keywords:
Cc:

Description

Alot of BuddyPress URLs are not handling invalid URLs correctly. Make sure you have wp_debug set.
These must 404, not redirect back to the home page or a component's root page:

1) http://example.com/groups/INVALID/ (and all subdirs, i.e. /forum/, /members/, and so on).

2) http://example.com/groups/valid/INVALID/
3) http://example.com/groups/valid/forum/INVALID

4) http://example.com/members/INVALID/
5) http://example.com/members/valid/INVALID/

If a valid component is on the URL, I think that component should be responsible for handling 404s within that component, rather than letting it fall back to BP_Core, e.g.

$wp_query->set_404();
status_header( 404 );
nocache_headers();

Attachments (6)

3280-1.patch (6.0 KB) - added by DJPaul 13 years ago.
3280-2.patch (12.7 KB) - added by boonebgorges 13 years ago.
3280-3.patch (11.5 KB) - added by DJPaul 13 years ago.
3280-4.patch (13.0 KB) - added by boonebgorges 13 years ago.
3280-5.patch (20.6 KB) - added by DJPaul 13 years ago.
3280-6.patch (23.9 KB) - added by DJPaul 13 years ago.

Download all attachments as: .zip

Change History (21)

#1 @DJPaul
13 years ago

Related: #3211

Last edited 13 years ago by DJPaul (previous) (diff)

#2 @boonebgorges
13 years ago

I agree that this should be fixed, but is it really a blocker? It's not a regression; BP already works like this (for better or for worse).

In any case, it should mean just changing a few 'return false' calls to the status_header(404); sequence, right?

@DJPaul
13 years ago

#3 @DJPaul
13 years ago

Fairly rough first patch attached. There may be some more situations in the messages component to 404 for, but I was unsure.

Had to hack up bp_core_catch_no_access(). As a result, the "If the displayed user was marked as a spammer and the logged-in user is not a super admin" thing doesn't work.

For the email notifications, I suggest we go through and edit all of those to point to wp-login.php with a redirect_to argument.

#4 @johnjamesjacoby
13 years ago

Patch applied over at testbp.org. Still doesn't seem to fix the http://testbp.org/members/sdafsadfsdf/profile issue though.

#5 @DJPaul
13 years ago

Thanks. There's definitely more to do. I'll check it out after work.

#6 @boonebgorges
13 years ago

Thanks for starting this, DJPaul. 3280-2.patch is an expanded version with a few enhancements:

  • Distinguish between groups that don't exist and groups that one does not have access to. If you attempt to visit a non-existent group, or any subpage of a non-existent group, you get a 404. If you attempt to visit the inner page of a group to which you do not have access, you get bp_core_no_access(), ie a redirect to the login page with a redirect_to param. This will take care of the email notification issue without resorting to putting the hideous wp-login.php url in emails :)
  • http://example.com/members/INVALID/profile now 404s. I did this by putting a check directly into bp_core_set_uri_globals(), where BP attempts to find a displayed_user. This was tricky for components that also have root component pages, like http://example.com/members/INVALID/groups, because WP's canonical URL functions tried to "help" our 404 situation by redirecting back to the similarly-named WP page with the name 'Groups'. That's why you'll see

remove_action( 'template_redirect', 'redirect_canonical' );

in a few places.

#7 @boonebgorges
13 years ago

I was thinking about this, and I think it might be nice to make a wrapper function bp_handle_404() or something like that, since unsetting the current_component and unhooking 'redirect_canonical' will generally be necessary in the case of BP 404s. This'll also make it easier for plugin authors to do proper 404ing.

@DJPaul
13 years ago

#8 @DJPaul
13 years ago

Patch updated to remove unused global per IRC. /groups/valid/forum/INVALID/ is still incorrectly handled.

#9 @DJPaul
13 years ago

As is /groups/valid/send-invites/INVALID/

#10 @DJPaul
13 years ago

As much as I really, really hate it, unless we want to whitelist URLs for everything, I think we're going to have to put up with URLs like /groups/valid/send-invites/ANYTHING/GOES/HERE/.

Last edited 13 years ago by DJPaul (previous) (diff)

#11 @boonebgorges
13 years ago

As much as I really, really hate it, unless we want to whitelist URLs for everything, I think we're going to have to put up with URLs like /groups/valid/send-invites/ANYTHING/GOES/HERE/.

I don't think that's true. We can just change the logic in groups_screen_group_invite() a bit. Working on a patch.

It's true that this is a huge PITA to fix, but it's good to do now, so we can set some best practices for future dev.

#12 @boonebgorges
13 years ago

See 3280-4.patch

@DJPaul
13 years ago

#13 @DJPaul
13 years ago

Nice one; 3280-5.patch attached with convenience function to set the 404. Also includes a bunch of whitespace cleanup.

@DJPaul
13 years ago

#14 @DJPaul
13 years ago

3280-6.patch handles some more situations along the lines of /groups/valid/send-invites/ANYTHING/GOES/HERE/. Probably not complete, and needs checking.

#15 @boonebgorges
13 years ago

  • Resolution set to fixed
  • Status changed from new to closed

(In [4506]) Introduces bp_do_404() for easy 404ing. Corrects invalid path handling throughout, using bp_do_404(). Fixes #3280. Props DJPaul

Note: See TracTickets for help on using tickets.