r/javascript • • Nov 27 '18

event-stream vulnerability explained

https://schneid.io/blog/event-stream-vulnerability-explained/
412 Upvotes

70 comments sorted by

View all comments

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 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.

5

u/musicisair Nov 28 '18

These lock files don't do what you think they do.

package-lock.json and yarn.lock are for the developers of the module only. When consumed as a published module, installed via npm/yarn, these lock files are ignored.

Npm does respect a published npm-shrinkwrap.json. Yarn does not have a locking mechanism for transitive dependencies if published modules (they call this a feature).

2

u/blood_bender Nov 28 '18

Well, strict semver would solve that too, which I think anyone who publishes modules should be using anyway.

But I did assume the lockfiles would be used recursively for dependencies, I'm surprised they're not. Good to know.

3

u/musicisair Nov 28 '18

Yeah, if everyone would use strict semver then this lock file issue would go away, but then we get other issues... like increasing the size of node_modules even more due to having multiple versions of the same modules in a package this risking opening a black hole here on Earth because of it 😆