Commit c2cc10b6568 for woocommerce
commit c2cc10b6568dea42a698a31b21cdd0342bb89c77
Author: Luigi Teschio <gigitux@gmail.com>
Date: Wed Oct 28 14:46:34 2026 +0100
Strengthen download permission ID checks (#70329)
* Strengthen download permission ID checks
* Add changelog entry for download permission checks
* Match download permissions exactly before limiting results
* Remove redundant download ID check
diff --git a/plugins/woocommerce/changelog/fix-download-permission-exact-id b/plugins/woocommerce/changelog/fix-download-permission-exact-id
new file mode 100644
index 00000000000..edf3df088a6
--- /dev/null
+++ b/plugins/woocommerce/changelog/fix-download-permission-exact-id
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Strengthen download permission ID checks
diff --git a/plugins/woocommerce/includes/data-stores/class-wc-customer-download-data-store.php b/plugins/woocommerce/includes/data-stores/class-wc-customer-download-data-store.php
index e6f2a219ea1..c27359b1d2b 100644
--- a/plugins/woocommerce/includes/data-stores/class-wc-customer-download-data-store.php
+++ b/plugins/woocommerce/includes/data-stores/class-wc-customer-download-data-store.php
@@ -459,7 +459,12 @@ class WC_Customer_Download_Data_Store implements WC_Customer_Download_Data_Store
}
if ( $args['download_id'] ) {
- $query[] = $wpdb->prepare( 'AND download_id = %s', $args['download_id'] );
+ // Keep the indexed lookup while requiring an exact match before ordering and limiting the results.
+ $query[] = $wpdb->prepare(
+ 'AND download_id = %s AND CAST(download_id AS BINARY) = CAST(%s AS BINARY)',
+ $args['download_id'],
+ $args['download_id']
+ );
}
$orderby = in_array( $args['orderby'], $valid_fields, true ) ? $args['orderby'] : 'permission_id';