Make WordPress Core


Ignore:
Timestamp:
09/30/2014 02:03:49 PM (12 years ago)
Author:
boonebgorges
Message:

Improve parameter sanitization in WP_Date_Query::build_query().

  • Don't run non-numeric values through intval() for sanitization; this transforms them into 1s and 0s, which can cause unintended results.
  • Be more generous about numeric array keys (don't require 0 and 1) in BETWEEN and NOT BETWEEN clauses.

Fixes #29801.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/date.php

    r29479 r29797  
    314314                        case 'IN':
    315315                        case 'NOT IN':
    316                                 return '(' . implode( ',', array_map( 'intval', (array) $value ) ) . ')';
     316                                $value = (array) $value;
     317
     318                                // Remove non-numeric values.
     319                                $value = array_filter( $value, 'is_numeric' );
     320
     321                                if ( empty( $value ) ) {
     322                                        return false;
     323                                }
     324
     325                                return '(' . implode( ',', array_map( 'intval', $value ) ) . ')';
    317326
    318327                        case 'BETWEEN':
    319328                        case 'NOT BETWEEN':
    320                                 if ( ! is_array( $value ) || 2 != count( $value ) || ! isset( $value[0] ) || ! isset( $value[1] ) )
     329                                if ( ! is_array( $value ) || 2 != count( $value ) ) {
    321330                                        $value = array( $value, $value );
     331                                } else {
     332                                        $value = array_values( $value );
     333                                }
     334
     335                                // If either value is non-numeric, bail.
     336                                foreach ( $value as $v ) {
     337                                        if ( ! is_numeric( $v ) ) {
     338                                                return false;
     339                                        }
     340                                }
    322341
    323342                                $value = array_map( 'intval', $value );
    … …  
    326345
    327346                        default;
     347                                if ( ! is_numeric( $value ) ) {
     348                                        return false;
     349                                }
     350
    328351                                return (int) $value;
    329352                }
Note: See TracChangeset for help on using the changeset viewer.