From 7f516052e212b5aacceaa2152feb98d23b48dd4b Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 13 Nov 2026 09:57:21 -0800 Subject: [PATCH 1/8] REST API: Add failing tests for malformed note reaction keys A reaction row whose content is not a key should be left out of the summary, and markup around a key should be rejected on create. See #66695. --- .../rest-api/rest-comments-controller.php | 72 ++++++++++++++++--- 1 file changed, 64 insertions(+), 8 deletions(-) diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 898b344842f9a..9bd33f5c0fb24 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -4997,13 +4997,13 @@ public static function data_uncurated_reaction_keys() { } /** - * The stored reaction content is the validated, canonical key - markup - * around the key must not reach the database, or `reaction_summary` - * grouping would split visually identical reactions. + * Markup around a key is not a key, so it is rejected and never reaches + * the database. * * @ticket 64638 + * @ticket 66695 */ - public function test_create_reaction_stores_canonical_key() { + public function test_create_reaction_rejects_markup_around_key(): void { wp_set_current_user( self::$editor_id ); $post_id = self::factory()->post->create(); @@ -5032,10 +5032,7 @@ public function test_create_reaction_stores_canonical_key() { ); $response = rest_get_server()->dispatch( $request ); - $this->assertSame( 201, $response->get_status() ); - - $new_comment = get_comment( $response->get_data()['id'] ); - $this->assertSame( '2764', $new_comment->comment_content ); + $this->assertErrorResponse( 'rest_comment_invalid_reaction', $response, 400 ); } /** @@ -6635,4 +6632,63 @@ public function test_reaction_summary_excludes_trashed_reactions() { $this->assertSame( array(), $response->get_data()['reaction_summary'] ); } + + /** + * A row whose content is not a reaction key, written by something other + * than this controller, is left out and not counted as another emoji. + * + * @ticket 66695 + * + * @dataProvider data_malformed_reaction_content + * + * @param string $content The stored reaction content. + */ + public function test_reaction_summary_omits_malformed_reaction_content( string $content ): void { + wp_set_current_user( self::$editor_id ); + + $note_id = self::factory()->comment->create( + array( + 'comment_post_ID' => self::$post_id, + 'comment_type' => 'note', + 'comment_approved' => 0, + 'user_id' => self::$editor_id, + 'comment_content' => 'Test note', + ) + ); + $reaction_id = $this->create_reaction_for_update_tests( self::$post_id, $note_id, self::$editor_id ); + $this->create_reaction_for_update_tests( self::$post_id, $note_id, self::$admin_id, $content ); + + $response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/comments/' . $note_id ) ); + $data = $response->get_data(); + $this->assertIsArray( $data ); + + $summary = $data['reaction_summary']; + $this->assertIsArray( $summary ); + + // PHP casts the numeric string key to an integer. + $this->assertSame( array( 2764 ), array_keys( $summary ) ); + $this->assertSame( + array( + 'count' => 1, + 'current_user_reaction' => $reaction_id, + ), + $summary['2764'] + ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_malformed_reaction_content(): array { + return array( + 'markup around a key' => array( '2764' ), + 'not hex' => array( 'heart' ), + 'uppercase hex' => array( '1F680' ), + 'beyond the last code point' => array( '110000' ), + 'surrogate' => array( 'd83d' ), + 'trailing separator' => array( '1f44d-' ), + ); + } } From 937d62ff801457fa3c3554a5267fb6bf2b6d9983 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Fri, 13 Nov 2026 09:57:21 -0800 Subject: [PATCH 2/8] REST API: Validate note reaction keys instead of stripping tags wp_strip_all_tags() let any stored content through as a summary key and folded "2764" into "2764". Check the shape of a stored key and compare validated keys exactly. See #66695. --- .../class-wp-rest-comments-controller.php | 49 ++++++++++++++++--- 1 file changed, 41 insertions(+), 8 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index f5739e6b3a3f3..6d84b4accd62b 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -52,6 +52,34 @@ private static function get_note_reaction_keys(): array { return array( '1f44d', '2795', '2764', '1f389', '1f604', '1f440', '1f680' ); } + /** + * Determines whether a stored value has the shape of a reaction key. + * + * A key is one or more Unicode scalar values in lowercase hex, joined + * by `-`. The shape is checked, not the curated set, so a reaction + * stays readable if the set changes. + * + * @since 7.2.0 + * + * @param string $value Stored reaction content. + * @return bool True for a well-formed key. + */ + private static function is_reaction_key( string $value ): bool { + if ( 1 !== preg_match( '/^[0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*$/D', $value ) ) { + return false; + } + + foreach ( explode( '-', $value ) as $hex ) { + $code_point = hexdec( $hex ); + // Beyond the last code point, or a surrogate. + if ( $code_point > 0x10FFFF || ( $code_point >= 0xD800 && $code_point <= 0xDFFF ) ) { + return false; + } + } + + return true; + } + /** * Constructor. * @@ -812,7 +840,7 @@ public function create_item( $request ) { $raw_content = $request['content']['raw']; } - $emoji_key = trim( wp_strip_all_tags( $raw_content ) ); + $emoji_key = trim( $raw_content ); if ( ! in_array( $emoji_key, self::get_note_reaction_keys(), true ) ) { return new WP_Error( @@ -853,7 +881,7 @@ public function create_item( $request ) { ); foreach ( $existing as $existing_reaction ) { - if ( wp_strip_all_tags( $existing_reaction->comment_content ) === $emoji_key ) { + if ( $existing_reaction->comment_content === $emoji_key ) { return new WP_Error( 'rest_comment_duplicate_reaction', __( 'You have already reacted with this emoji.' ), @@ -875,7 +903,7 @@ public function create_item( $request ) { /* * Persist the validated, canonical reaction key rather than the raw * request content, so stored values stay consistent for grouping and - * counting (e.g. "2764" is stored as "2764"). + * counting (e.g. " 2764" is stored as "2764"). */ if ( null !== $reaction_key ) { $prepared_comment['comment_content'] = $reaction_key; @@ -1045,7 +1073,7 @@ public function create_item( $request ) { ); $duplicates = array(); foreach ( $matching as $candidate ) { - if ( wp_strip_all_tags( $candidate->comment_content ) === $reaction_key ) { + if ( $candidate->comment_content === $reaction_key ) { $duplicates[] = (int) $candidate->comment_ID; } } @@ -2370,7 +2398,7 @@ protected function prefetch_reaction_summaries( $note_ids ) { if ( $user_rows ) { foreach ( $user_rows as $row ) { - $key = (int) $row->comment_parent . ':' . wp_strip_all_tags( $row->comment_content ); + $key = (int) $row->comment_parent . ':' . $row->comment_content; $my_reactions[ $key ] = (int) $row->comment_ID; } } @@ -2386,9 +2414,14 @@ protected function prefetch_reaction_summaries( $note_ids ) { } foreach ( $counts as $row ) { - $note_id = (int) $row->comment_parent; - $emoji_key = wp_strip_all_tags( $row->comment_content ); - $key = $note_id . ':' . $emoji_key; + $emoji_key = $row->comment_content; + // Rows written outside this controller may hold anything. + if ( ! is_string( $emoji_key ) || ! self::is_reaction_key( $emoji_key ) ) { + continue; + } + + $note_id = (int) $row->comment_parent; + $key = $note_id . ':' . $emoji_key; $this->reaction_summaries[ $note_id ][ $emoji_key ] = array( 'count' => (int) $row->reaction_count, From 611895d3577c7028ba7892fd88474987b8730951 Mon Sep 17 00:00:00 2001 From: Adam Silverstein Date: Tue, 24 Nov 2026 12:00:40 -0800 Subject: [PATCH 3/8] Improve doc block --- .../endpoints/class-wp-rest-comments-controller.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index bcd9b8898ad8c..e5f7d57634293 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -53,16 +53,15 @@ private static function get_note_reaction_keys(): array { } /** - * Determines whether a stored value has the shape of a reaction key. - * - * A key is one or more Unicode scalar values in lowercase hex, joined - * by `-`. The shape is checked, not the curated set, so a reaction - * stays readable if the set changes. + * Determines if a given value represents a valid reaction key. * + * Reaction keys are described by a sequence of one or more Unicode + * Scalar Values joined by a hyphen (U+2D). + * * @since 7.2.0 * - * @param string $value Stored reaction content. - * @return bool True for a well-formed key. + * @param string $value Potentially contains a valid reaction key. + * @param bool Whether the given value comprises a well-formed reaction key. */ private static function is_reaction_key( string $value ): bool { if ( 1 !== preg_match( '/^[0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*$/D', $value ) ) { From f22c771a9a7d873290edf53d6d49a90f9d8880eb Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Tue, 24 Nov 2026 12:13:29 -0800 Subject: [PATCH 4/8] Notes: Check reaction keys with strspn() instead of PCRE The pattern accepted several spellings of one code point (`02764` next to `2764`). Accept a single spelling per code point - lowercase hex, zero-padded to four digits - so equal reactions always share a summary bucket, and drop the regular expression for a span check. See #66695. --- .../class-wp-rest-comments-controller.php | 15 +++-- .../rest-api/rest-comments-controller.php | 59 +++++++++++++++++++ 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index e5f7d57634293..2386273fc2431 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -56,19 +56,26 @@ private static function get_note_reaction_keys(): array { * Determines if a given value represents a valid reaction key. * * Reaction keys are described by a sequence of one or more Unicode - * Scalar Values joined by a hyphen (U+2D). - * + * Scalar Values joined by a hyphen (U+2D). Each is written one way + * only: lowercase hex, zero-padded to four digits. + * * @since 7.2.0 * * @param string $value Potentially contains a valid reaction key. - * @param bool Whether the given value comprises a well-formed reaction key. + * @return bool Whether the given value comprises a well-formed reaction key. */ private static function is_reaction_key( string $value ): bool { - if ( 1 !== preg_match( '/^[0-9a-f]{4,6}(?:-[0-9a-f]{4,6})*$/D', $value ) ) { + if ( strlen( $value ) !== strspn( $value, '-0123456789abcdef' ) ) { return false; } foreach ( explode( '-', $value ) as $hex ) { + $length = strlen( $hex ); + // Too short (or an empty span), too long, or zero-padded past four digits. + if ( $length < 4 || $length > 6 || ( $length > 4 && '0' === $hex[0] ) ) { + return false; + } + $code_point = hexdec( $hex ); // Beyond the last code point, or a surrogate. if ( $code_point > 0x10FFFF || ( $code_point >= 0xD800 && $code_point <= 0xDFFF ) ) { diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 5c101dda18f3e..2e8c05bde0884 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -6689,6 +6689,65 @@ public function data_malformed_reaction_content(): array { 'beyond the last code point' => array( '110000' ), 'surrogate' => array( 'd83d' ), 'trailing separator' => array( '1f44d-' ), + 'leading separator' => array( '-1f44d' ), + 'empty span' => array( '1f44d--fe0f' ), + 'fewer than four digits' => array( 'a9' ), + 'padded past four digits' => array( '02764' ), + 'more than six digits' => array( '0002764' ), + ); + } + + /** + * A well-formed key outside the curated set stays readable, so a + * reaction survives a change to the set. + * + * @ticket 66695 + * + * @dataProvider data_well_formed_reaction_content + * + * @param string $content The stored reaction content. + */ + public function test_reaction_summary_keeps_well_formed_reaction_content( string $content ): void { + wp_set_current_user( self::$editor_id ); + + $note_id = self::factory()->comment->create( + array( + 'comment_post_ID' => self::$post_id, + 'comment_type' => 'note', + 'comment_approved' => 0, + 'user_id' => self::$editor_id, + 'comment_content' => 'Test note', + ) + ); + $reaction_id = $this->create_reaction_for_update_tests( self::$post_id, $note_id, self::$editor_id, $content ); + + $response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/comments/' . $note_id ) ); + $data = $response->get_data(); + $this->assertIsArray( $data ); + + $this->assertSame( + array( + $content => array( + 'count' => 1, + 'current_user_reaction' => $reaction_id, + ), + ), + $data['reaction_summary'] + ); + } + + /** + * Data provider. + * + * @return array + */ + public function data_well_formed_reaction_content(): array { + return array( + 'padded to four digits' => array( '00a9' ), + 'five digits' => array( '1f680' ), + 'last code point' => array( '10ffff' ), + 'keycap sequence' => array( '0023-fe0f-20e3' ), + 'joined sequence' => array( '1f468-200d-1f469-200d-1f467' ), ); } } From 63ce68c63c2bec5606b274d652703cbc24857679 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Tue, 24 Nov 2026 12:13:29 -0800 Subject: [PATCH 5/8] Notes: Type the reaction summary query rows Describe the rows wpdb returns so the summary code passes PHPStan at level 10, which makes the is_string() guard redundant. See #66695. --- .../rest-api/endpoints/class-wp-rest-comments-controller.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index 2386273fc2431..5d4cc2fc16a90 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -2417,6 +2417,7 @@ protected function prefetch_reaction_summaries( $note_ids ) { $query = "SELECT comment_parent, comment_content, COUNT(*) AS reaction_count FROM $wpdb->comments WHERE comment_type = 'reaction' AND comment_approved = '1' AND "; $query .= $parent_in; $query .= ' GROUP BY comment_parent, comment_content'; + /** @var list|null $counts */ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $counts = $wpdb->get_results( $query ); @@ -2426,6 +2427,7 @@ protected function prefetch_reaction_summaries( $note_ids ) { $query = "SELECT comment_ID, comment_parent, comment_content FROM $wpdb->comments WHERE comment_type = 'reaction' AND comment_approved = '1' AND "; $query .= $parent_in; $query .= $wpdb->prepare( ' AND user_id = %d', $current_user_id ); + /** @var list|null $user_rows */ // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared $user_rows = $wpdb->get_results( $query ); @@ -2449,7 +2451,7 @@ protected function prefetch_reaction_summaries( $note_ids ) { foreach ( $counts as $row ) { $emoji_key = $row->comment_content; // Rows written outside this controller may hold anything. - if ( ! is_string( $emoji_key ) || ! self::is_reaction_key( $emoji_key ) ) { + if ( ! self::is_reaction_key( $emoji_key ) ) { continue; } From 9168954eb06995438ad278b4bbe5dc7a2aef71bb Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Tue, 24 Nov 2026 12:16:11 -0800 Subject: [PATCH 6/8] Notes: Assign reaction counts instead of accumulating them Keys are no longer stripped of tags, so each group of rows maps to its own key and nothing is left to add up. See #66695. --- .../endpoints/class-wp-rest-comments-controller.php | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index d57cd8a47c06f..e4fe3b4d40c0e 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -2512,15 +2512,10 @@ protected function prefetch_reaction_summaries( $note_ids ) { continue; } - // Rows are grouped on the raw content, so several groups can strip to one key. - if ( ! isset( $this->reaction_summaries[ $note_id ][ $emoji_key ] ) ) { - $this->reaction_summaries[ $note_id ][ $emoji_key ] = array( - 'count' => 0, - 'current_user_reaction' => $my_reactions[ $key ] ?? 0, - ); - } - - $this->reaction_summaries[ $note_id ][ $emoji_key ]['count'] += (int) $row->reaction_count; + $this->reaction_summaries[ $note_id ][ $emoji_key ] = array( + 'count' => (int) $row->reaction_count, + 'current_user_reaction' => $my_reactions[ $key ] ?? 0, + ); } } From 3b36f6f89d0bad73c129888ae76997f32137f271 Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Tue, 24 Nov 2026 13:06:33 -0800 Subject: [PATCH 7/8] Notes: Drop the reaction key shape check Since r65750 the summary only counts curated keys, an allow list that covers everything the shape check guarded. Compare stored content to the curated keys exactly and remove the helper. See #66695. --- .../class-wp-rest-comments-controller.php | 43 +------- .../rest-api/rest-comments-controller.php | 103 +++++++----------- 2 files changed, 41 insertions(+), 105 deletions(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index e4fe3b4d40c0e..ee1b29d719280 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -52,40 +52,6 @@ private static function get_note_reaction_keys(): array { return array( '1f44d', '2795', '2764', '1f389', '1f604', '1f440', '1f680' ); } - /** - * Determines if a given value represents a valid reaction key. - * - * Reaction keys are described by a sequence of one or more Unicode - * Scalar Values joined by a hyphen (U+2D). Each is written one way - * only: lowercase hex, zero-padded to four digits. - * - * @since 7.2.0 - * - * @param string $value Potentially contains a valid reaction key. - * @return bool Whether the given value comprises a well-formed reaction key. - */ - private static function is_reaction_key( string $value ): bool { - if ( strlen( $value ) !== strspn( $value, '-0123456789abcdef' ) ) { - return false; - } - - foreach ( explode( '-', $value ) as $hex ) { - $length = strlen( $hex ); - // Too short (or an empty span), too long, or zero-padded past four digits. - if ( $length < 4 || $length > 6 || ( $length > 4 && '0' === $hex[0] ) ) { - return false; - } - - $code_point = hexdec( $hex ); - // Beyond the last code point, or a surrogate. - if ( $code_point > 0x10FFFF || ( $code_point >= 0xD800 && $code_point <= 0xDFFF ) ) { - return false; - } - } - - return true; - } - /** * Constructor. * @@ -2498,14 +2464,9 @@ protected function prefetch_reaction_summaries( $note_ids ) { $allowed_keys = self::get_note_reaction_keys(); foreach ( $counts as $row ) { + $note_id = (int) $row->comment_parent; $emoji_key = $row->comment_content; - // Rows written outside this controller may hold anything. - if ( ! self::is_reaction_key( $emoji_key ) ) { - continue; - } - - $note_id = (int) $row->comment_parent; - $key = $note_id . ':' . $emoji_key; + $key = $note_id . ':' . $emoji_key; // Only curated emoji keys are summarized. if ( ! in_array( $emoji_key, $allowed_keys, true ) ) { diff --git a/tests/phpunit/tests/rest-api/rest-comments-controller.php b/tests/phpunit/tests/rest-api/rest-comments-controller.php index 7c78a82cf4b9b..277749a239563 100644 --- a/tests/phpunit/tests/rest-api/rest-comments-controller.php +++ b/tests/phpunit/tests/rest-api/rest-comments-controller.php @@ -6633,70 +6633,6 @@ public function test_reaction_summary_excludes_trashed_reactions() { $this->assertSame( array(), $response->get_data()['reaction_summary'] ); } - /** - * A row whose content is not a reaction key, written by something other - * than this controller, is left out and not counted as another emoji. - * - * @ticket 66695 - * - * @dataProvider data_malformed_reaction_content - * - * @param string $content The stored reaction content. - */ - public function test_reaction_summary_omits_malformed_reaction_content( string $content ): void { - wp_set_current_user( self::$editor_id ); - - $note_id = self::factory()->comment->create( - array( - 'comment_post_ID' => self::$post_id, - 'comment_type' => 'note', - 'comment_approved' => 0, - 'user_id' => self::$editor_id, - 'comment_content' => 'Test note', - ) - ); - $reaction_id = $this->create_reaction_for_update_tests( self::$post_id, $note_id, self::$editor_id ); - $this->create_reaction_for_update_tests( self::$post_id, $note_id, self::$admin_id, $content ); - - $response = rest_get_server()->dispatch( new WP_REST_Request( 'GET', '/wp/v2/comments/' . $note_id ) ); - $data = $response->get_data(); - $this->assertIsArray( $data ); - - $summary = $data['reaction_summary']; - $this->assertIsArray( $summary ); - - // PHP casts the numeric string key to an integer. - $this->assertSame( array( 2764 ), array_keys( $summary ) ); - $this->assertSame( - array( - 'count' => 1, - 'current_user_reaction' => $reaction_id, - ), - $summary['2764'] - ); - } - - /** - * Data provider. - * - * @return array - */ - public function data_malformed_reaction_content(): array { - return array( - 'markup around a key' => array( '2764' ), - 'not hex' => array( 'heart' ), - 'uppercase hex' => array( '1F680' ), - 'beyond the last code point' => array( '110000' ), - 'surrogate' => array( 'd83d' ), - 'trailing separator' => array( '1f44d-' ), - 'leading separator' => array( '-1f44d' ), - 'empty span' => array( '1f44d--fe0f' ), - 'fewer than four digits' => array( 'a9' ), - 'padded past four digits' => array( '02764' ), - 'more than six digits' => array( '0002764' ), - ); - } - /** * The curated reaction key for the heart emoji, as stored in a reaction's content. */ @@ -6791,6 +6727,45 @@ public function test_reaction_summary_ignores_uncurated_keys(): void { $this->assertSame( array(), $this->get_reaction_summary( $note_id ) ); } + /** + * A row holding markup around a curated key is not that key, so it is + * left out and does not add to the real key's count. + * + * @ticket 66695 + */ + public function test_reaction_summary_ignores_markup_around_a_curated_key(): void { + list( $post_id, $note_id ) = $this->create_editor_note(); + + $heart_id = self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'comment_type' => 'reaction', + 'comment_parent' => $note_id, + 'comment_approved' => 1, + 'user_id' => self::$editor_id, + 'comment_content' => self::HEART_REACTION_KEY, + ) + ); + + self::factory()->comment->create( + array( + 'comment_post_ID' => $post_id, + 'comment_type' => 'reaction', + 'comment_parent' => $note_id, + 'comment_approved' => 1, + 'user_id' => self::$subscriber_id, + 'comment_content' => '' . self::HEART_REACTION_KEY . '', + ) + ); + + $summary = $this->get_reaction_summary( $note_id ); + + $this->assertCount( 1, $summary ); + $this->assertArrayHasKey( self::HEART_REACTION_KEY, $summary ); + $this->assertSame( 1, $summary[ self::HEART_REACTION_KEY ]['count'] ); + $this->assertSame( $heart_id, $summary[ self::HEART_REACTION_KEY ]['current_user_reaction'] ); + } + /** * A note reply has to sit on the same post as the note it answers, or a * user could thread their own note under one on a post they cannot read. From 13623fb7f12863f9992376e7ce4ff137b4d3301d Mon Sep 17 00:00:00 2001 From: adamsilverstein Date: Sat, 28 Nov 2026 23:26:55 -0800 Subject: [PATCH 8/8] Notes: Flag where reaction key parsing belongs if the set widens Exact comparison against the fixed list is the only guard on request and stored reaction content. Note that at both comparisons so widening the set does not leave unvalidated keys behind. --- .../endpoints/class-wp-rest-comments-controller.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php index ee1b29d719280..305c0b1ee0631 100644 --- a/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php +++ b/src/wp-includes/rest-api/endpoints/class-wp-rest-comments-controller.php @@ -822,6 +822,11 @@ public function create_item( $request ) { $emoji_key = trim( $raw_content ); + /* + * An exact match against the fixed list is the only validation. If the + * set widens (any code point, grapheme clusters, slugs), parse and + * validate the key here. + */ if ( ! in_array( $emoji_key, self::get_note_reaction_keys(), true ) ) { return new WP_Error( 'rest_comment_invalid_reaction', @@ -2468,7 +2473,11 @@ protected function prefetch_reaction_summaries( $note_ids ) { $emoji_key = $row->comment_content; $key = $note_id . ':' . $emoji_key; - // Only curated emoji keys are summarized. + /* + * Only curated emoji keys are summarized. The exact match is also the + * only check on stored content, so a wider set needs the key parsed + * and validated here. + */ if ( ! in_array( $emoji_key, $allowed_keys, true ) ) { continue; }