Review/update $adminTags variable for new html elements to be whitelisted

Created on 1 August 2016, almost 8 years ago
Updated 26 February 2024, 3 months ago

Problem/Motivation

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.

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
5. Choose Formatter = Rendered entity and View mode = Responsive 3x2
6. Look at the page
7. Result: See original image for the articles
8. Expected: See responsive image for the articles

Proposed resolution

Review/update $adminTags to include picture & source. It would probably be good to review $adminTags to see if there are any other html elements that should be whitelisted at the same time.

Remaining tasks

  • Verify steps to reproduce
  • Review what HTML elements to add
  • New HTML elements to be reviewed for XSS vulnerabilities

HTML elements to add:

  • button

User interface changes

none

API changes

none

Data model changes

none

๐Ÿ“Œ Task
Status

Needs work

Version

11.0 ๐Ÿ”ฅ

Component
Otherย  โ†’

Last updated about 12 hours ago

Created by

๐Ÿ‡บ๐Ÿ‡ธUnited States nmillin

Live updates comments and jobs are added and updated live.
  • Security improvements

    It makes Drupal less vulnerable to abuse or misuse. Note, this is the preferred tag, though the Security tag has a large body of issues tagged to it. Do NOT publicly disclose security vulnerabilities; contact the security team instead. Anyone (whether security team or not) can apply this tag to security improvements that do not directly present a vulnerability e.g. hardening an API to add filtering to reduce a common mistake in contributed modules.

  • Needs issue summary update

    Issue summaries save everyone time if they are kept up-to-date. See Update issue summary task instructions.

Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

  • ๐Ÿ‡ต๐Ÿ‡ฑPoland prauat

    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   but if we use <button> CKEditor5 lefts syntax intact.

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

  • ๐Ÿ‡จ๐Ÿ‡ฆCanada jigarius Montrรฉal

    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.

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

    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?

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

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

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

    The last Drupal update 9.5.9 breaks this patch / it no longer applies.

    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.

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States Webbeh Georgia, USA

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

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

    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.

  • last update about 1 year ago
    30,327 pass
  • last update about 1 year ago
    28,520 pass
  • ๐Ÿ‡ช๐Ÿ‡ธSpain SadySierralta

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

  • last update about 1 year ago
    28,520 pass
  • last update about 1 year ago
    30,336 pass
  • First commit to issue fork.
  • last update 12 months ago
    Custom Commands Failed
  • @adambraun opened merge request.
  • Here is the reroll for 10.1

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

  • last update 12 months ago
    Custom Commands Failed
  • last update 12 months ago
    Custom Commands Failed
  • last update 11 months ago
    Custom Commands Failed
  • last update 11 months ago
    29,567 pass
  • 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.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

    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.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

    Adding button element.

  • last update 10 months ago
    Custom Commands Failed
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia _utsavsharma

    Tried to fix failures in #58.

  • last update 9 months ago
    Custom Commands Failed
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

    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[].

  • Status changed to Needs review 9 months ago
  • last update 9 months ago
    30,058 pass
  • ๐Ÿ‡ฎ๐Ÿ‡ณIndia sourabhjain

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

  • last update 9 months ago
    29,471 pass
  • Status changed to Needs work 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    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.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

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

  • ๐Ÿ‡ต๐Ÿ‡ฑPoland prauat

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

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

    Button is in #58, @prauat

  • ๐Ÿ‡ต๐Ÿ‡ฑPoland prauat

    @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
    
  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

    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.

  • Status changed to Needs review 9 months ago
  • last update 9 months ago
    30,060 pass
  • ๐Ÿ‡ต๐Ÿ‡ฑPoland prauat

    - 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

  • Status changed to Needs work 9 months ago
  • ๐Ÿ‡บ๐Ÿ‡ธUnited States smustgrave

    #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.

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

    @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?

  • ๐Ÿ‡บ๐Ÿ‡ธUnited States rex.barkdoll

    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! :)

  • ๐Ÿ‡ณ๐Ÿ‡ฟNew Zealand murrow

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

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

    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.

  • ๐Ÿ‡ธ๐Ÿ‡ฎSlovenia KlemenDEV

    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.

Production build 0.69.0 2024