Skip to content

Administration: Avoid parsing tab and hash values as HTML in admin scripts - #14061

Closed
sirreal wants to merge 3 commits into
WordPress:trunkfrom
sirreal:fix/admin-selector-hardening
Closed

sirreal wants to merge 3 commits into
WordPress:trunkfrom
sirreal:fix/admin-selector-hardening

Conversation

@sirreal

@sirreal sirreal commented Oct 7, 2026 •

Copy link
Copy Markdown
Member

Several scripts pass an intended selector variable to $(). $() can be used as a selector or to create elements from HTML. Avoiding $() in favor of $().find() ensures selectors are not incorrectly used as HTML.

This is a hardening follow-up to r64133.

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

Use of AI Tools

AI assistance: Yes
Tools: Claude Code
Models: Claude Opus 5.5
Used for: Applying the change, checking the touched files for similar selections, running lint, and drafting this description.


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.

@github-actions

github-actions Bot commented Oct 7, 2026

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.

@sirreal
sirreal marked this pull request as ready for review October 7, 2026 09:23
@github-actions

github-actions Bot commented Oct 7, 2026 •

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. You can also manually ask me to refresh this list by adding the props-bot label.

Core Committers: Use this line as a base for the props when committing in SVN:

Props jonsurrell, westonruter.

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

@sirreal
sirreal force-pushed the fix/admin-selector-hardening branch 2 times, most recently from 9b4d4ba to aebd94d Compare October 7, 2026 09:41
…ripts.

Several admin scripts pass a link `href` or the URL hash to `$()`, which parses strings that look like HTML as markup. Select through `$( document ).find()` where the value is the whole selector, and escape the value with `$.escapeSelector()` where it is part of a larger selector, so each value is only ever treated as a selector.

This follows the same change made to the contextual help tabs in common.js in [64133].
`wp.updates.addAdminNotice()`, `wp.media.transition()` and the attachment details frame's `focusNavButton()` pass a caller-supplied selector to `$()`, which parses a value that looks like HTML as markup. Select through `$( document ).find()` so the value is only ever treated as a selector.

This follows [64133] and the admin script changes in the same series.
@sirreal
sirreal force-pushed the fix/admin-selector-hardening branch from aebd94d to 2034440 Compare October 7, 2026 09:42
Comment thread src/js/_enqueues/admin/site-health.js Resolved
Co-authored-by: Weston Ruter <westonruter@gmail.com>
@sirreal
sirreal requested a review from westonruter October 16, 2026 12:29
@sirreal

sirreal commented Oct 19, 2026

Copy link
Copy Markdown
Member Author

r64241 removed one case that was hardened here.

wporg-sync pushed a commit that referenced this pull request Oct 19, 2026
`$( string )` either selects elements or creates elements from HTML, and the string decides which. Several scripts passed values that are not string literals to `$()`. These scripts now use `$( document ).find()`, which only selects.

Developed in: #14061

Follow-up to r64133.

Props jonsurrell, westonruter.
Fixes #66265.


git-svn-id: https://develop.svn.wordpress.org/trunk@64498 602fd350-edb4-49c9-b593-d223f7449a82
@github-actions

Copy link
Copy Markdown

A commit was made that fixes the Trac ticket referenced in the description of this pull request.

SVN changeset: 64498
GitHub commit: 87e86a9

This PR will be closed, but please confirm the accuracy of this and reopen if there is more work to be done.

@github-actions github-actions Bot closed this Oct 19, 2026
@sirreal
sirreal deleted the fix/admin-selector-hardening branch October 19, 2026 06:49
wporg-sync pushed a commit to WordPress/WordPress that referenced this pull request Oct 19, 2026
`$( string )` either selects elements or creates elements from HTML, and the string decides which. Several scripts passed values that are not string literals to `$()`. These scripts now use `$( document ).find()`, which only selects.

Developed in: WordPress/wordpress-develop#14061

Follow-up to r64133.

Props jonsurrell, westonruter.
Fixes #66265.

Built from https://develop.svn.wordpress.org/trunk@64498


git-svn-id: http://core.svn.wordpress.org/trunk@63648 1a063a9b-81f0-0310-95a4-ce76da25c4cd
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