Problem/Motivation

Xss::filterAdmin() is currently stripping out harmless elements (ie. the picture & source html elements that are part of the Core module Responsive Image).
$adminTags sets the elements that are allowed and would need to be updated.

This bug was first found at https://www.drupal.org/node/2687479. Views is stripping out the picture & source elements when responsive images fields are being rewritten. The patch there will be uploaded here to start / demo a fix that would need to be reviewed.

Steps to reproduce

This is for testing responsive image support (picture):

  1. Install Drupal with Umami profile
  2. Create new View: Content of type Article, Create a page, Save and edit
  3. Switch Format from Content to Fields
  4. Add a Media Image field then
    1. Choose Formatter = Rendered entity and View mode = Responsive 3x2
    2. Hide from display
  5. Add a Global: Custom text field then
    1. Include the previous Media field as a twig variable
  6. Save and look at the page

Result: See original image for the articles
Expected: See responsive image for the articles

Proposed resolution

Review/update $adminTags to include any html elements that should be allowed.

Remaining tasks

  • Verify steps to reproduce
  • Review what HTML elements to add
  • New HTML elements to be reviewed for XSS vulnerabilities
  • Provide a MR with new elements and associated tests

HTML elements to add:

User interface changes

None

API changes

None

Data model changes

None

CommentFileSizeAuthor
#108 xss-responsive-image-tags.patch420 bytesburcu.sogut@drupart.com.tr
#97 2776667-97-mr-4231.patch5.52 KBwebflo
#91 2776667-91-10.4.patch1.97 KBduaelfr
#91 2776667-91-11.x.patch10.81 KBduaelfr
#90 2776667-90-10.4.patch1.96 KBduaelfr
#90 2776667-90-11.x.patch10.71 KBduaelfr
#88 2776667-88-10.4.patch1.95 KBduaelfr
#87 2776667-87.patch2.18 KBduaelfr
#85 2776667-85.patch1.84 KBduaelfr
#80 core-update-adminTags-variable-for-new-html-elements-to-be-whitelisted-2776667-80.patch2.96 KBahmad abbad
#68 interdiff_60-61.txt6.62 KBprauat
#68 2776667-61.patch7.91 KBprauat
#61 interdiff_59-60.txt558 bytessourabhjain
#61 2776667-60.patch4.21 KBsourabhjain
#59 2776667-59.patch3.53 KB_utsavsharma
#59 interdiff_58-59.txt479 bytes_utsavsharma
#58 interdiff_55-58.txt1.68 KBmurrow
#58 review-update-adminTags-variable-2776667-58.patch3.53 KBmurrow
#55 review-update-adminTags-variable-2776667-55.patch3.52 KBadambraun
#54 review-update-adminTags-variable-2776667-51.patch5.16 KBadambraun
#50 review-update-adminTags-variable-2776667-50.patch2.95 KBsadysierralta
#49 review-update-adminTags-variable-2776667-9.5.9-reroll.patch2.93 KBklemendev
#41 review-update-adminTags-variable-2776667-41.patch2.92 KBmmatsoo
#27 interdiff-2776667-22-27.txt1.66 KBcrzdev
#27 review-update-adminTags-variable-2776667-27.patch2.8 KBcrzdev
#22 interdiff-2776667-16-22.txt1.12 KBeugene bocharov
#22 review-update-adminTags-variable-2776667-22-TEST-ONLY-FAIL.patch899 byteseugene bocharov
#22 review-update-adminTags-variable-2776667-22.patch2.79 KBeugene bocharov
#21 review-update-adminTags-variable-2776667-16.patch2.51 KBlobodakyrylo
#15 review-update-adminTags-variable-2776667-15.patch2.5 KBbaysaa
#15 review-update-adminTags-variable-2776667-15-tests-only.patch639 bytesbaysaa
#12 review-update-adminTags-variable-2776667-12.patch1.87 KBpostovan dumitru
#11 2776667_11.patch1.66 KBnavneet0693
#2 2776667-review-update-adminTags-variable-1.patch1.67 KBnmillin

Issue fork drupal-2776667

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

nmillin created an issue. See original summary.

nmillin’s picture

nmillin’s picture

I found https://www.drupal.org/node/732992 which is where the $adminTags array came from (same HTML elements). Adding as a related issue since it is an old issue and was hard for me to find.

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

Drupal 8.2.0-beta1 was released on August 3, 2016, which means new developments and disruptive changes should now 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.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.

luigif’s picture

Protocol filtering should also be disabled for the media attribute to avoid complex breakpoints to be mangled.
Currently protocol filtering is disabled for other non-uri attibutes such as "title, alt, rel, property".
It can be easily disabled for media by adding it to the $skip_protocol_filtering array in the attributes function:

$skip_protocol_filtering = substr($attribute_name, 0, 5) === 'data-' || in_array($attribute_name, array(
              'title',
              'alt',
              'rel',
              'property',
              'media',
            ));

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.

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.

navneet0693’s picture

StatusFileSize
new1.66 KB
postovan dumitru’s picture

Hi,

Seems like we also need to add 'media' to $skip_protocol_filtering, otherwise half of the media attribute value is removed.

alex malkov’s picture

@postovan-dumitru Many thanks!
The patch in #12 works for me (d8.7.4).

gresko8’s picture

How about video tag? Is there a reason It shouldn't be whitelisted?

baysaa’s picture

Here's a small test change to illustrate the media attribute issue. The patch in #12 fixes the issue so re-uploading with test updates too.

The allowed admin tags test only checks for tags that are not allowed, so there's no test to update for whitelisted tags.

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.

lobodakyrylo’s picture

StatusFileSize
new2.51 KB

Added video tag support

eugene bocharov’s picture

Added img sizes attribute to the $skip_protocol_filtering list.

Status: Needs review » Needs work
eugene bocharov’s picture

Status: Needs work » Needs review

Test only patch failed as expected. Reverting status to Needs review

volker23’s picture

Applied the patch #22 on drupal 9.2.6 successfully. We had the problem that a views rewrite of an image field caused the loss of the picture element. Now fixed! Thanks!

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.

crzdev’s picture

#22 Seems working as expected, just adding new patch adding noscript tag to list, is something provided by core too & can be found in quite common related scenarios like using blazy contrib module with no js fallback, @see Drupal\Core\Render\Element\HtmlTag::preRenderHtmlTag().
Think there is no need to add extra test, please review/any suggestion is accepted. Thanks!

ahmad abbad’s picture

Patch #27 working for me
Core: 9.3.5

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.

kristen pol’s picture

Requesting issue credit be added here for those who worked on the duplicate issue:

#2687479: Responsive Image not working in rewritten Views field/area due to XSS filtering

kristen pol’s picture

Thanks for this issue. Tagging for some cleanup.

1. Issue summary needs steps to reproduce

2. Issue summary needs to be updated with noscript inclusion

@CRZDEV Why don't you think there should be a test added for noscript?

kristen pol’s picture

Issue summary: View changes

Updated issue summary to use similar steps to reproduce from the duplicate issue: #2687479: Responsive Image not working in rewritten Views field/area due to XSS filtering

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.

klemendev’s picture

I hope this issue fix will be backported to D9 and not only cover D10

klemendev’s picture

I can confirm patch #27 fixing the problem on our websites. Is the issue ready for RTBC?

klemendev’s picture

Status: Needs review » Reviewed & tested by the community
larowlan’s picture

Status: Reviewed & tested by the community » Needs review

#31 still needs to be answered

crzdev’s picture

Hi @Kristen Pol, @larowlan feel free to add any possible scenario to test coverage if you think is needed. I don't know any noscript vulnerabilities that could cause, taking into account that will be used for Xss::filterAdmin() not for default Xss::filter method. Thanks in advance!

larowlan’s picture

Category: Bug report » Task
Status: Needs review » Needs work

Yeah, if you want it to stick around, you'll need a test to make sure there's no regressions.

I also see the video element has been added, there's no mention of that in the issue summary either.

Also, I'm not sure this is a bug, its a feature request or perhaps a task.

carlygerard’s picture

Since this seems to be an overall review of the $adminTags variable and allowed elements in general, I'd like to propose the <button> element be considered as allowed markup in addition to the <video>, <source>, and <picture> tags.

There are tickets like https://www.drupal.org/project/drupal/issues/3217767 that have expressed a want for it, and use cases in our Drupal instance where the <button> element gets stripped away from patterns because it's not an allowed tag--causing developers to create hacky or less accessible workarounds when a native <button> should be used.

I'm not sure if that suggestion needs a new ticket since this covers "new html5 elements," but figured I should throw it out there anyway so it's at least known and can be addressed.

mmatsoo’s picture

Re-rolling patch 22 for 9.5.0

marcoka’s picture

Thank you very much. I use views fields to rewrite stuff a LOT!
Searched for hours on why the browser does always only use the fallback option. And indeed your media querys will be butchered and then they will not work.
#41 works and fixes the problem as sizes and media are excluded from filtering.

prauat’s picture

CarlyGerard
She/Her/Hers
CreditAttribution: CarlyGerard at Western Washington University commented 2 months ago

Since this seems to be an overall review of the $adminTags variable and allowed elements in general, I'd like to propose the element be considered as allowed markup in addition to the , , and
tags.

There are tickets like https://www.drupal.org/project/drupal/issues/3217767 that have expressed a want for it, and use cases in our Drupal instance where the element gets stripped away from patterns because it's not an allowed tag--causing developers to create hacky or less accessible workarounds when a native should be used.

I'm not sure if that suggestion needs a new ticket since this covers "new html5 elements," but figured I should throw it out there anyway so it's at least known and can be addressed.

<button> tag should be definitely added to list of allowed tags, moreover I don't see any specific reason why it's not allowed. It's allowed by full html text format. Lack of <button> tag produces strange situation where placing simple button on a page needs tricky hacks. Since all content produced by Global: Custom Text gets filtered button is removed from field content even if it was previously allowed by text format, but if instead of using fields content is displayed by views it's allowed.

Now let's assume that <button> is not allowed and try to change it to <a> for example in content type body managed by CKEditor5 so from:

<button class="rounded-pill btn-rounded" type="button">
   Label
   <span><i class="fas fa-arrow-right"> </i></span>
</button>

we change to that:

<a class="rounded-pill btn-rounded">
   Label
   <span><i class="fas fa-arrow-right"> </i></span>
</a>

But one of CKEditor5 filters is correcting HTML to take care of user publishing content and instead of wanted markup we get:

    <a class="rounded-pill btn-rounded" type="button">Label&nbsp;</a>

This time CKEditor5 filtered <span> and <i> changing it to &nbsp; but if we use <button> CKEditor5 lefts syntax intact.

Why placing simple <button> on site when using fields is almost impossible when using fields?

Same applies to <svg> so both button and svg should be added to allowed tags.

jigarius’s picture

IMHO, if we use a new line for each tag in this $adminTags variable declaration, it'll be easier to understand the diffs in the future.

klemendev’s picture

I think #27 fixes the original bug/issue for this issue. Maybe this one should be merged and a follow-up issue opened where those topics are addressed?

klemendev’s picture

Side question, does #27 apply cleanly to 10.0 too?

klemendev’s picture

Priority: Normal » Major

The last Drupal update 9.5.9 breaks patch #41 / it no longer applies (due to changes in file in https://www.drupal.org/project/drupal/issues/2692451).

It would be helpful to get this into the core soon to prevent such issues in the future.

Also to my comment #45, I think further work could be done in another issue.

Webbeh’s picture

Priority: Major » Normal

A reroll patch request does not constitute a priority update to Major.

klemendev’s picture

Here is the re-roll for 9.5.9

@Webbeh my reasoning was not the need for re-roll, but the fact that this issue prevents websites from using responsive images in rewrites in views, which quite reduces the possibilities one has with responsive images and views in the D9/D10 core.

Looking at #2692451, it was merged without additional changes that seem to be holding back this issue.

sadysierralta’s picture

Not sure why noscript tag was removed from the admintag list in #41 after being applied in #27, just added it again.

Version: 10.1.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, which currently accepts only minor-version allowed changes. For more information, see the Drupal core minor version schedule and the Allowed changes during the Drupal core release cycle.

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

adambraun’s picture

Here is the reroll for 10.1

adambraun’s picture

The patch in #54 accidentally reverted some changes. Rerolled for 10.1 again

adambraun’s picture

The patch in #50 still applies to 10.1. My issue with it not applying was due to another composer conflict. Merge request !4231 currently reflects the patch from #50.

murrow’s picture

No comments from those making patches about #40 and #43 and the recommendation to support the button element? Is this issue correctly named or is it just a responsive image issue? Button is valid and ought to be included.

murrow’s picture

Adding button element.

_utsavsharma’s picture

StatusFileSize
new479 bytes
new3.53 KB

Tried to fix failures in #58.

murrow’s picture

Drupal\Component\Utility\Xss::needsRemoval() requires an array. But, the patch has removed string[]:

   /**
    * Whether this element needs to be removed altogether.
    *
-   * @param string[] $html_tags
+   * @param $html_tags
    *   The list of HTML tags.
-   * @param string $elem
+   * @param $elem
    *   The name of the HTML element.
    *
    * @return bool
    *   TRUE if this element needs to be removed.
    */
-  protected static function needsRemoval(array $html_tags, $elem) {
+  protected static function needsRemoval($html_tags, $elem) {
     return !isset($html_tags[strtolower($elem)]);
   }

That is breaking "core/modules/editor/src/EditorXssFilter/Standard.php", which wants string[].

sourabhjain’s picture

Status: Needs work » Needs review
StatusFileSize
new4.21 KB
new558 bytes

Fixed the PHPCS issue showing in #59. Please review.

smustgrave’s picture

Status: Needs review » Needs work

Was previously tagged for IS update which believe still needs to happen.

Also existing patch appears to be removing the typehints previously there, that doesn't seem correct.

murrow’s picture

Adding IS details for "button" proposed by @CarlyGerard and @prauat.

prauat’s picture

@sourabhjain, @murrow are you taking care of this patch or should I do it as I'm in need of that functionality?

murrow’s picture

Button is in #58, @prauat

prauat’s picture

Issue summary: View changes

@murrow yes, but I also see there type hinting removed which @smustgrave mentioned. Why did this type has been removed?

-   * @param string[] $html_tags
+   * @param $html_tags
    *   The list of HTML tags.
-   * @param string $elem
+   * @param $elem
murrow’s picture

That was not in my patch @prauat. I mentioned the issue in #60, but the fix that was applied afterwards just exacerbated the problem. IMO, the type hints need to be returned.

prauat’s picture

Status: Needs work » Needs review
StatusFileSize
new7.91 KB
new6.62 KB

- Fix for most of code style warnings and errors
- Revert of type hinting
- Add type hinting for primitive type string for following methods:

core/lib/Drupal/Component/Utility/Xss.php

-  protected static function needsRemoval(array $html_tags, $elem) {
+  protected static function needsRemoval(array $html_tags, string $elem) {

core/modules/editor/src/EditorXssFilter/Standard.php

-  protected static function needsRemoval(array $html_tags, $elem) {
+  protected static function needsRemoval(array $html_tags, string $elem) {

I don't see a reason why $elem shouldn't be typed here

smustgrave’s picture

Issue summary: View changes
Status: Needs review » Needs work

#32 update the issue summary and steps were from a closed duplicate but haven't seen anyone confirm those yet. If that could happen please. Added to the tasks in the IS.

The proposed solution talks about reviewing/updating the adminTags. But it should specifically say what tags are being added. Already part of the remaining tasks. So leaving the needs issue summary tag for that one.

Also #68 seems to have some comment changes, breaking them into new lines that seem out of scope of this issue.

murrow’s picture

@smustgrave, are you saying that the note (now removed) stating that the button tag had been added to adminTags was in the wrong place, incorrectly specified or shouldn't have been there at all?

rex.barkdoll’s picture

Adding a nudge and support for being added for accessibility reasons.

Off topic / separate question, but would there ever be the possibility for site administrators to control the list of allowed tags via a screen in the Configuration? Like a page with checkboxes that might default to a set (safe) list and include links to some sort of security vulnerabilities page for each HTML element about what the risks are?

Thank you everyone for your hard work on this! :)

murrow’s picture

Issue summary: View changes

Adding a list to cover "Review what HTML elements to add" task.

klemendev’s picture

Can confirm #49 still applies to D10.2 and fixes the original issue of this ticket before it branched to fixing more than just that:

Xss::filterAdmin() is currently stripping out the picture & source html elements that are part of the Core module Responsive Image. $adminTags sets the elements that are whitelisted and would need to be updated.

I hope this issue will be merged into the core soon as without this fix, responsive images can't be used in the views rewrite filter at all.

klemendev’s picture

I think this issue should be reduced to the original case of responsive images not working in rewritten fields and a new ticket should be open for other HTML tags needed.

klemendev’s picture

As this issue is still stalling, does anyone have a patch for 10.3 at hand, otherwise I can try to prepare one later?

rgpublic’s picture

TBH I never understood why Xss is not a service. Almost everything else in Drupal can at least be overridden/extended by a module. I find it a bit "un-Drupalish" that we say Xss::filterAdmin and not \Drupal::service("xss")->filterAdmin(...). This way, other modules like response_image could at least easily extend the list of allowed tags.

klemendev’s picture

#49 still applies cleanly in 10.3

janpongos’s picture

another tag that gets strips out that's good to be whitelisted is "drupal-media" when using core's ckeditor5.

gtr18’s picture

#49 woks as expected
This is very helpful to ensure we render the picture and source tag from the responsive image in a custom text field in views.

ahmad abbad’s picture

Re-roll for patch #49 to add noscript tag.

alex malkov’s picture

@ahmad-abbad Many thanks! The patch in #80 works for me (d10.4.4).

j_s’s picture

Patch in #80 worked well for me. I needed video and source tags and this patch enabled them. Thanks!

murrow’s picture

Is the button tag going in? See #40 and #43 above.

duaelfr’s picture

Title: Review/update $adminTags variable for new html elements to be whitelisted » Review/update $adminTags variable for new html elements to be allowed
Issue summary: View changes
Issue tags: -Needs issue summary update, -Needs steps to reproduce
duaelfr’s picture

Status: Needs work » Needs review
StatusFileSize
new1.84 KB

Rerolled and cleaned MR.
Added <button> to the allowed list.
Patch attached for composer (11.x).

rgpublic’s picture

If video is added, audio should probably be added as well...

duaelfr’s picture

Issue summary: View changes
StatusFileSize
new2.18 KB

Fixed missing attributes lost in the reroll.
Added <audio> tag as well. (thanks #86 for that suggestion)
Again, attached patch for composer.

duaelfr’s picture

Here is a simplified patch for Drupal 10.4 for live projects.

klemendev’s picture

Glad to see tracting here again! :)

duaelfr’s picture

StatusFileSize
new10.71 KB
new1.96 KB

Added <template> to allowed tags in the MR (from #3443362: Xss::filterAdmin() to allow "template" elements).
Patches for composer.

duaelfr’s picture

StatusFileSize
new10.81 KB
new1.97 KB

Added to allowed tags in the MR (from #3348218: <data> element stripped by $adminTags).
Patches for composer.

duaelfr’s picture

Issue summary: View changes
duaelfr’s picture

Issue summary: View changes

Updated IS with references for every tag added to the list.

smustgrave’s picture

Status: Needs review » Needs work

Think we need coverage for all the tags being added

duaelfr’s picture

Issue tags: +Needs tests

@smustgrave I didn't manage to find existing coverage for other allowed tags. Would you help me find it so I can extend it, please?

prudloff’s picture

If we allow noscript, we should probably add a test for this kind of attack: https://www.acunetix.com/blog/web-security-zone/mutation-xss-in-google-s...

webflo’s picture

StatusFileSize
new5.52 KB

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

just_like_good_vibes’s picture

Hello, i suggest the svg tag should be allowed too.

prudloff’s picture

The svg tag would need to allow a lot of other tags to be useful (circle, rect, etc) and there is a lot of ways to use SVG for XSS attacks so adding SVG support would massively increase the scope of this issue.

apotek’s picture

Patch in #97 applies cleanly to 11.2.5 and works well.

prudloff’s picture

Instead of adding arbitrary tags to the list, wouldn't it make more sense to add a way to alter the list?
This way modules could allow tag needed for their specific use case.

(WordPress has a hook that does this: https://developer.wordpress.org/reference/hooks/wp_kses_allowed_html/)

klemendev’s picture

That is a good idea with a configurable list.

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.

4kant’s picture

Patch for D 10 in #91 applies cleanly to 10.6.5 and works well.
No videos in views without this patch!

nitinkumar_7’s picture

Tested the #91 patch and it works as expected for me. The issue is resolved and I did not find any problems during testing but I agree with @prudloff. An alter hook would be a more flexible and maintainable solution than continually adding tags to the hardcoded list. Modules could then extend the allowed tags for their own use cases while core maintains a secure default set.

so a module could do:

function mymodule_xss_admin_tags_alter(array &$tags) {
$tags[] = 'picture';
$tags[] = 'source';
}

apparatchik’s picture

Couldn't this functionality be tied to the very similar text format configurations, where basic html, restricted html, etc. already have configurable filters for allowed tags, etc?

burcu.sogut@drupart.com.tr’s picture

StatusFileSize
new420 bytes

Attaching a small patch that extends the admin tag/attribute allowlist in Xss.php to include the picture and source elements plus the media, sizes and srcset attributes, so responsive image markup survives filterAdmin()-based filtering (e.g. Views token rewriting). I see MR !4231 already covers a much broader set of elements/attributes here, so this is really just a confirmation of the same underlying need from a narrower, single-purpose patch -- feel free to close this out in favor of the MR if it already includes these.

Patch attached: xss-responsive-image-tags.patch

apotek’s picture

My $0.02

I am not entirely sold on the idea that an XSS filter class (which is there for security purposes) should be easily extensible.

At the very least, it seems like a question that would merit some discussion.

I note also that the original issue that was reported here has been fixed with a perfectly adequate patch for quite some time, and the fix appears to be being held up by turning this from a fix to a feature request.

I think if we really want an extensible XSS filter, then a feature request/discussion should be opened for that.

In the meantime, let's not hold up good work that actually fixes the reported issue with a feature discussion, or by expanding the original issue into an ever expanding list of missing elements. What do you guys think?

rgpublic’s picture

@apotek: Just my thoughts on this... I'm personally not a huge fan of this "educational" concept to be honest. Drupal is usally known for being fully extensible and flexible and I think that's also what its success and appeal to a large part come from. Developer can do all kind of bad stuff - right now and nothing in Drupal actually keeps them from doing it. Introducing SQL injections, taking an unvalidated query argument and building a file path from it, etc etc. - you name it. I think if XSS was a service and someone wrote a Drupal module, overrode that service - I assume they know what they're doing and at the very least what XSS is about. There's a myriad of other ways people could shoot themselves in the foot if they absolutely want to. But the opposite could also be true: That person might have a very valid reason if they wanted to XSS like a new upcoming HTML tag for example. Considering how long this issue takes to be actually resolved, I don't think it's completely unreasonable to have the idea that there might be absolutely valid reasons to extend the XSS via a module. It's just another part of Drupal like any other that should be extensible and replaceable IMHO. You might do weird unsafe shenanigans with it - or you might do completely sensible stuff. It's ultimately up to the developer. Right now, people will need to resort to overriding other services that call the XSS filter. Not much more complicated considering you could use AI right now. But will produce much more convoluted code and might actually make the security landscape worse.

What I totally agree with, though, is that we should separate this. The one thing are the extensions to the XSS proposed here in this issue. Another thing is turning XSS into a service if that is something people can agree on for the future. Good idea!

klemendev’s picture

I agree this should be separated into another ticket for a feature request and the original fix should be merged as this issue has been requiring patching core for quite a while now