Commit 10b2937fd1 for wordpress.org
commit 10b2937fd17570350bdeb25996d9d1c488a42bb5
Author: dmsnell <dmsnell@git.wordpress.org>
Date: Thu Dec 3 04:26:55 2026 +0000
KSES: Adjust restrictions for non-DATA text content.
Contents of IFRAME elements are not rendered in a browser, and while they are benign in terms of being parsed as RAWTEXT, it is prudent to empty them from untrusted content sources.
On the other hand, NOEMBED, NOFRAMES, and XMP (while all are deprecated) do render in browsers. To preserve fallback text in these elements, it’s reasonable to replace angle brackets with visually-similar characters to maintain as much of the plaintext rendering as is possible without making it easy for downstream parsers to misidentify content as markup.
Developed in: https://github.com/WordPress/wordpress-develop/pull/16209
Discussed in: https://core.trac.wordpress.org/ticket/66917
Follow-up to r64233.
Props dmsnell, jonsurrell.
Fixes #66917, see #66208.
Built from https://develop.svn.wordpress.org/trunk@65875
git-svn-id: http://core.svn.wordpress.org/trunk@64904 1a063a9b-81f0-0310-95a4-ce76da25c4cd
diff --git a/wp-includes/kses.php b/wp-includes/kses.php
index 0c88d9ab52..c92f6d9e12 100644
--- a/wp-includes/kses.php
+++ b/wp-includes/kses.php
@@ -2018,29 +2018,68 @@ function wp_sanitize_html_kses( $content, $allowed_html, $allowed_protocols = ar
}
if ( $is_special_atomic_element ) {
- if ( 'TITLE' === $token_name || 'TEXTAREA' === $token_name ) {
- /*
- * RCDATA nodes can be safely escaped, but this must be
- * done after enqueuing the update to avoid double-escaping.
- */
- $tag_maker->set_modifiable_text( $text );
- $tag_maker->lexical_updates['modifiable text']->text = strtr(
- $tag_maker->lexical_updates['modifiable text']->text,
- array(
- "\x00" => "\u{FFFD}",
- "\r" => '
',
- )
- );
- } elseif ( ! self::contains_a_block_delimiter( $text ) ) {
- // Other nodes not containing a block delimiter are safe.
- $tag_maker->set_modifiable_text( $text );
- } else {
- /*
- * But RAWTEXT and SCRIPT cannot be generally escaped, so reject
- * updates which would include something that could be misparsed
- * as a block comment delimiter.
- */
- $tag_maker->set_modifiable_text( '' );
+ switch ( $token_name ) {
+ case 'IFRAME':
+ /*
+ * IFRAME contents are ignored, so there is no reason to allow
+ * them from untrusted inputs.
+ */
+ $tag_maker->set_modifiable_text( '' );
+ break;
+
+ case 'TEXTAREA':
+ case 'TITLE':
+ /*
+ * RCDATA nodes can be safely escaped, but this must be
+ * done after enqueuing the update to avoid double-escaping.
+ */
+ $tag_maker->set_modifiable_text( $text );
+ $tag_maker->lexical_updates['modifiable text']->text = strtr(
+ $tag_maker->lexical_updates['modifiable text']->text,
+ array(
+ "\x00" => "\u{FFFD}",
+ "\r" => '
',
+ )
+ );
+ break;
+
+ case 'NOEMBED':
+ case 'NOFRAMES':
+ case 'XMP':
+ /*
+ * These elements are obsolete and their contents are not
+ * unescaped; therefore make a visual change to prevent
+ * downstream parsers from interpreting content as markup.
+ * The alternative is rejecting the elements entirely, which
+ * is the default behavior unless they are specifically allowed.
+ *
+ * Replacing angle brackets with U+27E8 and U+27E9 is a practical
+ * content degradation that will mostly preserve the contents
+ * perceptually while retaining as much as is safely possible.
+ */
+ $text = strtr(
+ $text,
+ array(
+ '<' => '⟨',
+ '>' => '⟩',
+ )
+ );
+ $tag_maker->set_modifiable_text( $text );
+ break;
+
+ default:
+ if ( self::contains_a_block_delimiter( $text ) ) {
+ /*
+ * Reject special atomic elements whose contents contain the syntax
+ * for a block comment delimiter to prevent accidental parses. There
+ * is no reliable way to escape their content, so rejecting it is a
+ * more fitting approach for untrusted inputs.
+ */
+ $tag_maker->set_modifiable_text( '' );
+ } else {
+ // Otherwise consider the contents safe to pass through.
+ $tag_maker->set_modifiable_text( $text );
+ }
}
}
diff --git a/wp-includes/version.php b/wp-includes/version.php
index 3b0792c3e7..f04ec0de67 100644
--- a/wp-includes/version.php
+++ b/wp-includes/version.php
@@ -16,7 +16,7 @@
*
* @global string $wp_version
*/
-$wp_version = '7.3-alpha-65874';
+$wp_version = '7.3-alpha-65875';
/**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.