Skip to:
Content

BuddyPress.org


Ignore:
Timestamp:
08/18/2021 12:28:22 AM (4 years ago)
Author:
imath
Message:

Limit orderby values in BP_Invitation.

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

Props dcavins

(trunk)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-core/classes/class-bp-invitation.php

    r12916 r13082  
    131131     */
    132132    public $accepted;
     133
     134    /**
     135     * Columns in the invitations table.
     136     *
     137     * @since 9.0.0
     138     * @access public
     139     * @var array
     140     */
     141    public static $columns = array(
     142        'id',
     143        'user_id',
     144        'inviter_id',
     145        'invitee_email',
     146        'class',
     147        'item_id',
     148        'secondary_item_id',
     149        'type',
     150        'content',
     151        'date_modified',
     152        'invite_sent',
     153        'accepted'
     154    );
    133155
    134156    /** Public Methods ****************************************************/
     
    474496        // Order by.
    475497        if ( ! empty( $args['order_by'] ) ) {
    476             $order_by               = implode( ', ', (array) $args['order_by'] );
    477             $conditions['order_by'] = "{$order_by}";
     498            $order_by_clean = array();
     499            foreach ( (array) $args['order_by'] as $key => $value ) {
     500                if ( in_array( $value, self::$columns, true ) ) {
     501                    $order_by_clean[] = $value;
     502                }
     503            }
     504            if ( ! empty( $order_by_clean ) ) {
     505                $order_by               = implode( ', ', $order_by_clean );
     506                $conditions['order_by'] = "{$order_by}";
     507            }
    478508        }
    479509
Note: See TracChangeset for help on using the changeset viewer.