Skip to content

Commit 917f5d4

Browse files
authored
_pad_term_counts() uses string-concatenated SQL without prepared statement
$object_types values are not individually escaped via $wpdb->prepare(). They use esc_sql() only at the get_taxonomy() call, but imploded directly into the query string. The array keys are integer IDs but are not cast. This should use prepare() with placeholders.
1 parent e12ddb3 commit 917f5d4

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

src/wp-includes/taxonomy.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4066,8 +4066,13 @@ function _pad_term_counts( &$terms, $taxonomy ) {
40664066
// Get the object and term IDs and stick them in a lookup table.
40674067
$tax_obj = get_taxonomy( $taxonomy );
40684068
$object_types = esc_sql( $tax_obj->object_type );
4069-
$results = $wpdb->get_results( "SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_keys( $term_ids ) ) . ") AND post_type IN ('" . implode( "', '", $object_types ) . "') AND post_status = 'publish'" );
4070-
4069+
$results = $wpdb->get_results(
4070+
$wpdb->prepare(
4071+
"SELECT object_id, term_taxonomy_id FROM $wpdb->term_relationships INNER JOIN $wpdb->posts ON object_id = ID WHERE term_taxonomy_id IN (" . implode( ',', array_fill( 0, count( $term_ids ), '%d' ) ) . ') AND post_type IN (' . implode( ',', array_fill( 0, count( $object_types ), '%s' ) ) . ") AND post_status = 'publish'",
4072+
array_merge( array_keys( $term_ids ), $object_types )
4073+
)
4074+
);
4075+
40714076
foreach ( $results as $row ) {
40724077
$id = $term_ids[ $row->term_taxonomy_id ];
40734078

0 commit comments

Comments
 (0)