Archived link

The polyfill.js is a popular open source library to support older browsers. 100K+ sites embed it using the cdn.polyfill.io domain. Notable users are JSTOR, Intuit and World Economic Forum. However, in February this year, a Chinese company bought the domain and the Github account. Since then, this domain was caught injecting malware on mobile devices via any site that embeds cdn.polyfill.io. Any complaints were quickly removed (archive here) from the Github repository.

  • dan@upvote.au
    link
    fedilink
    English
    arrow-up
    100
    ·
    5 months ago

    Reposting my comment from Github:

    A good reminder to be extremely careful loading scripts from a third-party CDN unless you trust the owner 100% (and even then, ownership can change over time, as shown here). You’re essentially giving the maintainer of that CDN full control of your site. Ideally, never do it, as it’s just begging for a supply chain attack. If you need polyfills for older browsers, host the JS yourself. :)

    If you really must load scripts from a third-party, use subresource integrity so that the browser refuses to load it if the hash changes. A broken site is better than a hacked one.


    And on the value of dynamic polyfills (which is what this service provides):

    Often it’s sufficient to just have two variants of your JS bundles, for example “very old browsers” (all the polyfills required by the oldest browser versions your product supports) and “somewhat new browsers” (just polyfills required for browsers released in the last year or so), which you can do with browserslist and caniuse-lite data.

    • Echo Dot@feddit.uk
      link
      fedilink
      English
      arrow-up
      5
      ·
      4 months ago

      Yeah I used to be guilty of this. Although in slight defense of myself I never used to use random sites like that I always used to pull everything from Google CDN since I can’t see that changing hands.

      They may very well shut it down without warning, but they’re probably not going to sell it to anyone.

      • dan@upvote.au
        link
        fedilink
        English
        arrow-up
        3
        ·
        edit-2
        4 months ago

        Yeah, it really depends on how much you trust the vendor.

        Google? Say what you want about the company, but they’ll never intentionally serve malware.

        Random company with no track record where we don’t even know who is maintaining the code? Much less trustworthy. The polyfill . io repo is currently owned by a Github user called “polyfillpolyfill” with no identifying information.

        Third-party CDNs make less sense these days though. A lot of hosting services have a CDN of some sort. Most sites have some sort of build process, and you usually bundle all your JS and CSS (both your code and third-party code, often as separate bundles) as part of that.

      • dan@upvote.au
        link
        fedilink
        English
        arrow-up
        15
        ·
        edit-2
        4 months ago

        You’d be surprised how much code people blindly reuse without even looking at it, especially in JavaScript. A bunch of it is from projects owned by random individuals. The JS standard library is ridiculously small, so nearly all JS apps import third-party code of some sort. One JS framework can pull in hundreds of third-party modules.

        It’s much less of an issue with languages like C# and even PHP, where the first-party libraries are often sufficient for building a small or mid-sized app.

        • BURN@lemmy.world
          link
          fedilink
          English
          arrow-up
          5
          ·
          4 months ago

          JS and Python are both extremely bad for this. I’ve been working with data scientists and it’s hell trying to tell them that no, they can’t just install whatever libraries they want