Commit 9c81c2719e8 for woocommerce
commit 9c81c2719e8d8f359eaa6ca9ac3dc8ba68fcfc6c
Author: Luigi Teschio <gigitux@gmail.com>
Date: Fri Nov 20 17:07:04 2026 +0100
Escape customer data in admin order search results (#71210)
(cherry picked from commit e272ccacf3f3283aeb777ab2336c26ba94a24d4e)
Co-authored-by: Thomas Roberts <5656702+opr@users.noreply.github.com>
diff --git a/plugins/woocommerce/includes/class-wc-ajax.php b/plugins/woocommerce/includes/class-wc-ajax.php
index 70d353414da..418c4efbafe 100644
--- a/plugins/woocommerce/includes/class-wc-ajax.php
+++ b/plugins/woocommerce/includes/class-wc-ajax.php
@@ -2386,14 +2386,13 @@ class WC_AJAX {
// phpcs:enable WordPress.Security.NonceVerification.Recommended
foreach ( $ids as $id ) {
- $customer = new WC_Customer( $id );
- /* translators: 1: user display name 2: user ID 3: user email */
+ $customer = new WC_Customer( $id );
$found_customers[ $id ] = sprintf(
- /* translators: $1: customer name, $2 customer id, $3: customer email */
+ /* translators: 1: customer name, 2: customer ID, 3: customer email */
esc_html__( '%1$s (#%2$s – %3$s)', 'woocommerce' ),
- $customer->get_first_name() . ' ' . $customer->get_last_name(),
+ esc_html( $customer->get_first_name() . ' ' . $customer->get_last_name() ),
$customer->get_id(),
- $customer->get_email()
+ esc_html( $customer->get_email() )
);
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php b/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php
index e9d1ae02b1c..b6985a6e27f 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-ajax-test.php
@@ -1943,6 +1943,44 @@ class WC_AJAX_Test extends \WP_Ajax_UnitTestCase {
);
}
+ /**
+ * @testdox Customer search escapes HTML in customer names.
+ *
+ * @throws Automattic\WooCommerce\Internal\DependencyManagement\ContainerException If the LegacyProxy cannot be retrieved.
+ */
+ public function test_json_search_customers_escapes_html_in_names(): void {
+ $legacy_proxy = wc_get_container()->get( LegacyProxy::class );
+
+ try {
+ $legacy_proxy->reset();
+ $legacy_proxy->register_function_mocks(
+ array(
+ 'check_ajax_referer' => fn () => true,
+ )
+ );
+
+ $customer = WC_Helper_Customer::create_customer( 'test1', 'pass1', 'test1@example.com' );
+ $customer->set_first_name( 'Test' );
+ $customer->set_last_name( '<img src=x onerror=alert(1)>' );
+ $customer->save();
+
+ wp_set_current_user( self::factory()->user->create( array( 'role' => 'administrator' ) ) );
+ $_GET['term'] = $customer->get_id();
+
+ $response = $this->do_ajax( 'woocommerce_json_search_customers' );
+ } finally {
+ unset( $_GET['term'] );
+ wp_set_current_user( 0 );
+ $legacy_proxy->reset();
+ }
+
+ $this->assertSame(
+ sprintf( 'Test <img src=x onerror=alert(1)> (#%1$d – test1@example.com)', $customer->get_id() ),
+ $response[ $customer->get_id() ],
+ 'Customer search results should contain escaped names.'
+ );
+ }
+
/**
* Describe JSON search, particularly as it relates to handling searches for users in a
* multisite context (it should generally not be possible to retrieve information about