VOOZH about

URL: https://thenewstack.io/is-npm-a-hotbed-of-malware/

⇱ Is npm a Hotbed of Malware? - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2022-02-03 07:00:08
Is npm a Hotbed of Malware?
news,
Security / Software Development

Is npm a Hotbed of Malware?

WhiteSource, a leading open source security provider, says npm, one of the most widely used JavaScript package managers, is a playground for malicious actors.
Feb 3rd, 2022 7:00am by Steven J. Vaughan-Nichols
👁 Featued image for: Is npm a Hotbed of Malware?
Featured image via Pixabay.

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
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.