Skip to:
Content

BuddyPress.org

Changeset 13069


Ignore:
Timestamp:
08/17/2021 06:37:57 PM (5 years ago)
Author:
imath
Message:

Notifications: limit orderby values in BP_Notifications_Notification

Ensure that passed orderby value matches a verified database column name.

Props dcavins

(trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-notifications/classes/class-bp-notifications-notification.php

    r12753 r13069  
    8585         */
    8686        public $is_new;
     87
     88        /**
     89         * Columns in the notifications table.
     90         *
     91         * @since 9.1.0
     92         * @access public
     93         * @var array
     94         */
     95        public static $columns = array(
     96                'id',
     97                'user_id',
     98                'item_id',
     99                'secondary_item_id',
     100                'component_name',
     101                'component_action',
     102                'date_notified',
     103                'is_new'
     104        );
    87105
    88106        /** Public Methods ********************************************************/
     
    407425                // Order by.
    408426                if ( ! empty( $args['order_by'] ) ) {
    409                         $order_by               = implode( ', ', (array) $args['order_by'] );
    410                         $conditions['order_by'] = "{$order_by}";
     427                        $order_by_clean = array();
     428                        foreach ( (array) $args['order_by'] as $key => $value ) {
     429                                if ( in_array( $value, self::$columns, true ) ) {
     430                                        $order_by_clean[] = $value;
     431                                }
     432                        }
     433                        if ( ! empty( $order_by_clean ) ) {
     434                                $order_by               = implode( ', ', $order_by_clean );
     435                                $conditions['order_by'] = "{$order_by}";
     436                        }
    411437                }
    412438
Note: See TracChangeset for help on using the changeset viewer.