Why You Should Care What You Npm Install

$sasa->blagojevic;
JSGuru
Published in
4 min readDec 20, 2018

As if we haven’t learned anything from the Left-pad 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 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, 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.

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.

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

Hallelujah, praise the Lord! Preach! People didn’t come up with this meme for no reason:

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!

Follow us on Facebook, Twitter, LinkedIn, Medium or DEV.to.

Originally published at jsguru.io.

--

--

$sasa->blagojevic;
JSGuru
Editor for

full stack #php developer evangelist @ JSGuru, #ruby apprentice, coffee and code addict