Repository navigation
Notes: Tighten note and reaction rules, compare reaction keys exactly - #86775
adamsilverstein wants to merge 13 commits into
Conversation
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.
wp_strip_all_tags() let any stored content through as a summary key and folded "<b>2764</b>" into "2764". Check the shape of a stored key and compare validated keys exactly.
🤖 PR meta 🤖🎉 PropsIf you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. Props Bot commandsYou can trigger Props Bot actions by commenting on this PR:
Updated as activity occurs, without notifying anyone named here. Add the ⚡ PerformanceShow the resultsClient side metrics exclude the server response time. front-end-block-theme
front-end-classic-theme
media-processing
media-upload
post-editor
site-editor
🏁 Flaky testsSome tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information. should undo without broken temporary state in
|
Link the Core PR for Trac #66695 so the backport check can find it.
| * @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 ) ) { |
There was a problem hiding this comment.
this appears to limit the code points to those requiring 4–6 characters, but still lets through code points such as 000a. that’s not problematic, but lets certain syntax forms through while rejecting others when they refer to the same code point.
if the goal is a fast rejection of strings containing unallowed characters, strspn() can be used, and then the only additional check would be inside the foreach for empty spans
if ( strlen( $value ) !== strspn( $value, '-01234567789abcdef' ) ) {
return false;
}
foreach ( explode( '-', $value ) as $hex ) {
$code_point = hexdec( $hex );
if ( '' === $hex || $code_point > 0x10FFFF || ( ... ) ) {
return false;
}
}
return true;nothing significant, but it leaves the PCRE in an awkward spot because it rejects some values which are allowed as syntactical variations, while it allows some forms that may not be expected.
making the PCRE tighter would involve [1-9a-f][0-9a-f]{3,5} to ensure there aren’t leading zeros. relaxing it would be pointless compared to strspn() which performs the check with less complexity and zero allocation.
fun fact! \A and \Z do what I think you are looking for here with the combination of $ and /D. they always work. I have found the PCRE docs way more useful than the PHP docs for the preg_ functions too. anchors and simple assertions
There was a problem hiding this comment.
I like the strspn suggestion, I'll give that a try!
| // Rows written outside this controller may hold anything. | ||
| if ( ! is_string( $slug ) || ! self::is_reaction_key( $slug ) ) { | ||
| continue; | ||
| } |
There was a problem hiding this comment.
first thought: is it important to reject values like 1F170 vs. 1f170?
second thought: if this were self::parse_reaction_key() then the trimming and normalization and rejection could all happen in that method.
$reaction_key = self::parse_reaction_key( $slug );
if ( null === $reaction_key ) {
continue;
}
// now $reaction_key is lowercase, trimmed, and fully-normativeThe 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.
Describe the rows wpdb returns so the summary code passes PHPStan at level 10, which makes the is_string() guard redundant.
Core trunk annotates these rows as decimal-int-string objects; use the same annotation so the backport stays line for line.
|
Coming back to this again I realized it may not be needed yet, now that this change when enforces emojis are one of the predefined set was merged in on WordPress/wordpress-develop#15853. If we enable extensibility, we might need to change the approach, but in theory we should be able to use an allow list approach to be even more precise and declarative than the matching in this PR. We can probably close the core backport of this, and bring the core fixes from 15853 back over to Gutenberg's compat files. |
…ey-read-validation
Core now only counts reactions that carry a curated key (r65750), an allow list that covers what the shape check was guarding. Return the controller to trunk ahead of porting that change.
Port the REST API half of core r65750: a note reply needs a note on the same post as its parent, a note with replies or reactions stays on its post, and reaction_summary only counts reactions on their note's post that carry a curated key. The Ajax and XML-RPC handlers that commit also changed live in core files the plugin does not override.
A reaction's content is a curated key or it is not a reaction the controller wrote. Stripping tags first let markup around a key pass on create and count toward the real key in the summary.
I repurposed this PR to bring back over the changes from core that tighten and improve reaction handling, including matching the emoji from the list exactly and the |
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.
Claude Code (Fable 5.2) reworked this PR into the port and rewrote the description:
AI Use
Claude Code (Fable 5.2) wrote the port, the tests and this description. I will review and test.
🤖 Generated with Claude Code
https://claude.ai/code/session_018vwYjUFvgZaeA8cQrCjN2u