Repository navigation
KSES: Keep the content after a NOSCRIPT element when its end is clear. - #16227
mayankmajeji wants to merge 1 commit into
Conversation
Since the HTML API reimplementation of KSES, sanitizing stops at the first NOSCRIPT opening tag, so everything after it is lost when a user without the unfiltered_html capability saves a post, or someone leaves a comment. A browser with scripting enabled reads NOSCRIPT contents as plain text up to the first `</noscript`, while the Tag Processor, like a browser with scripting disabled, parses them as HTML. When both readings end the element at the same place, the element and its contents are now removed and sanitizing continues after it. Otherwise, sanitizing still stops there. See #66674.
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. Core Committers: Use this line as a base for the props when committing in SVN: 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:
|
Test using WordPress PlaygroundThe changes in this pull request can previewed and tested using a WordPress Playground instance. WordPress Playground is an experimental project that creates a full WordPress instance entirely within the browser. Some things to be aware of
For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation. |
Since the HTML API reimplementation of KSES ([64233]), sanitizing stops at the first
<noscript>opening tag. When a user withoutunfiltered_htmlsaves a post, or someone leaves a comment, everything after the<noscript>is lost:This follows the approach @dmsnell described in https://core.trac.wordpress.org/ticket/66674#comment:8. It does not nest NOSCRIPT elements, which is what made #15927 unsafe.
What changes
At an HTML
<noscript>opening tag, a new private methodskip_noscript_element():</noscriptfollowed by whitespace,/or>in the raw HTML. This is where a browser with scripting enabled ends the element, because it reads the contents as plain text.</noscript(a comment, an attribute value, SCRIPT, STYLE, TEXTAREA, TITLE and similar);</noscript>is ignored while an element such as P or DIV is still open, and a closing tag for an element outside would close the NOSCRIPT early;Otherwise, sanitizing stops at the NOSCRIPT element as it does now. The output never contains a NOSCRIPT element, so a browser never has to choose between the two readings. Inside SVG or MathML, nothing changes.
The contents are removed rather than sanitized and kept. The ticket says that is fine, and keeping them would show fallback content (for example the duplicate
<noscript>images in Squarespace exports) to every visitor.Testing
New tests in
tests/phpunit/tests/kses/noscript.php(--filter Tests_Kses_Noscript, 25 tests):</noscriptinside a comment, an attribute value and a TEXTAREA, a nested NOSCRIPT, unclosed P and DIV elements, a closing tag for an element outside, SVG with CDATA, PLAINTEXT, and block delimiters. These pass on trunk and with this change.Other checks, with PHP 8.4.28, MySQL 9.7.4 and PHPUnit 9.6.39 in the wordpress-develop Docker environment:
--group kses: OK (585 tests, 1,654 assertions), single site and multisite.--group comment,--group html-api,--filter Tests_Post_Filtering: OK.--group formattingshows the same 5 PHPUnit deprecation warnings as trunk.WP_HTML_Processor(scripting disabled) also closed the NOSCRIPT element at the first raw</noscript. The output never contained a SCRIPT, NOSCRIPT, IFRAME or PLAINTEXT tag or anon*attribute, and sanitizing it again did not change it.kses.php.Props sainathpoojary for the first PR and jamesbregenzer for the suggestion to test a Contributor save.
Trac ticket: https://core.trac.wordpress.org/ticket/66674
Use of AI Tools
AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: Investigation, code, local testing and PR wording. I reviewed the reasoning, the code and the test results, and I take responsibility for the contribution.
This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.