Skip to content

KSES: Remove NOSCRIPT elements without discarding the content that follows them - #14841

Open
mpeshev wants to merge 1 commit into
WordPress:trunkfrom
mpeshev:66208-kses-noscript
Open

mpeshev wants to merge 1 commit into
WordPress:trunkfrom
mpeshev:66208-kses-noscript

Conversation

@mpeshev

@mpeshev mpeshev commented Oct 25, 2026

Copy link
Copy Markdown

The HTML API based wp_kses() stops sanitizing at the first NOSCRIPT opening tag (break in sanitize()), so everything after it is dropped. For users without unfiltered_html (Authors, Contributors, commenters), a post or comment that contains a NOSCRIPT fallback loses the rest of its content on save:

Input 7.1.3 7.2-beta1
Before <noscript><img src="a.jpg"></noscript> after the noscript. Before <img src="a.jpg"> after the noscript. Before

This skips the NOSCRIPT element together with its contents and continues after its closer. Nothing inside a NOSCRIPT is emitted, so untrusted input still cannot produce one, including through a </noscript> hidden in an attribute value (one of the test cases). An unclosed NOSCRIPT still truncates, like other incomplete input.

Trac ticket: https://core.trac.wordpress.org/ticket/66208

Testing

  • vendor/bin/phpunit --filter test_wp_kses_removes_noscript_and_keeps_following_content: 5 of the 6 cases fail without the patch, all pass with it.
  • vendor/bin/phpunit --group kses (529 tests) and --group html-api (2051 tests) pass.
  • Merges cleanly with KSES: Preserve escaped shortcode brackets in text nodes #14770.

Use of AI Tools

AI assistance: Yes
Tool(s): Claude Code
Model(s): Claude Opus 5.5
Used for: finding the issue, drafting the fix and tests, and running them. I reviewed every line and reproduced the output above on 7.1.3 and 7.2-beta1.


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.

🤖 Generated with Claude Code

…llows them.

The HTML API based `wp_kses()` stopped sanitizing at the first NOSCRIPT opening tag, so everything after it was dropped from the output. For users without `unfiltered_html`, such as Authors, Contributors and commenters, any post or comment containing a NOSCRIPT fallback lost the rest of its content on save. In 7.1, the NOSCRIPT tags were removed and the following content was kept.

Skip NOSCRIPT elements together with their contents, as untrusted input still must not produce them, and continue with the rest of the document.

Follow-up to [64233].

See #66208.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@github-actions

Copy link
Copy Markdown

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:

Props nofearinc.

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.


Props Bot commands

You can trigger Props Bot actions by commenting on this PR:

  • @propsbot add <username> to give props to a GitHub user. Requires write access.
  • @propsbot remove <username> to leave a user out of the props. Requires write access.
  • @propsbot refresh to refresh this list. Adding the props-bot label works too.

@github-actions

Copy link
Copy Markdown

Test using WordPress Playground

The 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

  • All changes will be lost when closing a tab with a Playground instance.
  • All changes will be lost when refreshing the page.
  • A fresh instance is created each time the link below is clicked.
  • Every time this pull request is updated, a new ZIP file containing all changes is created. If changes are not reflected in the Playground instance,
    it's possible that the most recent build failed, or has not completed. Check the list of workflow runs to be sure.

For more details about these limitations and more, check out the Limitations page in the WordPress Playground documentation.

Test this pull request with WordPress Playground.

@dmsnell dmsnell left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’ve left a more in-depth comment on the ticket

Some quick notes here: NOSCRIPT doesn’t nest, so there’s never a time we should be tracking depth. It latches instead, like TITLE or TEXTAREA — once we’ve entered into it, we stay in it until the first closing tag.

Please see my linked comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants