Skip to:
Content

BuddyPress.org

Changeset 10385


Ignore:
Timestamp:
12/02/2015 07:49:54 PM (10 years ago)
Author:
djpaul
Message:

Improve input handling on a variety of admin screens.

An internal audit revealed some screens which react to form submission where we were not sanitising input as well as we could have been. We've added extra typecasting and existence checks to avoid mishandling causing PHP Notices.

Additionally, we moved a list of hardcoded BuddyPress "pages" (registration and account activation) into a filterable function to allow plugin developers to more easily customise or add to these, which also gives us the benefit of being able to use that function as a sanitisation whitelist, without duplicating that hardcoded list.

Props boonebgorges, DJPaul

Location:
branches/2.4/src
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • branches/2.4/src/bp-core/admin/bp-core-admin-slugs.php

    r10229 r10385  
    4040
    4141/**
    42  * Creates reusable markup for page setup on the Components and Pages dashboard panel.
    43  *
    44  * @package BuddyPress
    45  * @since 1.6.0
    46  * @todo Use settings API
    47  */
    48 function bp_core_admin_slugs_options() {
     42 * Generate a list of directory pages, for use when building Components panel markup.
     43 *
     44 * @since 2.4.1
     45 *
     46 * @return array
     47 */
     48function bp_core_admin_get_directory_pages() {
    4949    $bp = buddypress();
    50 
    51     // Get the existing WP pages
    52     $existing_pages = bp_core_get_directory_page_ids();
    53 
    54     // Set up an array of components (along with component names) that have
    55     // directory pages.
    5650    $directory_pages = array();
    5751
     
    6963    }
    7064
    71     /** Directory Display *****************************************************/
    72 
    7365    /**
    7466     * Filters the loaded components needing directory page association to a WordPress page.
     
    7870     * @param array $directory_pages Array of available components to set associations for.
    7971     */
    80     $directory_pages = apply_filters( 'bp_directory_pages', $directory_pages );
     72    return apply_filters( 'bp_directory_pages', $directory_pages );
     73}
     74
     75/**
     76 * Generate a list of static pages, for use when building Components panel markup.
     77 *
     78 * By default, this list contains 'register' and 'activate'.
     79 *
     80 * @since 2.4.1
     81 *
     82 * @return array
     83 */
     84function bp_core_admin_get_static_pages() {
     85    $static_pages = array(
     86        'register' => __( 'Register', 'buddypress' ),
     87        'activate' => __( 'Activate', 'buddypress' ),
     88    );
     89
     90    /**
     91     * Filters the default static pages for BuddyPress setup.
     92     *
     93     * @since 1.6.0
     94     *
     95     * @param array $static_pages Array of static default static pages.
     96     */
     97    return apply_filters( 'bp_static_pages', $static_pages );
     98}
     99
     100/**
     101 * Creates reusable markup for page setup on the Components and Pages dashboard panel.
     102 *
     103 * @package BuddyPress
     104 * @since 1.6.0
     105 * @todo Use settings API
     106 */
     107function bp_core_admin_slugs_options() {
     108    $bp = buddypress();
     109
     110    // Get the existing WP pages
     111    $existing_pages = bp_core_get_directory_page_ids();
     112
     113    // Set up an array of components (along with component names) that have directory pages.
     114    $directory_pages = bp_core_admin_get_directory_pages();
     115
     116    /** Directory Display *****************************************************/
    81117
    82118    if ( !empty( $directory_pages ) ) : ?>
     
    141177    /** Static Display ********************************************************/
    142178
    143     // Static pages
    144     $static_pages = array(
    145         'register' => __( 'Register', 'buddypress' ),
    146         'activate' => __( 'Activate', 'buddypress' ),
    147     );
    148 
    149     /**
    150      * Filters the default static pages for BuddyPress setup.
    151      *
    152      * @since 1.6.0
    153      *
    154      * @param array $static_pages Array of static default static pages.
    155      */
    156     $static_pages = apply_filters( 'bp_static_pages', $static_pages );
     179    $static_pages = bp_core_admin_get_static_pages();
    157180
    158181    if ( !empty( $static_pages ) ) : ?>
     
    226249        // Then, update the directory pages
    227250        if ( isset( $_POST['bp_pages'] ) ) {
    228 
    229             $directory_pages = array();
    230 
     251            $valid_pages = array_merge( bp_core_admin_get_directory_pages(), bp_core_admin_get_static_pages() );
     252
     253            $new_directory_pages = array();
    231254            foreach ( (array) $_POST['bp_pages'] as $key => $value ) {
    232                 if ( !empty( $value ) ) {
    233                     $directory_pages[$key] = (int) $value;
     255                if ( isset( $valid_pages[ $key ] ) ) {
     256                    $new_directory_pages[ $key ] = (int) $value;
    234257                }
    235258            }
    236             bp_core_update_directory_page_ids( $directory_pages );
     259            bp_core_update_directory_page_ids( $new_directory_pages );
    237260        }
    238261
  • branches/2.4/src/bp-groups/bp-groups-actions.php

    r10276 r10385  
    210210                foreach ( (array) $_POST['friends'] as $friend ) {
    211211                    groups_invite_user( array(
    212                         'user_id'  => $friend,
     212                        'user_id'  => (int) $friend,
    213213                        'group_id' => $bp->groups->new_group_id,
    214214                    ) );
  • branches/2.4/src/bp-groups/bp-groups-admin.php

    r10262 r10385  
    313313                // Process only those users who have had their roles changed
    314314                foreach ( (array) $_POST['bp-groups-role'] as $user_id => $new_role ) {
     315                    $user_id = (int) $user_id;
    315316
    316317                    $existing_role = isset( $_POST['bp-groups-existing-role'][$user_id] ) ? $_POST['bp-groups-existing-role'][$user_id] : '';
    317318
    318319                    if ( $existing_role != $new_role ) {
     320                        $result = false;
    319321
    320322                        switch ( $new_role ) {
Note: See TracChangeset for help on using the changeset viewer.