Playlist: Use wp_kses for safer tag stripping#76093
Open
Conversation
Replace wp_strip_all_tags() with wp_kses() + wp_specialchars_decode() for sanitizing track metadata (title, artist, album, ariaLabel). wp_strip_all_tags() internally uses strip_tags(), which treats any `<` as the start of an HTML tag. This means content like "I <3 Music" would incorrectly have "<3 Music" stripped, resulting in just "I ". The new approach uses wp_kses( $text, array() ) which properly distinguishes real HTML tags from non-tag content containing `<`/`>`, followed by wp_specialchars_decode() to convert entities back to plain text since the data is JSON-encoded via wp_interactivity_state(). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
Flaky tests detected in f4bc725. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/22631443077
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What?
Replaces
wp_strip_all_tags()withwp_kses() + wp_specialchars_decode()for sanitizing track metadata (title, artist, album, ariaLabel) in the playlist block's PHP render function.Why?
This addresses a review comment from @tyxla on PR #75203:
wp_strip_all_tags()internally uses PHP'sstrip_tags(), which treats any<character as the start of an HTML tag. This means content like "I <3 Music" would have<3 Musicstripped entirely, resulting in just "I ". While unusual for track titles, this is unnecessarily aggressive sanitization.How?
The new approach:
wp_kses( $text, array() )- Strips all HTML tags but properly distinguishes between real HTML tags (like<br>,<script>) and non-tag content containing</>. Non-tag<is encoded as<rather than being stripped.wp_specialchars_decode()- Decodes the HTML entities back to plain characters, since the data goes into JSON viawp_interactivity_state()and doesn't need HTML encoding.This preserves the security properties (stripping actual HTML tags) while being more accurate about what constitutes a tag.
Testing Instructions
<or>characters (e.g., "I <3 Music")<character preserved🤖 Generated with Claude Code