Problem/Motivation

Xss::filter() automatically does HTML escaping and protocol filtering on attributes. Protocols are filtered on everything except title, alt and data-

Attribute however, while it claims to make attributes sanitized and safe (issue to fix the claim at #2567741: Attribute/drupal_attributes() docs do not mention protocol filtering on URLs), does no such protocol filtering.

Steps to reproduce

Proposed resolution

Apply protocol stripping to everything except data attributes and a list of attributes necessary to not break existing tests.
The list could be expanded later in #2544110: XSS attribute filtering is inconsistent and strips valid attributes.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-2567743

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

catch created an issue. See original summary.

joelpittet’s picture

This sounds like a great idea. We already do Html::escape() on all values and attribute names. Though this may not be the best stategy. Twig actually has a strategy for attributes:
http://twig.sensiolabs.org/doc/filters/escape.html html_attr. I would suggest we use that to it's advantage as well as tag it on to AttributeValueBase. The name part can be left Html::escape() i'd assume.

If we want to strip dangerous protocols, it may be good to use Twig's html_attr strategy in place of Html::escape() inside UrlHelper::filterBadProtocol() at the very least I'd suspect, as well.

Xss::filter() needs the context of the tag I believe to do it's job effectively. Though we have context in Attribute to know the name of the attribute and effectively be smart about which attributes need something like.
UrlHelper::stripDangerousProtocols() eg: href,src,action,etc. And which ones don't eg. title

Hope that helps.

joelpittet’s picture

Oh and we should probably let twig apply the 'html_attr' strategy and not do it in Attribute as a step here. So the only domain thing this will deal with the dangerous protocol domain.

Just have to make our escapeFilter a bit smarter about SafeStringIntrface escaping strategy, which was inevitable.

pwolanin’s picture

@joelpittet - doing this all in twig would be a pretty dramatic code change.

Also, I don't think that actually meets the goal of this issue - it seems html_attr is just a much broader conversion of characters to entities:
http://stackoverflow.com/questions/12038048/difference-between-escapehtm...

In contrast, the suggestion here is to do protocol filtering. We can't escape those or they would break href, and src for example.

pwolanin’s picture

The tricky part of this issue is that I'm not sure we have the attribute name at the place we need it.

pwolanin’s picture

Status: Active » Needs review
StatusFileSize
new1.36 KB

I think it just needs to do this?

Probably need to write some new tests for it - let's see if existing ones fail.

effulgentsia’s picture

+++ b/core/lib/Drupal/Core/Template/AttributeString.php
@@ -30,7 +31,20 @@ class AttributeString extends AttributeValueBase {
-    return Html::escape($this->value);
...
+      return UrlHelper::filterBadProtocol($this->value);

Per #2565895-21: Add a new :placeholder to SafeMarkup::format() for URLs that handles bad protocols, I really don't think we should use filterBadProtocol() on something whose API is defined as needing to be in plain-text to begin with (which this is, since we currently do an unconditional Html::escape() on it). Instead, I think we should do Html::escape(UrlHelper::stripDangerousProtocols($this->value)); (without the Html::decodeEntities() that filterBadProtocol() does).

effulgentsia’s picture

Note there's a test in #2567795: Introduce a : placeholder which works like ! for now that includes a URL fragment on which Html::decodeEntities() would be incorrect to do, so perhaps we can add a similar test for that here as well.

Status: Needs review » Needs work

The last submitted patch, 6: 2567743-6.patch, failed testing.

The last submitted patch, 6: 2567743-6.patch, failed testing.

pwolanin’s picture

@effulgentsia - per catch, I was trying to mimic what Xss::filter does, which is to call UrlHelper::filterBadProtocol()

effulgentsia’s picture

The @param of Xss::filter() explicitly says that the parameter it receives is: "The string with raw HTML in it." So yes, that then needs to decode HTML entities, because what it was passed is expected to be HTML encoded. The input to Attribute, however, is explicitly plain-text, not HTML. Html::decodeEntities() is a function you call on HTML, not on plain text.

dawehner’s picture

StatusFileSize
new2.41 KB

This is, on purpose, a test only patch.

catch’s picture

Status: Needs work » Needs review

Running #13 past the bot.

Status: Needs review » Needs work

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

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new3.45 KB

And here's what I think we want. I had to whitelist 'callback' due to this amusing fail:

--- Expected
+++ Actual
@@ @@
 Array (
-    '#markup' => Drupal\Core\Render\SafeString Object (...)
+    '#markup' => '<p>#cache enabled, GET</p><dr...older>'
     '#attached' => Array (
         'drupalSettings' => Array (...)
         'placeholders' => Array (
-            '<drupal-render-placeholder callback=":callback" arguments="0=elk" token="175c060c"></drupal-render-placeholder>' => Array (...)
+            '<drupal-render-placeholder callback="Drupal\Tests\Core\Render\PlaceholdersTest::callback" arguments="0=elk" token="175c060c"></drupal-render-placeholder>' => Array (...)
         )
     )
     '#cache' => Array (...)
 )

Possibly we should use data-callback so that the AttributeString class doesn't know about placeholdering instead.

I get one fail from Daniel's phpunit test coverage, didn't look into that yet.

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

catch’s picture

StatusFileSize
new792 bytes
new3.46 KB

OK the one fail was a bad comparison in the test, see interdiff.

This should be green, but still a @todo for data-callback.

Status: Needs review » Needs work

The last submitted patch, 18: 2567743-18.patch, failed testing.

The last submitted patch, 16: 2567743-16.patch, failed testing.

The last submitted patch, 16: 2567743-16.patch, failed testing.

The last submitted patch, 18: 2567743-18.patch, failed testing.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Template/AttributeString.php
@@ -30,7 +31,15 @@ class AttributeString extends AttributeValueBase {
+    if (substr($this->name, 0, 5) === 'data-' || in_array($this->name, ['title', 'alt', 'callback'])) {
+      return Html::escape($this->value);

micro opt, I would swap the two conditions around.

+++ b/core/tests/Drupal/Tests/Core/Template/AttributeTest.php
@@ -448,7 +448,7 @@ public function providerTestAttributesWithUrls() {
-    $data['xss-in-style'] = [['style' => 'list-style-image: url(javascript:alert(0))'], ' style="alert(0)"'];
+    $data['xss-in-style'] = [['style' => 'list-style-image: url(javascript:alert(0))'], ' style="alert(0))"'];

The expected output I don't get. Do we really want two "))" closed?

catch’s picture

#1 So I'd swap them around and additionally try to make it an isset() check (maybe a class property with the whitelist as an assoc array), but wanted to keep the code the same as Xss::attributes() for now. I guess we could update Xss::attributes at the same time though so they still match.

#2 We only strip the protocols, we don't then correct the parentheses after the protocols were stripped.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new6.22 KB

Did that placeholder change.

Added 'value' to the whitelist which should fix the AJAX fails.

No interdiff because fail.

Status: Needs review » Needs work

The last submitted patch, 25: 2567743-25.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new6.23 KB
new724 bytes

Adding name via forum drag and drop tests.

dawehner’s picture

Status: Needs review » Needs work
+++ b/core/lib/Drupal/Core/Template/AttributeString.php
@@ -33,7 +33,7 @@ class AttributeString extends AttributeValueBase {
-    if (substr($this->name, 0, 5) === 'data-' || in_array($this->name, ['title', 'alt', 'value'])) {
+    if (substr($this->name, 0, 5) === 'data-' || in_array($this->name, ['title', 'alt', 'value', 'name'])) {
       return Html::escape($this->value);

Can we expand the test coverage to include an example for alt/value/name, just to be 100% sure?

catch’s picture

Yes I think we need that, although need a full whitelist first, see how #27 does with the bot.

We should probably also apply the same whitelisting to Xss::attributes() too and update the tests there.

The last submitted patch, 27: 2567743-27.patch, failed testing.

The last submitted patch, 25: 2567743-25.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new6.31 KB

Less fails.

Status: Needs review » Needs work

The last submitted patch, 32: 2567743-32.patch, failed testing.

dawehner’s picture

+++ b/core/lib/Drupal/Core/Template/AttributeString.php
@@ -30,7 +31,14 @@ class AttributeString extends AttributeValueBase {
+    // @see Xss::attributes()
+    if (substr($this->name, 0, 5) === 'data-' || in_array($this->name, ['title', 'alt', 'value', 'name', 'property', 'typeof', 'rel', 'about', 'content', 'datatype', 'datatype_callback'])) {
+      return Html::escape($this->value);

Given how many we already have I'm curious whether this needs to be configurable, much like allowed protocols ...

catch’s picture

StatusFileSize
new908 bytes
new6.32 KB

One more. And yes I think we need to think about extensibility here.

Leaving in the responsive image fail because nfi.

pwolanin’s picture

I would rather see us using an isset() instead of much slower in_array()

xjm’s picture

What is the correct way for someone to legitimately create attributes for something that are considered dangerous? I would have assumed that using Attribute() was the API for this.

The last submitted patch, 27: 2567743-27.patch, failed testing.

wim leers’s picture

Status: Needs work » Needs review
catch’s picture

@xjm I think that's what we're running into with:

fail: [Other] Line 283 of core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php:
Raw "data:image/gif;base64,R0lGODlhAQABAIABAP///wAAACH5BAEKAAEALAAAAAABAAEAAAICTAEAOw==" found

Don't have a good idea for that yet.

@pwolanin as above yes I think we should do this, but also I think we need to factor this whitelist logic out, make it extensible, and apply it to Xss::attributes() (or decide why it behaves differently here if not).

wim leers’s picture

StatusFileSize
new5.13 KB
new3.78 KB
+++ b/core/lib/Drupal/Core/Render/Renderer.php
@@ -706,7 +706,7 @@ protected function createPlaceholder(array $element) {
-    $attributes['callback'] = $placeholder_render_array['#lazy_builder'][0];
+    $attributes['data-callback'] = $placeholder_render_array['#lazy_builder'][0];
     $attributes['arguments'] = UrlHelper::buildQuery($placeholder_render_array['#lazy_builder'][1]);
     $attributes['token'] = hash('crc32b', serialize($placeholder_render_array));
     $placeholder_markup = SafeMarkup::format('<drupal-render-placeholder@attributes></drupal-render-placeholder>', ['@attributes' => $attributes]);

This could (and IMO should) just not use Attribute, and do a SafeString::create(). This is internal in the Renderer anyway.

We should do that, because this is what the preceding comment says:

    // Generate placeholder markup. Note that the only requirement is that this
    // is unique markup that isn't easily guessable. The #lazy_builder callback
    // and its arguments are put in the placeholder markup solely to simplify
    // debugging.

Prefixing it with data- makes it less developer-friendly.

dawehner’s picture

@Wim Leers
Do you mind doing that conversion in its own issue?

The last submitted patch, 35: 2567743-33.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 41: 2567743-40.patch, failed testing.

joelpittet’s picture

I'd like to add a few test assertions to this if it's ok with you all?

  1. I'd like to close this and move the tests here #2531824: Attribute class to check safe strings before escaping (has tests)
  2. And make two more tests from this comment #2545056-11: Attribute class does not sanitize for "javascript:alert('XSS')" and close that issue too as a duplicate of this

Ça joue?

catch’s picture

For the responsive image data: issue and #2531824: Attribute class to check safe strings before escaping (has tests) I think we should consider adding AttributeSafeStringInterface.

This will allow us to mark a string not only as safe, but safe for use in an attribute (a string that's safe for an attribute should be safe in an HTML fragment, but not vice versa).

Then when you have either an already escaped attribute or a valid use case for something like data: you can use it.

But it avoids the case where something is run through Filter:xss(), then assigned to SafeString, then put into an attribute - which if we allowed for that to avoid double-escaping would be its own XSS vector.

More test coverage here would be great, I got buried by RDF up until now.

joelpittet’s picture

Status: Needs work » Needs review
StatusFileSize
new5.43 KB
new970 bytes

Adding the mailto: and escape bypassing examples from #2545056-11: Attribute class does not sanitize for "javascript:alert('XSS')"

joelpittet’s picture

StatusFileSize
new967 bytes
new5.46 KB

Wrong assertion it should just strip the protocol not the value.

The last submitted patch, 47: add_protocol_filtering-2567743-47.patch, failed testing.

The last submitted patch, 32: 2567743-32.patch, failed testing.

Status: Needs review » Needs work

The last submitted patch, 48: add_protocol_filtering-2567743-48.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new11.54 KB
new3.84 KB

Added AttributeSafeStringInterface and AttributeSafeString per #46. Docs need lots of work.

I'm not sure we want to use this approach, but it shows there's a way to get the responsive image tests green, while being able to do a more specific check than just SafeStringInterface here.

interdiff is a bit messed up, but has everything except the new files, and includes joelpittet's changes.

Status: Needs review » Needs work

The last submitted patch, 52: 2567743-52.patch, failed testing.

The last submitted patch, 35: 2567743-33.patch, failed testing.

The last submitted patch, 41: 2567743-40.patch, failed testing.

The last submitted patch, 48: add_protocol_filtering-2567743-48.patch, failed testing.

catch’s picture

Status: Needs work » Needs review
StatusFileSize
new20.95 KB
new1.41 KB

Fixes the theme functions test.

Not sure what's up with the views grid style yet, guessing it's style attribute somewhere.

catch’s picture

StatusFileSize
new20.95 KB

Err wrong patch.

The last submitted patch, 47: add_protocol_filtering-2567743-47.patch, failed testing.

catch’s picture

StatusFileSize
new10.29 KB

Twice :(

The last submitted patch, 57: 2560863-2-61.patch, failed testing.

The last submitted patch, 58: 2560863-2-61.patch, failed testing.

dawehner’s picture

  1. +++ b/core/lib/Drupal/Core/Template/AttributeString.php
    @@ -30,7 +32,17 @@ class AttributeString extends AttributeValueBase {
    +    // Whitelist 'title', 'alt', and all data- attributes.
    

    Needs some doc updates

  2. +++ b/core/lib/Drupal/Core/Template/AttributeString.php
    @@ -30,7 +32,17 @@ class AttributeString extends AttributeValueBase {
    +    else if (substr($this->name, 0, 5) === 'data-' || in_array($this->name, ['title', 'alt', 'value', 'name', 'property', 'typeof', 'rel', 'about', 'content', 'datatype', 'datatype_callback', 'datetime', 'mailto', 'media', 'sizes'])) {
    

    Wait, so does that actually mean that Xss::attributes() is wrong at the moment?
    Ah yeah, see #2544110: XSS attribute filtering is inconsistent and strips valid attributes

Status: Needs review » Needs work

The last submitted patch, 60: 2567743-58.patch, failed testing.

mpdonadio’s picture

#63-2, one early idea on #2544110: XSS attribute filtering is inconsistent and strips valid attributes was to add setter/getters for its internal lists. If we do that, then Attributes could get the whitelist that way.

The last submitted patch, 52: 2567743-52.patch, failed testing.

The last submitted patch, 57: 2560863-2-61.patch, failed testing.

The last submitted patch, 58: 2560863-2-61.patch, failed testing.

The last submitted patch, 60: 2567743-58.patch, failed testing.

wim leers’s picture

#52 lost the changes I made in #41.

But @dawehner asked in #42 to do that in a separate issue. So here we go: #2569371: Update Renderer::createPlaceholder() to not use Attribute and SafeMarkup::format(). That's an easy patch to get in.

mpdonadio’s picture

Issue tags: +Needs reroll

This needs a reroll, but I am not sure which hunk for the callback attribute name is correct here.

wim leers’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
StatusFileSize
new9.39 KB

#71: just callback, #2569371: Update Renderer::createPlaceholder() to not use Attribute and SafeMarkup::format() removed the need here to prefix it with data-.

Done.

(This is a straight reroll with just the conflict with #2569371: Update Renderer::createPlaceholder() to not use Attribute and SafeMarkup::format() resolved, making this patch slightly simpler.)

Status: Needs review » Needs work

The last submitted patch, 72: 2567743-72.patch, failed testing.

The last submitted patch, 72: 2567743-72.patch, failed testing.

catch’s picture

I've opened #2569485: Add AttributeSafeStringInterface and UriAttributeSafeStringInterface for the interface changes from here.

That may help with other issues in the queue (including critical SafeMarkup ones), so I think we should postpone this on that issue. I haven't moved the interface changes over there yet although all I did was copy and paste SafeString and SafeStringInterface and change a few lines, so we can either hack those bits out of the patch here or start from scratch there.

While this issue would be postponed, the attribute list is also being dealt with in #2544110: XSS attribute filtering is inconsistent and strips valid attributes and that's the only remaining tricky thing in this issue. So if we focus efforts there too, then this patch ends up being a few lines in AttributeString and maybe some conversions - which is what I was hoping it would be when I opened it anyway...

catch’s picture

Status: Needs work » Postponed
mgifford’s picture

wim leers’s picture

Title: Add protocol filtering to Attribute » [PP-1] Add protocol filtering to Attribute

This is blocked on #2569485: Add AttributeSafeStringInterface and UriAttributeSafeStringInterface, which was in turn blocked on #2576533: Rename SafeStringInterface to MarkupInterface and move related classes. The latter has landed, so we're still blocked on one issue here.

catch’s picture

Status: Postponed » Needs work

I think #2576533: Rename SafeStringInterface to MarkupInterface and move related classes covered what we needed for this issue (in a different way to the initial patches here but a better way), so unpostponing.

catch’s picture

Title: [PP-1] Add protocol filtering to Attribute » Add protocol filtering to Attribute

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.

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

Drupal 8.2.6 was released on February 1, 2017 and is the final full bugfix release for the Drupal 8.2.x series. Drupal 8.2.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.3.0 on April 5, 2017. (Drupal 8.3.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.3.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.3.6 was released on August 2, 2017 and is the final full bugfix release for the Drupal 8.3.x series. Drupal 8.3.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.4.0 on October 4, 2017. (Drupal 8.4.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.4.x-dev branch from now on, and new development or disruptive changes should 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.4.x-dev » 8.5.x-dev

Drupal 8.4.4 was released on January 3, 2018 and is the final full bugfix release for the Drupal 8.4.x series. Drupal 8.4.x will not receive any further development aside from critical and security fixes. Sites should prepare to update to 8.5.0 on March 7, 2018. (Drupal 8.5.0-alpha1 is available for testing.)

Bug reports should be targeted against the 8.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 8.5.6 was released on August 1, 2018 and is the final bugfix release for the Drupal 8.5.x series. Drupal 8.5.x will not receive any further development aside from security fixes. Sites should prepare to update to 8.6.0 on September 5, 2018. (Drupal 8.6.0-rc1 is available for testing.)

Bug reports should be targeted against the 8.6.x-dev branch from now on, and new development or disruptive changes should 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.6.x-dev » 8.8.x-dev

Drupal 8.6.x will not receive any further development aside from security fixes. Bug reports should be targeted against the 8.8.x-dev branch from now on, and new development or disruptive changes should be targeted against the 8.9.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: 8.8.x-dev » 8.9.x-dev

Drupal 8.8.7 was released on June 3, 2020 and is the final full bugfix release for the Drupal 8.8.x series. Drupal 8.8.x will not receive any further development aside from security fixes. Sites should prepare to update to Drupal 8.9.0 or Drupal 9.0.0 for ongoing support.

Bug reports should be targeted against the 8.9.x-dev branch from now on, and new development or disruptive changes should 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: 8.9.x-dev » 9.2.x-dev

Drupal 8 is end-of-life as of November 17, 2021. There will not be further changes made to Drupal 8. Bugfixes are now made to the 9.3.x and higher branches only. For more information see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

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

Drupal 9.3.15 was released on June 1st, 2022 and is the final full bugfix release for the Drupal 9.3.x series. Drupal 9.3.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.4.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal 9.4.9 was released on December 7, 2022 and is the final full bugfix release for the Drupal 9.4.x series. Drupal 9.4.x will not receive any further development aside from security fixes. Drupal 9 bug reports should be targeted for the 9.5.x-dev branch from now on, and new development or disruptive changes should 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.

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

Drupal core is moving towards using a “main” branch. As an interim step, a new 11.x branch has been opened, as Drupal.org infrastructure cannot currently fully support a branch named main. New developments and disruptive changes should now be targeted for the 11.x branch. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

prudloff made their first commit to this issue’s fork.

prudloff’s picture

Status: Needs work » Needs review

I agree this is important and would help prevent some XSS vulnerabilities.
I rebased the latest patch and adjusted some things to make tests pass.

However, I see two potential problems with the solution:

  • It would require maintaining a long list of attributes in which protocols should not be filtered (see #2544110: XSS attribute filtering is inconsistent and strips valid attributes).
    This is an existing problem with the XSS filter, but filtering attributes everywhere makes it more visible.
  • Using MarkupInterface to explicitly bypass the filter seems a bit weird semantically, because an attribute value is not really markup.
    (When this was proposed the interface was still called SafeStringInterface.)

Also filtering the style attribute would break too many places in core where it is used (because every CSS rule contains the : character) and I don't think it is the job stripDangerousProtocols() to remove dangerous URLs in CSS.
Removing dangerous CSS could be implemented later in #3264121: Allow inline style to certain html elements despite of "Limit allowed HTML tags and correct faulty HTML" filter turned on .

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review

I rebased the MR.

joelpittet’s picture

It would be so nice if the tests didn’t change. Are the test changes really necessary? Adding more expected assertions is fine, but changing the provider values reduces confidence in the change.

Thanks for picking this up, it's been sitting for a while.

prudloff’s picture

The tests have to change (well at least the expected values) because attribute values that were not sanitized before now have their protocol removed.
However, I adjusted the MR a bit to limit the changes in tests.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest 11.x.

xjm’s picture

Title: Add protocol filtering to Attribute » Add protocol filtering to the core Attribute component

Retitling because I keep forgetting what this is.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest 11.x.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest 11.x.

xjm’s picture

smustgrave’s picture

So this seems to be toughing a number of different modules and components. Should this be broken up?

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest 11.x.

So this seems to be toughing a number of different modules and components. Should this be broken up?

Most of the changes are because these parts of the code add an attribute with a dangerous protocol and don't expect it to be filtered, so now they need to wrap the attribute in a Markup object to explicitly prevent it from being filtered.
I guess theses changes could be committed separately but they won't do anything or make a lot of sense on their own.

smustgrave’s picture

Ok, may take a while to get to then just an fyi

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review
dcam’s picture

Status: Needs review » Needs work
Issue tags: +Needs issue summary update

I left a bunch of comments on the MR. The issue summary needs to be updated too because the proposed resolution only refers to the title, alt, and data-* attributes. The MR excludes a lot more than that from protocol filtering. Please be certain to mention the other issue from which the current list of excluded attributes was taken.

prudloff’s picture

Issue summary: View changes
Status: Needs work » Needs review
Issue tags: -Needs issue summary update
Related issues: +#2544110: XSS attribute filtering is inconsistent and strips valid attributes

I applied the suggestions.

prudloff’s picture

Issue summary: View changes
dcam’s picture

Status: Needs review » Needs work

Unfortunately, the new function short description doesn't comply with the documentation standards. I left a suggestion for it, along with a couple of other things I noticed while reading through the MR again. I'm sorry I didn't notice those before.

Version: 11.x-dev » main

Drupal core is now using the main branch as the primary development branch. New developments and disruptive changes should now be targeted to the main branch.

Read more in the announcement.

prudloff’s picture

Status: Needs work » Needs review

I applied the suggestions.

needs-review-queue-bot’s picture

Status: Needs review » Needs work
StatusFileSize
new549 bytes

The Needs Review Queue Bot tested this issue. It fails the Drupal core commit checks. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review

I merged the latest main.