Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
09/07/2017 11:00:09 PM (9 years ago)
Author:
johnjamesjacoby
Message:

Messages: add a nonce check to site-wide notice actions.

Props jdgrimes. Trunk, for 3.0.

File:
1 edited

Legend:

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

    r11578 r11688  
    132132 * @since 2.4.0 This function was split from messages_screen_notices(). See #6505.
    133133 *
    134  * @global int $notice_id
    135  *
    136134 * @return boolean
    137135 */
    138136function bp_messages_action_edit_notice() {
    139         global $notice_id;
    140137
    141138        // Bail if not viewing a single notice URL.
    142         if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) || ! bp_action_variable( 1 ) ) {
    143                 return false;
    144         }
    145 
    146         // Get action variables.
    147         $action    = bp_action_variable( 0 ); // deactivate|activate|delete.
    148         $notice_id = bp_action_variable( 1 ); // 1|2|3|etc...
     139        if ( ! bp_is_messages_component() || ! bp_is_current_action( 'notices' ) ) {
     140                return false;
     141        }
     142
     143        // Get the notice ID (1|2|3).
     144        $notice_id = bp_action_variable( 1 );
    149145
    150146        // Bail if notice ID is not numeric.
    151         if ( ! is_numeric( $notice_id ) ) {
    152                 return;
    153         }
    154 
    155         // Define local variables.
    156         $redirect_to = '';
    157         $feedback    = '';
    158         $success     = false;
     147        if ( empty( $notice_id ) || ! is_numeric( $notice_id ) ) {
     148                return false;
     149        }
     150
     151        // Bail if the current user doesn't have administrator privileges.
     152        if ( ! bp_current_user_can( 'bp_moderate' ) ) {
     153                return false;
     154        }
     155
     156        // Get the action (deactivate|activate|delete).
     157        $action = sanitize_key( bp_action_variable( 0 ) );
     158
     159        // Check the nonce.
     160        check_admin_referer( "messages_{$action}_notice" );
    159161
    160162        // Get the notice from database.
    161         $notice = new BP_Messages_Notice( $notice_id );
     163        $notice   = new BP_Messages_Notice( $notice_id );
     164        $success  = false;
     165        $feedback = '';
    162166
    163167        // Take action.
Note: See TracChangeset for help on using the changeset viewer.