This was originally reported by alexpott to the Drupal Security Team, but is being made public since there is no actual vulnerability and it can be treated as a public bug.

There is no vulnerability since "on" attribute names are renamed which renders them harmless.

Problem/Motivation

Drupal\Component\Utility\Xss::filter has the following behaviour:

HEAD

BEFORE: <IMG SRC= onmouseover="alert('xxs')"
AFTER: <IMG nmouseover="alert(&#039;xxs&#039;)">

With patch

BEFORE: <IMG SRC= onmouseover="alert('xxs')"
AFTER: <IMG>

You can see the bug by running the test code below using "drush scr xss.php.txt"

<?php

$strings = [
  '<IMG SRC= onmouseover="alert(\'xxs\')"',
  '<IMG onmouseover="alert(\'xxs\')"',
  '<img src="http://example.com/foo.jpg" title="Example: title" alt="Example: alt">',
];

foreach ($strings as $original) {
  $string = filter_xss($original, array('img'));
  print "BEFORE: $original\nAFTER: $string\n\n";
}

Proposed resolution

Fix the logic so malformed attributes are stripped

Remaining tasks

review patch, backport.

User interface changes

n/a

API changes

n/a

Data model changes

n/a

Comments

pwolanin created an issue. See original summary.

pwolanin’s picture

Status: Needs review » Needs work

The last submitted patch, sdo-155203-D8-8.patch, failed testing.

Status: Needs work » Needs review

mr.baileys queued sdo-155203-D8-8.patch for re-testing.

Version: 8.0.x-dev » 8.1.x-dev

Drupal 8.0.6 was released on April 6 and is the final bugfix release for the Drupal 8.0.x series. Drupal 8.0.x will not receive any further development aside from security fixes. Drupal 8.1.0-rc1 is now available and sites should prepare to update to 8.1.0.

Bug reports should be targeted against the 8.1.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.2.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.1.x-dev » 8.2.x-dev

Drupal 8.1.9 was released on September 7 and is the final bugfix release for the Drupal 8.1.x series. Drupal 8.1.x will not receive any further development aside from security fixes. Drupal 8.2.0-rc1 is now available and sites should prepare to upgrade to 8.2.0.

Bug reports should be targeted against the 8.2.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.3.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

pwolanin’s picture

Issue summary: View changes
alexpott’s picture

Issue tags: +Triaged core major

Discussed with @catch, @xjm, @effulgentsia, @cilefen, and @Cottser. We agreed that this is a major bug because it is unexpected behaviour from a key part of the way that Drupal secures itself against XSS attack.

alexpott’s picture

Creditting myself since I reported it to security.drupal.org and I think provided the patch and test.

pwolanin’s picture

@alexpott - yes, looks like you wrote the original fix, and I added some tests and moved it over here.

pwolanin’s picture

Version: 8.2.x-dev » 8.3.x-dev
StatusFileSize
new3.56 KB

Here's a re-roll for 8.3.x

Version: 8.3.x-dev » 8.4.x-dev

Drupal 8.3.0-alpha1 will be released the week of January 30, 2017, which means new developments and disruptive changes should now be targeted against the 8.4.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Munavijayalakshmi’s picture

StatusFileSize
new3.52 KB

Rerolled the patch.

Status: Needs review » Needs work

The last submitted patch, 13: 2552837-13.patch, failed testing.

Version: 8.4.x-dev » 8.5.x-dev

Drupal 8.4.0-alpha1 will be released the week of July 31, 2017, which means new developments and disruptive changes should now be targeted against the 8.5.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.5.x-dev » 8.6.x-dev

Drupal 8.5.0-alpha1 will be released the week of January 17, 2018, which means new developments and disruptive changes should now be targeted against the 8.6.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

jhodgdon’s picture

See also #2635632-20: Drupal XSS filtering cuts valid attributes, make it configurable / use a blacklist, where I have tried to summarize all the mangled attribute issues and ask whether we should solve them together or apart.

alexpott’s picture

Status: Needs work » Needs review

@jhodgdon this is a straight-up bug fix which sets it apart from those other issues.

I think the test fail in #13 is unrelated setting back to needs review.

Version: 8.6.x-dev » 8.7.x-dev

Drupal 8.6.0-alpha1 will be released the week of July 16, 2018, which means new developments and disruptive changes should now be targeted against the 8.7.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.7.x-dev » 8.8.x-dev

Drupal 8.7.0-alpha1 will be released the week of March 11, 2019, which means new developments and disruptive changes should now be targeted against the 8.8.x-dev branch. For more information see the Drupal 8 minor version schedule and the Allowed changes during the Drupal 8 release cycle.

Version: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.0-alpha1 will be released the week of October 14th, 2019, which means new developments and disruptive changes should now be targeted against the 8.9.x-dev branch. (Any changes to 8.9.x will also be committed to 9.0.x in preparation for Drupal 9’s release, but some changes like significant feature additions will be deferred to 9.1.x.). For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 8.9.x-dev » 9.1.x-dev

Drupal 8.9.0-beta1 was released on March 20, 2020. 8.9.x is the final, long-term support (LTS) minor release of Drupal 8, which means new developments and disruptive changes should now be targeted against the 9.1.x-dev branch. For more information see the Drupal 8 and 9 minor version schedule and the Allowed changes during the Drupal 8 and 9 release cycles.

Version: 9.1.x-dev » 9.2.x-dev

Drupal 9.1.0-alpha1 will be released the week of October 19, 2020, which means new developments and disruptive changes should now be targeted for the 9.2.x-dev branch. For more information see the Drupal 9 minor version schedule and the Allowed changes during the Drupal 9 release cycle.

Version: 9.2.x-dev » 9.3.x-dev

Drupal 9.2.0-alpha1 will be released the week of May 3, 2021, which means new developments and disruptive changes should now be targeted for the 9.3.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.3.x-dev » 9.4.x-dev

Drupal 9.3.0-rc1 was released on November 26, 2021, which means new developments and disruptive changes should now be targeted for the 9.4.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

Version: 9.4.x-dev » 9.5.x-dev

Drupal 9.4.0-alpha1 was released on May 6, 2022, which means new developments and disruptive changes should now be targeted for the 9.5.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

amber himes matz’s picture

Triaged as part of Bug Smash. Sounds like this is a separate issue from the other XSS filter issues (some of which will be merged), so keeping open.

The patch has a test, but I think it also needs a failing test to prove the bug?

I think this will probably need both a 8.9 and 9.5 patch.

At the very least, it needs a re-roll to 9.5.x and a code review.

smustgrave’s picture

Issue tags: -Needs reroll, -Needs tests
StatusFileSize
new932 bytes
new2.84 KB

Hiding the previous patches.

Rerolled #13 after verifying the test fails without the fix.

Only thing I didn't include was the break in the case2. Thought all switch cases needed to have a break?

Uploading a tests-only patch

The last submitted patch, 28: 2552837-28-tests-only.patch, failed testing. View results

Status: Needs review » Needs work

The last submitted patch, 28: 2552837-28.patch, failed testing. View results

smustgrave’s picture

Status: Needs work » Needs review
StatusFileSize
new1.79 KB
new743 bytes
new3.72 KB

Fixed the test case. It was invalid now with this fix.

The last submitted patch, 31: 2552837-31-tests-only.patch, failed testing. View results

smustgrave’s picture

Trying to keep to the front of the issue queue. Don’t want to get lost in the shuffle

cilefen’s picture

Issue tags: +Needs security review

I think this needs extra security scrutiny.

lendude’s picture

+++ b/core/lib/Drupal/Component/Utility/Xss.php
--- a/core/modules/editor/tests/src/Unit/EditorXssFilter/StandardTest.php
+++ b/core/modules/editor/tests/src/Unit/EditorXssFilter/StandardTest.php

+++ b/core/modules/editor/tests/src/Unit/EditorXssFilter/StandardTest.php
@@ -104,7 +104,7 @@ public function providerTestFilterXss() {
-    $data[] = ['<IMG SRC= onmouseover="alert(\'xxs\')">', '<IMG nmouseover="alert(&#039;xxs&#039;)">'];
+    $data[] = ['<IMG SRC= onmouseover="alert(\'xxs\')">', '<IMG>'];

index db5ee1d7b9..5cc176f7bd 100644
--- a/core/tests/Drupal/Tests/Component/Utility/XssTest.php

This change seems to make us lose the test coverage for the onmouseover => nmouseover functionality (quick scan didn't reveal any other coverage for this, but could very well have missed something).
Are we ok with that? (my first guess would be 'no', but didn't look to deeply into what is doing this renaming)

smustgrave’s picture

So this is removing the onmouseover from the src of the image.

There's so many tickets trying to update this filter but they have each a unique case. So really they should happen in an order

Version: 9.5.x-dev » 10.1.x-dev

Drupal 9.5.0-beta2 and Drupal 10.0.0-beta2 were released on September 29, 2022, which means new developments and disruptive changes should now be targeted for the 10.1.x-dev branch. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

lendude’s picture

Status: Needs review » Reviewed & tested by the community

@smustgrave ah yes, I misread, it is indeed good that the old test case is removed

Not sure how to get 'Needs security review' to happen, so moving to RTBC, which might help get that done if indeed needed.

alexpott’s picture

I wrote this patch sometime back in 2015 :) and it has had tests ever since. I think we should trust our test coverage of the Xss class and we can see that this results in better and more correct HTML. I've reviewed the code again. I've not looked at it for years and I still believe that this is the correct fix.

The removal of the break; is neither here nor there. It's the last statement in a switch - the break does nothing.

  • catch committed 0217ee0a on 10.0.x
    Issue #2552837 by smustgrave, pwolanin, alexpott: XSS::filter and...

  • catch committed 4421948a on 10.1.x
    Issue #2552837 by smustgrave, pwolanin, alexpott: XSS::filter and...

  • catch committed c18e6eda on 9.5.x
    Issue #2552837 by smustgrave, pwolanin, alexpott: XSS::filter and...
catch’s picture

Version: 10.1.x-dev » 9.5.x-dev
Status: Reviewed & tested by the community » Fixed
Issue tags: -Needs backport to D7, -Needs security review

The change here looks good - just completely removing the attribute instead of leaving an invalid one.
edit: via @alexpott for correctness: "no longer creates invalid attributes and now filters following attribute/values the same as if src had had a value"

Untagging for security review because we already have extensive test coverage and this only affects the one test case that was validating the bug (bug better than XSS though of course).

Committed/pushed to 10.1.x, cherry-picked to 10.0.x and 9.5.x, thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.