The one thing this article doesn't mention, which isn't as clever as the rest but really shows how well he planned this attack, is that after introducing flatmap-stream, he bumped event-stream to v3.3.6. All well and good. But a week later when he removed flatmap-stream, he bumped event-stream to v4.0.0.
So any investigation of event-stream wouldn't find flatmap-stream as a dependency at all, yet by bumping to 4.0.0, he ensured that any one of the millions of downloads would continue downloading the infected version, unless their package.json showed * or something similar. Since npm install by default would add ^3.3.whatever, it's super unlikely anyone would actually upgrade to 4.0 anytime soon, yet an audit of the package would look clean.
This attack was super clever for a variety of reasons, including this one.
As the article says, use a package-lock.json or yarn.lock, and set your package.json to strict semver.
As the article says, use a package-lock.json or yarn.lock, and set your package.json to strict semver.
This is like buying food from a bunch of random people, and then storing it all in your fridge and assuming that it's all healthy and fine because it's in your fridge and you don't go buy it every day.
108
u/blood_bender Nov 27 '18
The one thing this article doesn't mention, which isn't as clever as the rest but really shows how well he planned this attack, is that after introducing
flatmap-stream, he bumpedevent-streamtov3.3.6. All well and good. But a week later when he removedflatmap-stream, he bumpedevent-streamtov4.0.0.So any investigation of
event-streamwouldn't findflatmap-streamas a dependency at all, yet by bumping to4.0.0, he ensured that any one of the millions of downloads would continue downloading the infected version, unless theirpackage.jsonshowed*or something similar. Sincenpm installby default would add^3.3.whatever, it's super unlikely anyone would actually upgrade to 4.0 anytime soon, yet an audit of the package would look clean.This attack was super clever for a variety of reasons, including this one.
As the article says, use a
package-lock.jsonoryarn.lock, and set yourpackage.jsonto strict semver.