From d7105c2b80978000910446d2169b3da84d226608 Mon Sep 17 00:00:00 2001 From: jorgelr771 Date: Wed, 2 Sep 2026 10:47:57 +0200 Subject: [PATCH] Database: Prevent SQL FROM keyword matching inside string literals in wpdb::get_table_from_query() --- src/wp-includes/class-wpdb.php | 2 +- tests/phpunit/tests/db.php | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/class-wpdb.php b/src/wp-includes/class-wpdb.php index a676d395ee95c..2d128dcb8dd9f 100644 --- a/src/wp-includes/class-wpdb.php +++ b/src/wp-includes/class-wpdb.php @@ -3874,7 +3874,7 @@ protected function get_table_from_query( $query ) { // Quickly match most common queries. if ( preg_match( '/^\s*(?:' - . 'SELECT.*?\s+FROM' + . 'SELECT.*\s+FROM' . '|INSERT(?:\s+LOW_PRIORITY|\s+DELAYED|\s+HIGH_PRIORITY)?(?:\s+IGNORE)?(?:\s+INTO)?' . '|REPLACE(?:\s+LOW_PRIORITY|\s+DELAYED)?(?:\s+INTO)?' . '|UPDATE(?:\s+LOW_PRIORITY)?(?:\s+IGNORE)?' diff --git a/tests/phpunit/tests/db.php b/tests/phpunit/tests/db.php index 22eeb235e4819..7b245eff3ce01 100644 --- a/tests/phpunit/tests/db.php +++ b/tests/phpunit/tests/db.php @@ -866,6 +866,9 @@ public function data_get_table_from_query() { // @ticket 63777 "SET STATEMENT max_statement_time=1 FOR SELECT * FROM $table", + + // @ticket 43664 + "SELECT c AS 'a from b' FROM $table", ); $querycount = count( $queries );