Opened 10 hours ago
Last modified 10 hours ago
#66695 new defect (bug)
REST API: Validate note reaction keys instead of stripping tags
| Reported by: | adamsilverstein | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | Awaiting Review |
| Component: | Notes | Version: | trunk |
| Severity: | normal | Keywords: | has-patch has-unit-tests |
| Cc: | Focuses: | rest-api |
Description
Claude drafted this ticket from the Gutenberg fix:
Follow up to [64488].
A note reaction stores its emoji as a hex key in
comment_content(eg.2764for a heart).WP_REST_Comments_Controllervalidates that key against the curated set on create, but each time it reads one back it runs the content throughwp_strip_all_tags()and uses whatever comes out. There are five calls inclass-wp-rest-comments-controller.php.
This has two problems:
- The reaction summary trusts any row. A reaction written by something other than the controller, with
heartor1F680as its content, shows up inreaction_summaryas another emoji.- Stripping folds different content together. A
<b>2764</b>row lands on the same key as a real2764row and one count overwrites the other.Proposed fix
- Add a check for the shape of a key: lowercase hex code points joined by
-, each a Unicode scalar value (nothing past U+10FFFF, no surrogates). The summary skips rows that fail it.- Compare stored content to the validated key exactly in the duplicate check and the concurrent-request cleanup.
- On create, trim the content and require an exact match with a curated key.
<b>2764</b>was accepted and stored as2764before; it would now returnrest_comment_invalid_reaction.The same change for the Gutenberg plugin, with tests: https://github.com/WordPress/gutenberg/pull/86775
Raised by @dmsnell in review: https://github.com/WordPress/gutenberg/pull/83169#discussion_r4547481345
Change History (1)
This ticket was mentioned in PR #15985 on WordPress/wordpress-develop by @adamsilverstein.
10 hours ago
#1
- Keywords has-patch has-unit-tests added
_Claude Code ported the Gutenberg fix over and wrote this up:_
Use of AI Tools
Claude Code wrote the code, the tests and this description, porting the change from the Gutenberg PR. I will review and test.