Security: Use aria-controls attribute with safe $( '#' + id ) selector pattern avoiding unsafe use of href#12579
Security: Use aria-controls attribute with safe $( '#' + id ) selector pattern avoiding unsafe use of href#12579SainathPoojary wants to merge 3 commits into
Conversation
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. |
…r pattern avoiding unsafe use of href
8a9ca8b to
63f3327
Compare
|
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 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. |
There was a problem hiding this comment.
Pull request overview
This PR hardens the admin contextual help tab click handler by avoiding passing a raw href value into jQuery’s $() constructor, reducing the risk of selector/HTML interpretation issues and aligning tab targeting with the aria-controls pattern used for other admin UI toggles.
Changes:
- Switches help-tab panel resolution from
$( link.attr( 'href' ) )to resolving the panel via the tab’saria-controlstarget ID. - Uses DOM lookup (
document.getElementById) as an input to jQuery to avoid jQuery parsing potentially unsafe strings.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (1)
src/js/_enqueues/admin/common.js:699
- The active tab CSS classes are updated before verifying that the target panel exists. If
aria-controlsis missing/invalid (or the panel is absent for any reason), the handler returns early leaving the previous panel visible while marking a different tab as active. Consider resolving the panel first, returning early if not found, and only then updating the tab/panel state.
$('.contextual-help-tabs .active').removeClass('active');
link.parent('li').addClass('active');
panel = $( document.getElementById( link.attr( 'aria-controls' ) || '' ) );
The contextual help tab click handler passed the raw
hrefattribute to jQuery's$(), which accepts both CSS selectors and raw HTML.Fix: Use
aria-controlswith the$( '#' + id )pattern, the same convention used elsewhere in the same file and across admin JS (privacy-tools.js,site-health.js).Trac ticket: #65574