Background information
This was originally reported as a private security issue, but has been approved for handling in the public queue by the Drupal Security Team.
Problem/Motivation
block.admin.js passes the value of the data-element attribute to $() without sanitizing it:
const $input = $(once('block-filter-text', 'input.block-filter-text'));
const $table = $($input.attr('data-element'));
This is dangerous because $() accepts either a selector or raw HTML.
Steps to reproduce
This could be exploited if an attacker can insert this payload on /admin/structure/block :
<input class="block-filter-text" data-element="<img src=x onerror=alert()>">
Proposed resolution
Using document.querySelector() would probably be safer.
Remaining tasks
User interface changes
Introduced terminology
API changes
Data model changes
Release notes snippet
Comments
Comment #3
prudloff commentedComment #4
smustgrave commentedRan the test locally since can't in the pipeline right now
Change itself seems pretty minimal and makes sense to run through all so LGTM.
No additional feedback.
Comment #5
godotislateOne comment on the MR. I think we can move the test assertions to
Drupal\Tests\block\FunctionalJavascript\BlockFilterTest::testBlockFilterand save one test bootstrap.Comment #7
brandonlira commentedAddressed the review feedback by moving the XSS coverage into BlockFilterTest::testBlockFilter() and removing the separate BlockXssTest. The test still uses the block_test fixture and asserts that window.XSS remains undefined after loading the block admin page.
Please let me know if any further changes are needed.
Comment #8
danielvezaLooks good, did a fresh check after the last changes and I think this is good to go.
My first thoughts was to wonder if we still needed this to be jQuery, but changing that would be a bigger change than we should introduce in this issue.
Comment #13
longwaveCommitted and pushed 6d0b12247f4 to main and 15e811374ff to 11.x and 7587cc077b6 to 11.4.x. Thanks!
I also thought this might not backport cleanly, but turns out it does, so backported to 10.6.x as a security improvement.