• [object Object]@lemmy.ca
    link
    fedilink
    English
    arrow-up
    176
    arrow-down
    5
    ·
    2 days ago

    Can we stop using npm now?

    I swear to god the number of attacks like this or spawned from other attacks like this is fucking stupid. I’ve gender seen anything like it.

    • i_am_not_a_robot@discuss.tchncs.de
      link
      fedilink
      English
      arrow-up
      65
      ·
      2 days ago

      This problem has nothing to do with NPM. Checkmarx was compromised last month, and during that compromise there were malicious VS Code extensions published to Visual Studio Code Marketplace. A Bitwarden developer says that somebody ran one of those malicious extensions, and GitHub API keys were stolen which were used in publishing the malicious CLI package.

      It’s probably better that it happened on NPM. If the CLI were only downloadable from the Bitwarden website, it would have likely taken longer for somebody to notice something was wrong.

      • realitaetsverlust@piefed.zip
        link
        fedilink
        English
        arrow-up
        27
        arrow-down
        3
        ·
        2 days ago

        Yes, but NPM has been had countless security problems, this isn’t a new problem. Even tho this instance is not a problem of NPM itself, it still has been proven as one of the most unreliable and insecure package managers out there.

        • wizardbeard@lemmy.dbzer0.com
          link
          fedilink
          English
          arrow-up
          26
          arrow-down
          1
          ·
          2 days ago

          I’m not a particular fan of npm, but you’ll probably see this kind of thing with any package manager of similar size. More a matter of what’s the most attractive target than the package tech itself.

          • tjoa@feddit.org
            link
            fedilink
            English
            arrow-up
            5
            arrow-down
            1
            ·
            1 day ago

            But why does NPM enable post install scripts by default? Why is there no way to define a minimum release age for dependency versions? It’s just poor design choices.

    • anyhow2503@lemmy.world
      link
      fedilink
      English
      arrow-up
      12
      ·
      1 day ago

      Npm probably has the biggest attack surface and many of the libraries hosted there are in extremely widespread use. They’ve taken some steps to mitigate these supply chain attacks, but as we’ve seen with more recent examples, it’s unrealistic to think they can be prevented completely. Most of these attacks use stolen developer credentials, which invalidates almost all potential security measures on the registry side and the best you can hope for is catching a malicious package quickly. To be clear: I think the JS ecosystem is uniquely positioned to be the prime target of supply chain attacks and while that doesn’t excuse the slow implementation of security measures from the npm team, the people arguing that other package managers and registries aren’t vulnerable to this have to be huffing fumes.

      • [object Object]@lemmy.ca
        link
        fedilink
        English
        arrow-up
        7
        ·
        1 day ago

        That’s fair, I won’t pretend pypi/pip and running uvx is much safer than npx.

        But why hasn’t JavaScript established a defacto stdlib to replace ask the left pads and is even type packages?

        I’ve taken a near zero dependency policy on my personal projects regardless, and now I run most code in containers to sandbox it.

        • Tekhne@sh.itjust.works
          link
          fedilink
          English
          arrow-up
          2
          ·
          20 hours ago

          If you’re asking why there isn’t one shipped with JS, the answer is because JS is built for the web, and the “don’t break the web” rule makes changing things in JS hard, as well as browser devs pushing back hard on anything that increases install size.

          If you’re asking why as a community, we haven’t agreed on a single package to be a stdlib - lodash.

        • anyhow2503@lemmy.world
          link
          fedilink
          English
          arrow-up
          3
          ·
          1 day ago

          But why hasn’t JavaScript established a defacto stdlib to replace ask the left pads and is even type packages?

          I’m guessing things were working out pretty alright, even with the insane amount of dependencies per project. The awareness and the increasing frequency of supply chain attacks is relatively recent for npm. But who knows, maybe the tech giants in control of the web standards are happy to keep using their own vendored registries.

    • LurkingLuddite@piefed.social
      link
      fedilink
      English
      arrow-up
      40
      ·
      2 days ago

      Genuine question. How is NPM more vulnerable than other repos? Haven’t similar supply chain attacks succeeded at least as well as this one through GitHub itself and even Linux package repos?

      • Serinus@lemmy.world
        link
        fedilink
        English
        arrow-up
        42
        ·
        2 days ago

        Larger standard libraries do a lot. It’s a lot harder to sneak vulnerabilities into the basic C# or Java or C++ libraries than it is to add a vulnerability to something one dude maintains in the javascript ecosystem.

        And since javascript libraries tend to be so small and focused, it’s become standard practice for even other libraries to pull in as many of those as they want.

        And it stacks. Your libraries pull in other libraries which can pull in their own libraries. I had a project recently where I had maybe a dozen direct dependencies and they ended up pulling in 1,311 total libraries, largely all maintained by different people.

        In a more sane ecosystem like C#, all the basics like string manipulation, email, or logging have libraries provided by Microsoft that have oversight when they’re changed. There can be better, third-party libraries for these things (log4net is pretty great), but they have to compete with their reputation and value over the standard library, which tends to be a high bar. And libraries made on top of that system are generally pulling all those same, certified standard libraries. So you pull in 3 libraries and only one of those pulls in another third party single library. And you end up with 4 total third party libraries.

        Javascript just doesn’t really have a certified standard library.

        (This certified standard library doesn’t have to be proprietary. Microsoft has made C# open source, and Linus Torvalds with the Linux Kernel Organization holds ultimate responsibility for the Linux kernel.)

        • vithigar@lemmy.ca
          link
          fedilink
          English
          arrow-up
          12
          ·
          2 days ago

          I will almost always choose .NET as my development platform when greenfielding a project for exactly this reason. It’s an incredibly robust standard library that virtually guarantees I won’t need to pull in a litany of additional utility libraries, and I can also expect that what libraries I do choose to bring in are highly unlikely to drag along a ridiculous parade of dependencies.

            • boonhet@sopuli.xyz
              link
              fedilink
              English
              arrow-up
              3
              ·
              1 day ago

              Probably more worth than it was 15 years ago since you’re no longer restricted to Windows and it’s now open source. I’ve heard a lot of people say it’s nicer than Spring for enterprise stuff. Haven’t tried it much myself though. Was fairly easy to set up a simple API, but I then got distracted by other projects.

      • hersh@literature.cafe
        link
        fedilink
        English
        arrow-up
        12
        ·
        2 days ago

        I don’t think you’ll find another major repo with so many real-world incidents though. Whether this is because of a systemic problem or just because it’s targeted more frequently, I’m not sure.

        • tempest@lemmy.ca
          link
          fedilink
          English
          arrow-up
          8
          arrow-down
          8
          ·
          2 days ago

          As much as some people deride it Javascript is one of the most used languages on the planet.

          This is basically the same as people thinking windows is less secure because it’s more often targeted.

          JavaScript does have a bit of a problem with dependencies but it isn’t much different than other languages with built in package managers like rust. It’s just a bigger juicer target.

          • aesthelete@lemmy.world
            link
            fedilink
            English
            arrow-up
            15
            arrow-down
            3
            ·
            edit-2
            1 day ago

            But Windows is less secure. Two things can be true at once. They are in the original topic too.

            The Java ecosystem is massive and decades old and I don’t hear one iota of the shit about maven central that I hear about npm.

            I guarantee that npm is full up with vibe coded bullshit at this point as well.

            I’m not sure what it even takes to upload a package to npm. Not even a pulse. I honestly never looked into it because the whole ecosystem is so rancid.

            EDIT: Look at how many shits in this are optional (and note the overall quality of the article as well): https://dev.to/aneshodza/publishing-your-first-npm-library-51k2. The ecosystem sucks.

      • Kairos@lemmy.today
        link
        fedilink
        English
        arrow-up
        4
        arrow-down
        1
        ·
        2 days ago

        There’s a lot of features that make it a better package manager but nobody cares. Every project has hundreds of dependencies and packages use a minimum, not exact, version.

        • LurkingLuddite@piefed.social
          link
          fedilink
          English
          arrow-up
          3
          ·
          2 days ago

          That sounds more like bad practices from the community. It definitely has ways to use exact versions. Not the least of which the lock file. Or the shrinkwrap file which public packages should be using.

          • dustyData@lemmy.world
            link
            fedilink
            English
            arrow-up
            7
            ·
            2 days ago

            Any security system based on expecting good behavior from people is sure to fail. If NPM has no estructural features to enforce safe behaviors, it is vulnerable by default. As no person using it will apply safe practices unless forced to. Specially if the default, easiest, less friction behavior, is inherently unsafe.

            • LurkingLuddite@piefed.social
              link
              fedilink
              English
              arrow-up
              1
              ·
              2 days ago

              I wouldn’t say pulling in higher versions is unsafe unless an attack like this succeeds. Otherwise it’s only an annoyance.

          • Serinus@lemmy.world
            link
            fedilink
            English
            arrow-up
            3
            arrow-down
            1
            ·
            2 days ago

            Then you’re waiting forever on vulnerability patches. Especially if there are layers, and each layer waits to update.

    • Meron35@lemmy.world
      link
      fedilink
      English
      arrow-up
      13
      ·
      2 days ago

      As someone completely unfamiliar with the JavaScript mess, are these security issues specific to npm the actual repository or npm the package manager?

      If it’s the latter, does using something else like yarn or bun instead help?

      • [object Object]@lemmy.ca
        link
        fedilink
        English
        arrow-up
        10
        ·
        1 day ago

        I think npm allows installation scripts which do make this worse, as a package can run arbitrary command at install time.

        • anyhow2503@lemmy.world
          link
          fedilink
          English
          arrow-up
          2
          ·
          1 day ago

          Npm has gotten a few config options that prevent this behaviour. We can only hope that they will become the default eventually.

      • delcaran@feddit.it
        link
        fedilink
        English
        arrow-up
        8
        ·
        1 day ago

        It’s not, it’s a problem of every package manager that do not use sources and checksums, like rust and python. Take a look at this article that does a better job then me at explaining the situation.

        • Nibodhika@lemmy.world
          link
          fedilink
          English
          arrow-up
          1
          ·
          edit-2
          8 hours ago

          That article has lots of issues:

          17% of the most popular Rust packages contain code that virtually nobody knows what it does

          That’s not true at all, the article where he got that information from says:

          Only 8 crate versions straight up don’t match their upstream repositories. None of these were malicious: seven were updates from vendored upstreams (such as wrapped C libraries) that weren’t represented in their repository at the point the crate version was published, and the last was the inadvertent inclusion of .github files that hadn’t yet been pushed to the GitHub repository.

          So, of the 999 most popular crates analyzed 0% contains code nobody knows what it does.

          He then lists some ways packages can be maliciously compromised:

          1. Steal credentials and impersonate a dev
          2. Misleading package names
          3. Malicious macros (this one is interesting, had never considered it before)
          4. Malicious build script

          And his solutions are:

          1. Bigger std library (solves none of the above)
          2. Source dependencies (solves none of the issues he showed, only the issue that happens in 0% of packages where binary doesn’t match the source and is detectable)
          3. Decentralized packages (which worsens every security concern)
          4. Centralized Checksum database (so a centralized package manager is bad, but a centralized Checksum index is good? How does that work?)

          Honestly I can’t take that article seriously, it grossly misinterpreted another study, presents problems that exist on every single package manager ever, doesn’t propose ANY valid solution, and the only thing he points to as a solution suffers from ALL of the same issues and then some.

        • arcterus@piefed.blahaj.zone
          link
          fedilink
          English
          arrow-up
          6
          ·
          edit-2
          1 day ago

          In a recent analysis, Adam Harvey found that among the 999 most popular crates on crates.io, around 17% contained code that do not match their code repository.

          17%!

          Let me rephrase this, 17% of the most popular Rust packages contain code that virtually nobody knows what it does (I can’t imagine about the long tail which receives less attention).

          Given that he lied about the results of the analysis he is using to prove his point, I find it hard to trust anything in this article.

          In the analysis, Harvey said only 8 repositories did not match their upstream repos. The other problems were issues like not including the VCS info, squashing history, etc.

          EDIT: Also, I just noticed that he called it a “recent” analysis. It’s roughly a two year old analysis. I expect things have improved a bit since then, especially since part of the problem was packaging using older versions of Cargo.

        • anyhow2503@lemmy.world
          link
          fedilink
          English
          arrow-up
          7
          ·
          1 day ago

          The good news is that there already is a gold standard for supply chain security: the Go programming language.

          Lmfao

          • bright_side_@piefed.world
            link
            fedilink
            English
            arrow-up
            4
            ·
            1 day ago

            Competent standard lib + decentralized libs + checksum db.

            While the article is a bit theatralic, it offers important arguments.

            • anyhow2503@lemmy.world
              link
              fedilink
              English
              arrow-up
              2
              ·
              1 day ago

              There are some good points in it, though I wouldn’t really consider go dependencies all that decentralized in practice and I don’t understand how checksum db will protect against supply chain attacks with stolen credentials, but I admit I haven’t looked into the details.

              • bright_side_@piefed.world
                link
                fedilink
                English
                arrow-up
                1
                ·
                20 hours ago

                Yep you’re right, tampering before transmission is still possible. I think I agree with having a strong standard lib helping that considerably. While the language of the blog is not objective, the “content” was better than expected 😊

        • AnarchistArtificer@slrpnk.net
          link
          fedilink
          English
          arrow-up
          1
          ·
          23 hours ago

          Thanks for the link. There have been a few people in this thread making this point, and I was considering asking them to elaborate so that I can gauge what my risk is from using pip for python. I appreciate you providing a resource so I can go learn more about this