choices/choices 9.0.1 is affected by polyfill.io

Created on 26 June 2024, 10 months ago

Problem/Motivation

Choices-JS includes a script hosted by polyfill.io

3rd Party Libraries and Supply Chains - PSA-2024-06-26

Steps to reproduce

The current require in composer.libraries.json is this:

        "choices": {
            "type": "package",
            "package": {
                "name": "choices/choices",
                "version": "9.0.1",
                "type": "drupal-library",
                "extra": {
                    "installer-name": "choices"
                },
                "dist": {
                    "url": "https://github.com/Choices-js/Choices/archive/refs/tags/v9.0.1.zip",
                    "type": "zip"
                },
                "license": "MIT"
            }
        },

If you open the Zip file and look at public/index.html, it includes a script hosted by polyfill.io.

Proposed resolution

There is an open pull request on the library. Assuming it gets merged and a new release is created, composer.libraries.json will need to be updated to include a newer version of the library that is no longer using polyfill.io.

Remaining tasks

User interface changes

API changes

Data model changes

📌 Task
Status

Active

Version

6.2

Component

Code

Created by

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

    It is used for security vulnerabilities which do not need a security advisory. For example, security issues in projects which do not have security advisory coverage, or forward-porting a change already disclosed in a security advisory. See Drupal’s security advisory policy for details. Be careful publicly disclosing security vulnerabilities! Use the “Report a security vulnerability” link in the project page’s sidebar. See how to report a security issue for details.

Sign in to follow issues

Merge Requests

Comments & Activities

  • Issue created by @solideogloria
  • 🇺🇸United States ransomweaver

    There is also a polyfill.io url in webform.libraries.yml, under js for the external library webform.choices

    This external library is a dependency of the webform.element.choices, which is conditionally attached in prepare() for the Select element plugin class Plugin/WebformElement/Select.php.

    // Enhance select element using select2, chosen, or choices.
        if (isset($element['#select2']) && $select2_exists) {
          $element['#attached']['library'][] = 'webform/webform.element.select2';
          $element['#attributes']['class'][] = 'js-webform-select2';
          $element['#attributes']['class'][] = 'webform-select2';
        }
        elseif (isset($element['#choices']) && $choices_exists) {
          $element['#attached']['library'][] = 'webform/webform.element.choices';
          $element['#attributes']['class'][] = 'js-webform-choices';
          $element['#attributes']['class'][] = 'webform-choices';
        }
        elseif (isset($element['#chosen']) && $chosen_exists) {
          $element['#attached']['library'][] = 'webform/webform.element.chosen';
          $element['#attributes']['class'][] = 'js-webform-chosen';
          $element['#attributes']['class'][] = 'webform-chosen';
        }

    BUT, It looks like the system will only offer one of the above, and the preferred option is Select2, so Choices is a fallback from that.

    // If select2, choices, or chosen is not available,
        // see if we can use the alternative.
        $select2_exists = $this->librariesManager->isIncluded('jquery.select2');
        $choices_exists = $this->librariesManager->isIncluded('choices');
        $chosen_exists = $this->librariesManager->isIncluded('jquery.chosen');
        $default_select = ($select2_exists ? '#select2' :
          ($choices_exists ? '#choices' :
            ($chosen_exists ? '#chosen' : NULL)
          )
        );

    So i think the default setup with Select2 available means this polyfill.io script isn't loaded, but it should be fixed in webform.libraries.yml, or just removed altogether since it's just one of two fallbacks from Select2.

  • I wouldn't remove it altogether. It's not a "fallback", it's a valid configuration option. I'm sure there's lots of sites using it.

  • 🇺🇸United States chartmann

    Thank you for the patch. I've emailed the maintainer of the Choices library to request action and offer to find a new maintainer. Hopefully the related PR, which has already been reviewed and approved, will soon be merged.

  • 🇺🇸United States luke.leber Pennsylvania

    Just chiming in here from a different perspective: our group has disallowed the use of Choices.js for years due to inherent accessibility issues.

    Given that...

    1. The software hasn't had a commit in ~3 years
    2. The software ships with a vulnerability
    3. The Select2 implementation ranked higher in [our] a11y testing

    Might it be an alternative to deprecate / disable its use in Webform by default? Shipping what is effectively abandonware doesn't seem sustainable.

  • 🇺🇸United States luke.leber Pennsylvania

    Savvy users can also utilize composer to further harden their applications:

    Example: Nuke the vulnerable file from orbit on `composer install`

        "scripts": {
            "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
            "post-install-cmd": [
              "rm docroot/libraries/choices/public/index.html"
            ]
        }
    

    🛡️

  • 🇺🇸United States wesleymusgrove

    Another thing you can do in composer.json is tell Composer not to even try downloading and installing the `choices/choices` library even if it is required by another package, like webform's `composer.libraries.json`. This is informing Composer that I already have a package that replaces the functionality of all versions of `choices/choices` (even though I don't have a replacement). So, Composer will not attempt to download and install `choices/choices`..

    "replace": {
        "choices/choices": "*"
    }
    
  • 🇦🇹Austria tgoeg

    Be aware that in case of choices 9.0.1 (contrary to the current master), which gets included by webform, the URL is *not* cdn.polyfill.io but <script src="https://polyfill.io/v3/polyfill.min.js?features=es5%2Ces6%2CArray.prototype.includes%2Cfetch%2CCustomEvent%2CElement.prototype.closest"></script> as mentioned by OP.
    If you use some kind of search & replace mechanism, it should rather be something along these lines:

    "scripts": {
        "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
        "post-install-cmd": [
          "sed -i 's#https://polyfill\.io/#https://polyfill-fastly\.io/#g' web/libraries/choices/public/index.html"
        ]
    },

    As already mentioned in [ 🐛 polyfill.io Library is no longer considered safe to use Fixed ], I'd very much favor that composer.libraries.json included this or some other form of patching the file without user interaction for the time being. Users should get a secure setup by just running composer update for their drupal installation, at least that's my way of thinking.
    We can update to a fixed version later on (or switch to a better maintained lib as mentioned above) anyway.

  • 🇬🇧United Kingdom malcomio

    I like the suggestion in #12 of removing the html file - it's not ideal to have random example library html pages available on your website, even if they don't have malicious scripts on them

  • 🇺🇸United States rraney

    Hello, I tried applying the patch as part of "drupal/webform" in composer.json.

    "drupal/webform": {
    "3457416: choices/choices 9.0.1 is affected by polyfill.io" : " https://www.drupal.org/files/issues/2024-06-27/3457416-choices-affected-... "
    }

    Should it be part of "drupal/core"? After I ran composer -v install, it gave me the error:

    Could not apply patch! Skipping. The error was: Cannot apply patch https://www.drupal.org/files/issues/2024-06-27/3457416-choices-affected-...

    In Patches.php line 331:

    [Exception]

    Cannot apply patch 3457416: choices/choices 9.0.1 is affected by polyfill.io ( https://www.drupal.org/files/issues/2024-06-27/3457416-choices-affected-... )!

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    The patch in #7 is a patch of choices.

  • 🇺🇸United States rraney

    Thanks - that appears to have worked.
    "choices/choices" : {}

  • Is there a way to patch it with composer?

    Also, RE: #14, be aware that it's not valid JSON, as the escape sequence isn't valid. This is corrected:

        "scripts": {
            "drupal-scaffold": "DrupalComposer\\DrupalScaffold\\Plugin::scaffold",
            "post-install-cmd": [
                "sed -i 's#https://polyfill\\.io/#https://polyfill-fastly\\.io/#g' web/libraries/choices/public/index.html"
            ]
        },
    
  • 🇺🇸United States luke.leber Pennsylvania

    Seeing as https://www.drupal.org/project/webform/issues/3460222#comment-15692042 📌 Consider deprecating Choices Closed: duplicate closed a related issue as a duplicate, I wanted to bring over the opinion that deprecating, discouraging the use of Choices, and ultimately removing it from Webform seems to be the most responsible path forward here.

    The library is abandonware.

  • 🇨🇦Canada Liam Morland Ontario, CA 🇨🇦

    I agree that is the best solution. Anything else would be temporary.

  • FYI, Select2 hasn't been updated for even longer than Choices. If we're going to consider ChoicesJS abandoned, the same should be said about Select2...

  • It looks like a new release is being worked on for Choices.

    https://github.com/Choices-js/Choices/pull/1166

  • A new maintainer (Xon) was added for Choices.

    I've been added as a maintainer, and plan todo v11.0.0 beta/rc release early next week and will be closing out issues as they are fixed.

    https://github.com/Choices-js/Choices/issues/1150#issuecomment-2270158764

  • 🇫🇷France raphaelbertrand Lauris

    a new version with the patch for pollyfill bug has been published
    https://github.com/Choices-js/Choices/releases

  • 🇺🇸United States rraney

    Can we simply do a composer update choices/choices?

  • Wouldn't it be better to update composer.json, so that we require a secure version? I think that's best.

  • It's also possible that the new version breaks some things due to backwards compatibility changes. I'm not sure.

  • 🇺🇸United States jrockowitz Brooklyn, NY
  • 🇺🇸United States jrockowitz Brooklyn, NY

    In Webform 6.3, we can upgrade libraries before the stable release.

  • 🇺🇸United States jrockowitz Brooklyn, NY

    Let's try updating the latest release of choices, which is 11.0.2.

    Below are my steps to test

    • Check that composer libraries work as expected
    • Check that drush webform:libraries:download works as expected
    • Check that CDN works as expected drush webform:libraries:remove
    • Confirm Choices is loading via CDN
    • Check that the Choices library is enabled ()
    • Check that the Choices select menu works as expected (/form/test-element-select)
  • 🇺🇸United States jrockowitz Brooklyn, NY
  • 🇺🇸United States jrockowitz Brooklyn, NY

    Marking this RTBC and assuming all the tests will pass.

  • Pipeline finished with Success
    4 months ago
    Total: 658s
    #361961
  • 🇺🇸United States jrockowitz Brooklyn, NY
  • Pipeline finished with Skipped
    4 months ago
    #362448
  • Pipeline finished with Skipped
    4 months ago
    #362449
    • jrockowitz committed df494d4d on 6.3.x
      Issue #3457416 by jrockowitz, nick dewitte, solideogloria, luke.leber,...
  • 🇺🇸United States jrockowitz Brooklyn, NY
    • jrockowitz committed df494d4d on 6.x
      Issue #3457416 by jrockowitz, nick dewitte, solideogloria, luke.leber,...
  • Automatically closed - issue fixed for 2 weeks with no activity.

  • Pipeline finished with Success
    3 months ago
    Total: 829s
    #402212
  • Pipeline finished with Canceled
    3 months ago
    Total: 110s
    #404896
  • Pipeline finished with Failed
    3 months ago
    Total: 869s
    #404899
  • Pipeline finished with Failed
    3 months ago
    Total: 1131s
    #404984
  • Pipeline finished with Failed
    3 months ago
    Total: 902s
    #405508
  • Pipeline finished with Failed
    3 months ago
    Total: 1023s
    #405542
  • Pipeline finished with Failed
    3 months ago
    Total: 898s
    #407821
  • Pipeline finished with Failed
    3 months ago
    Total: 873s
    #408302
  • Pipeline finished with Failed
    3 months ago
    Total: 1069s
    #408576
  • Pipeline finished with Success
    3 months ago
    Total: 889s
    #408593
  • Pipeline finished with Failed
    2 months ago
    Total: 1089s
    #409768
  • Pipeline finished with Failed
    2 months ago
    Total: 1261s
    #409787
  • Pipeline finished with Failed
    2 months ago
    Total: 1105s
    #409813
  • Pipeline finished with Failed
    2 months ago
    Total: 1204s
    #410343
  • Pipeline finished with Failed
    2 months ago
    Total: 1125s
    #410407
  • Pipeline finished with Skipped
    2 months ago
    #410421
Production build 0.71.5 2024