Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
06/16/2015 10:48:11 PM (10 years ago)
Author:
johnjamesjacoby
Message:

Messages: Introduce filter to enforce private message thread query boundaries.

This change ensures that all queries for private messages will always return anticipated results, even when certain malformed values are passed in. It specifically hardens the user ID argument to prevent accidental overriding.

Fixes #6504. Props r-a-y. (trunk, for 2.4.0)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-messages/bp-messages-filters.php

    r9862 r9948  
    6666add_filter( 'bp_get_the_thread_message_content', 'stripslashes_deep' );
    6767add_filter( 'bp_get_the_thread_subject',         'stripslashes_deep' );
     68
     69/**
     70 * Enforce limitations on viewing private message contents
     71 *
     72 * @since BuddyPress (2.3.2)
     73 *
     74 * @see bp_has_message_threads() for description of parameters
     75 *
     76 * @param array|string $args See {@link bp_has_message_threads()}.
     77 */
     78function bp_messages_enforce_current_user( $args = array() ) {
     79
     80    // Non-community moderators can only ever see their own messages
     81    if ( is_user_logged_in() && ! bp_current_user_can( 'bp_moderate' ) ) {
     82        $_user_id = (int) bp_loggedin_user_id();
     83        if ( $_user_id !== (int) $args['user_id'] ) {
     84            $args['user_id'] = $_user_id;
     85        }
     86    }
     87
     88    // Return possibly modified $args array
     89    return $args;
     90}
     91add_filter( 'bp_after_has_message_threads_parse_args', 'bp_messages_enforce_current_user', 5 );
Note: See TracChangeset for help on using the changeset viewer.