Is npm a Hotbed of Malware? (2024)

According to WhiteSource, a leading open source security provider, npm, one of the most widely used JavaScript package managers, is a playground for malicious actors. Is it really that bad?

First, JavaScript is wildly popular. Love it or hate it, Javascript by Stack Overflow’s count remains today’s most commonly used programming language. With more than 16 million developers worldwide relying on its speed, strong documentation, and interoperability with other programming languages that won’t be changing soon.

But its popularity is a mixed blessing. Hackers are increasingly targeting JavaScript’s open source package managers and package registries. The most widely used of which is npm, with more than 1.8 million active packages.

Malware Detection

Using WhiteSource Diffend, the company’s flagship automated malware detection platform. The company claims it found more than 1,300 malicious npm packages in 2021 in npm. That’s bad, but 1,300 out of 1.8-million is only 0.007222%. If you were to just randomly grab JavaScript packages for your program, odds are you’ll be safe.

According to the report, WhiteSource tracked an average of 32 thousand new npm packages published every month during 2021. Even out of that yearly total of 384 thousand packages, your chance of grabbing the wrong code only goes up to 0.00338%.

Of course, no one programs it that way. But this does underline that you need to look very carefully at any npm code before pulling it into your project. For example, you’ll want to avoid new code or code that others have avoided.

Different Attacks

On the other hand, do you want to take even a minute chance when the kind of attacks hiding in npm included:

  • Software supply chain attacks: Used to steal data, corrupt targeted systems, and gain access throughout networks via lateral movement.
  • Cryptojacking: Enables a threat actor to take control of a victim’s compute resources to mine cryptocurrency.
  • Data stealing: Using keyloggers, screen scrapers, spyware, adware, bots, and more, attackers steal private and/or proprietary data from victims.
  • Security research: Attackers create packages that falsely claim to be designed for security research but actually contain malicious code.

I don’t think you do.

True, most npm malware is just there to check out your site. But who wants a reconnaissance program cruising through your systems? I sure don’t!

In addition, by npm’s official count, an astronomical 20 billion package versions are downloaded every week. Clearly, few people are doing their due diligence when it comes to using npm packages.

By its very nature, npm is difficult to police. Npm enables you to use external libraries and supports dependency management. Combined this makes it all too easy to call third-party libraries and dependencies for your project. In addition, while in theory npm packages include everything needed for their functionality all too often, many packages download additional resources upon installation. Sure, you checked the specific program for security problems but what about all its dependencies and its downloads?

Can you say “dependency hell?” I can.

Secure the Software Supply Chain

Npm is a sterling example of why we need software supply chain security. And we need it now.

So it’s no surprise that “with more than 18,000 npm package versions published in 2021, there’s no question that npm is a valuable tool for developers,” explained Rami Sass, WhiteSource’s co-founder and CEO. But, “Unfortunately, that popularity is being used by threat actors to spread malware and launch attacks that harm businesses and individuals.”

For example, let’s say you downloaded what you thought was the well-regarded npm packages style-resources-loader and sass-loader. But, unlucky you, instead, you download the two brandjacking packages faking them. Besides having names that looked right at a casual glance they also included their good source code. But, hiding away in there was an obfuscated JavaScript file and a pair of binary files hidden as JavaScript components that were up to no good.

Specifically, one of the fake JavaScript files was part of the Cobalt Strike, an adversary simulation framework. The final goal? To put your machine to work mining Monero cryptocurrency. That’s no one’s idea of a good time.

Diffend Yourself

So, what can you do? Well, of course, WhiteSource would like you to download and eventually buy Diffend. Their tool checks to make sure you’re only using verified package sources and that you avoid most npm security traps. Using Diffend is actually a good idea.

In addition, WhiteSource has numerous other suggestions on how to defend yourself against common npm security holes. These include:

  • Watch out for typosquatting and its friends. For example, sspec -> rspec; atlas-client -> atlas_client; damerau-levenstein -> damerau-levenshtein; or ruby-bitcoin -> bitcoin-ruby
  • Never blindly assume ownership in any registry.
  • Migrate from packages that are abandoned or take them over.
  • Do not use packages that are fairly new (e.g. days old).
  • Report unexpected behaviors and inconsistencies to package owners.
  • Never install packages without running an assessment.
  • Don’t install upgraded libraries without carefully reviewing the code.
  • Make sure that dependency update tools that pull request (PR) updates have enough delay to time to verify packages updates.
  • Do not use the same environment variable (ENV) for running specs, building containers, pushing things, etc.

Finally, always remember that the most damage to date from npm has not come from conventional malware at all. Instead, it’s come from developers screwing around with their npm libraries, Examples include the recent “colors.js” and “faker.js” mess and 2016’s infamous, “left-pad npm” episode.

In short, while I can’t call npm a “playground for malicious actors,” I can call it ripe for malware and unable to defend itself well from its inherent security problems. If you use npm, and I know many of you do, you must take steps to protect yourself.

TRENDING STORIES

Steven J. Vaughan-Nichols, aka sjvn, has been writing about technology and the business of technology since CP/M-80 was the cutting-edge PC operating system, 300bps was a fast internet connection, WordStar was the state-of-the-art word processor, and we liked it. Read more from Steven J. Vaughan-Nichols
Is npm a Hotbed of Malware? (2024)

FAQs

Can you get malware from npm? ›

Malware is a major concern for npm Security and we have removed hundreds of malicious packages from the registry. For every malware report we receive, npm Security takes the following actions: Confirm validity of the report. Remove the package from the registry.

Is npm a security risk? ›

NPM can also introduce vulnerabilities and exploits that execute arbitrary commands on the developer's workstation. Arbitrary command execution in NPM refers to a vulnerability in the NPM package manager that allows an attacker to execute arbitrary commands on a targeted system through a malicious npm package.

Is everything on npm safe? ›

Many popular npm packages have been found to be vulnerable and may carry a significant risk without proper security auditing of your project's dependencies. Some examples are npm request, superagent, mongoose, and even security-related packages like jsonwebtoken, and validator.

How do I know if npm is safe? ›

npm audit automatically runs when you install a package with npm install . You can also run npm audit manually on your locally installed packages to conduct a security audit of the package and produce a report of dependency vulnerabilities and, if available, suggested patches.

What are the risks of npm? ›

There's an escalating trend of malicious actors targeting NPM packages, posing a threat to software project integrity and potentially exposing user data to compromise. A comprehensive understanding of these threats, their repercussions, and effective mitigation strategies is essential.

How to avoid npm vulnerabilities? ›

To mitigate vulnerabilities related to target attacks in npm:
  1. Use npm audit to scan your project for known vulnerabilities and take action to fix them.
  2. Use a security scanner or other tool to regularly check your project dependencies for known vulnerabilities.
Jan 22, 2023

How to use npm securely? ›

Use npm Audit

The npm audit command allows you to scan your dependencies for security vulnerabilities. It will scan direct, devDependencies, bundled, and optional dependencies and send them to your default repository to check for known vulnerabilities. Running npm audit every time you run npm install is recommended.

Do people still use npm? ›

In 2023, Yarn and npm will continue to be widely used package managers in the JavaScript ecosystem. Ultimately, the choice between the two will come down to your specific needs and preferences as a developer.

Why is npm not Recognised? ›

The system may not recognize the npm command due to incorrect or missing environment variables. Follow these steps to check and configure environment variables in Windows: 1. Type environment variables in the search box on the Windows taskbar.

Why is npm insecure? ›

NPM itself doesn't automatically check for vulnerabilities like these or prevent developers and users from uploading and downloading insecure packages. As a result, if left undetected, vulnerabilities in NPM packages can spread quickly within communities that use Node.

How do I get rid of npm? ›

To remove a package with the npm uninstall command, you can use the syntax npm uninstall package-name in the directory where the package is located.

What is the vulnerability of npm IP? ›

An issue in all published versions of the NPM package ip allows an attacker to execute arbitrary code and obtain sensitive information via the isPublic() function. This can lead to potential Server-Side Request Forgery (SSRF) attacks.

Is it safe to update npm? ›

Updating npm is generally safe, as new releases undergo thorough testing and are widely adopted by the community. However, it's always best practice to back up your projects and review the release notes for any breaking changes that could affect your work.

How do I get rid of npm warnings? ›

If you run npm with --loglevel=error , you should no longer see this or any other warnings.

How to check for vulnerabilities using npm? ›

Check for Security Vulnerabilities in your Project's NPM Packages and Dependencies
  1. Run npm audit fix to apply remediations to the package tree automatically.
  2. Run the recommended commands individually to manually install updates to vulnerable dependencies.

How do I know if a program is malware? ›

  1. Signs of malware. Your device is running slower than usual. Your device keeps crashing. Your data runs out quicker. You're getting a lot of pop-ups. You notice messages you didn't send. You notice apps and files you didn't download. ...
  2. How to remove malware from your device.
  3. Make sure your devices are safe from malware.
Dec 12, 2023

Can you get malware from downloading a file? ›

Downloading unknown or unsolicited programs or files can be dangerous because they may contain viruses, malware, or harmful content that could harm your computer, compromise your personal data, or lead to potential security risks.

Top Articles
Latest Posts
Article information

Author: The Hon. Margery Christiansen

Last Updated:

Views: 5889

Rating: 5 / 5 (70 voted)

Reviews: 93% of readers found this page helpful

Author information

Name: The Hon. Margery Christiansen

Birthday: 2000-07-07

Address: 5050 Breitenberg Knoll, New Robert, MI 45409

Phone: +2556892639372

Job: Investor Mining Engineer

Hobby: Sketching, Cosplaying, Glassblowing, Genealogy, Crocheting, Archery, Skateboarding

Introduction: My name is The Hon. Margery Christiansen, I am a bright, adorable, precious, inexpensive, gorgeous, comfortable, happy person who loves writing and wants to share my knowledge and understanding with you.