Skip to:
Content

BuddyPress.org

Changeset 9559


Ignore:
Timestamp:
02/25/2015 02:56:18 PM (10 years ago)
Author:
boonebgorges
Message:

Improve AJAX referer determination during URI parsing.

When parsing referer URLs during bp_core_set_uri_globals(), BP has
historically used bp_core_referrer() to generate a "current URL" relative to
the current web root. This path is then passed to the 'bp_uri' filter before
being parsed. However, bp_core_referrer() incorrectly returns a URL without
a leading slash, making it a relative path rather than a webroot-absolute path.
The parsing logic later in bp_core_set_uri_globals() makes it so that the
error does not matter from the point of BP core, but plugins filtering 'bp_uri'
will receive a potentially incorrect URL path.

This changeset deprecates the unreliable bp_core_referrer() in favor of
bp_get_referer_path(). The latter function correctly returns URL paths with a
leading slash. bp_get_referer_path() is then used instead of
bp_core_referrer() in bp_core_set_uri_globals().

Props mechter for an initial patch.
Fixes #6252.

Location:
trunk
Files:
3 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/bp-core-catchuri.php

    r9517 r9559  
    5252    // Ajax or not?
    5353    if ( defined( 'DOING_AJAX' ) && DOING_AJAX || strpos( $_SERVER['REQUEST_URI'], 'wp-load.php' ) )
    54         $path = bp_core_referrer();
     54        $path = bp_get_referer_path();
    5555    else
    5656        $path = esc_url( $_SERVER['REQUEST_URI'] );
  • trunk/src/bp-core/bp-core-functions.php

    r9507 r9559  
    836836
    837837/**
    838  * Return the referrer URL without the http(s)://
    839  *
    840  * @return string The referrer URL.
    841  */
    842 function bp_core_referrer() {
    843     $referer = explode( '/', wp_get_referer() );
    844     unset( $referer[0], $referer[1], $referer[2] );
    845     return implode( '/', $referer );
     838 * Return the URL path of the referring page.
     839 *
     840 * This is a wrapper for `wp_get_referer()` that sanitizes the referer URL to
     841 * a webroot-relative path. For example, 'http://example.com/foo/' will be
     842 * reduced to '/foo/'.
     843 *
     844 * @since BuddyPress (2.3.0)
     845 *
     846 * @return bool|string Returns false on error, a URL path on success.
     847 */
     848function bp_get_referer_path() {
     849    $referer = wp_get_referer();
     850
     851    if ( false === $referer ) {
     852        return false;
     853    }
     854
     855    // Turn into an absolute path.
     856    $referer = preg_replace( '|https?\://[^/]+/|', '/', $referer );
     857
     858    return $referer;
    846859}
    847860
  • trunk/src/bp-loader.php

    r9557 r9559  
    462462            require( $this->plugin_dir . 'bp-core/deprecated/2.1.php' );
    463463            require( $this->plugin_dir . 'bp-core/deprecated/2.2.php' );
     464            require( $this->plugin_dir . 'bp-core/deprecated/2.3.php' );
    464465        }
    465466    }
Note: See TracChangeset for help on using the changeset viewer.