Why You Should Care What You Npm Install
Tags: javascript, npm, security
Published: 2018-12-20 13:36:52

---
title: Why You Should Care What You Npm Install
published: true
description: As if we haven't learned anything from the Left-pad debacle on November 26th the Javascript world was shaken once again.
tags: javascript, npm, security
canonical_url: https://jsguru.io/blog/why-you-should-care-what-you-npm-install
cover_image: https://delivery.eusi.cloud/api/v1/f1a4305c-e431-4668-ae4c-02f78c656a41/media/s3/1545307898320_181220-Cover.png
---


As if we haven't learned anything from the _[Left-pad](https://qz.com/646467/how-one-programmer-broke-the-internet-by-deleting-a-tiny-piece-of-code/)_ debacle on November 26th the Javascript world was shaken once again.

---

A popular Npm library with over 2 million installs had a backdoor. Wait, what?! Yep, you heard it correctly the _[event-stream](https://github.com/dominictarr/event-stream/issues/116)_ library which was not archived at that time and was used all over the place from your garage script kiddie to enterprise systems was infected with an obnoxious back-door, a crypto miner /stealer/something. From now on we will call it the C - virus for dramatic effect.

>Damn crypto hype, it's high time the bubble burst and let us go on with our lives. - [Me](https://twitter.com/blackcat_dev), December 2018

But, how did it happen? Well, a combination of unfortunate circumstances and the author's faith in people led us here where we are today.
The author stopped using and maintaining the library a long time ago. Since it wasn't archived over time it became a dependency of many projects and lo and behold one day a good Samaritan slid into his inbox and offered to take the burden of maintaining the library upon himself and to carry the torch onwards, but he was not good, was he now.

{% twitter 1067124100332744704 %}

The author transferred the rights of the Npm module to this kind stranger but left the module's code on his Github account since there were some problems with name conflict when he tried to transfer it to the stranger's account, or so he says, but I suppose they weren't accidental either. This Samaritan was one nefarious schemer.
As soon as he got hold of the library he removed the publishing rights of the old author, added the `flatmap-stream` module which contained the C-virus, did a minor version bump and finally a new release on Npm.
The event-stream library was updated to the new minor version all over the world.
As soon as he planted the C-virus, he removed the `flatmap-stream` module from the library and then he did a major version bump and once again a new release on Npm. Quite smart isn't it? Now there was nothing suspicious in the codebase but since it was a major version update most of the systems wouldn't update to it because they are version locked to the previous major version thus they would still have the infected code.
Even one of my coworkers got infected, barely anyone noticed, but Kevin Beaumont.

{% twitter 1067125660014051330 %}

That was a brief summary and I probably missed a step or two but you get the picture.


---

__SHORT NOTICE:__
We shouldn't blame the author, he probably didn't really think it through that much but maintaining open source software is a real hassle and can be really mentally draining on the authors, especially in today's entitled society where people expect everything for nothing. So let's not put the blame on him.

-------

Now let's get back on track! Oh, here's another gem by Kevin Beaumont

{% twitter 1067130326395351040 %}

Hallelujah, praise the Lord! Preach! People didn't come up with this meme for no reason:
![Npm modules](https://cdn-images-1.medium.com/max/800/1*xMYsLPXMT02nL83x3Qbp6w.png)

__Key takeaways from this mess:__
* Sometimes we take for granted and don't think what we Npm install/composer require/yarn add
* Developers have become lazy. We have started taking "don't reinvent the wheel too literally", instead of writing a few extra lines we'd rather require a library, sometimes even for the most trivial of tasks (especially in the Javascript World this seems to be the trend)
* You should always put careful thought in what you require as a dependency, more dependencies can sometimes mean more technical debt
* Add a layer of abstraction and design an interface as a bridge/adapter between your domain logic and libraries, so you can swap them more easily if the need arises
* When a library stops being maintained we now own that code and it is our responsibility to fix it as part of our codebase or find a suitable replacement for it

These lessons were once again learned the hard way by many businesses this November.

Thanks for reading my long rant!


---
###Before you go…
If you enjoyed reading this post please share it. You should check out our other publications, you might like them too! We write from time to time about software development, tips and tricks, and how to become a better developer and business person in general. Join us on the journey of constant improvement!
<p>Follow us on <a href="https://www.facebook.com/jsguruio/">Facebook</a>, <a href="https://twitter.com/jsguru_software">Twitter</a>, <a href="https://www.linkedin.com/company/jsguru">LinkedIn</a>, <a href="https://medium.com/jsguru">Medium</a> or <a href="https://dev.to/jsguru_io">DEV.to</a>.</p>
---

Originally published at [jsguru.io](https://jsguru.io/blog/why-you-should-care-what-you-npm-install).