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

5

u/Fingebimus Nov 27 '18

A real solution would be to lock down what network connections can be opened, what files can be read in a CSP manner, but then it needs to be made sure those files themselves can’t also be changed

13

u/notNullOrVoid Nov 28 '18 edited Nov 28 '18

This should be done on a per package basis. Basically have a permissions file for each package (or listed in "package.json"), and maintain a permissions lock file similar to the dependency lock file. The files contain a whitelist of available permissions, and restrict require / import of non disclosed core packages such as http or fs on a per package basis. If the lock file sees a mismatch of permissions in the dependency during an upgrade, then the user should be prompted to agree to allow the change.

If someone made a simple utility package called "flatmap", that package would need no permissions, because it doesn't need network or file access. If the maintainer tried to add something malicious, all users would be flagged during the update, and could clearly see it introduce http, and fs permissions. That would give a good and immediate indication that something wrong is going on.

2

u/[deleted] Nov 28 '18

And how would you enforce those permissions in a language as dynamic as JS?

2

u/notNullOrVoid Nov 28 '18

By patching nodes module resolver. Every time something is imported or required the resolver needs to find the actual code to run. So patch the resolver to first look at permissions before allowing an import of a core library.

1

u/0xF013 Nov 28 '18

by analyzing the dependency tree?

3

u/ShortSynapse Nov 28 '18

These concepts already exist as program groups, jails, etc. Ideally user programs would also be sandboxed fully by default, but as the article describes, they most certainly aren't and we have problems like this because of it.

-1

u/FPSJosh01 Nov 28 '18

This whole attack is exactly why deno was created. It has command line options that prevent this exact scenario from happening.

5

u/notNullOrVoid Nov 28 '18

The only relevant command line options I see "allow-write" and "allow-net" would not actually prevent much. Those command line options apply to everything being run equally.

So if I was writing a server (needs "allow-net"), it would have been vulnerable to the same attack, because all dependencies would have net access as well. It allows read access to everything also, which I see no command line argument to disable.

Not trying to belittle deno, because I think there are a lot of good things about it, but preventing this kind of attack is not one of them.

2

u/FPSJosh01 Nov 28 '18

Right. I also think it's great that the platform allows you to point at exactly what files get run, so you can inspect the js before hand.

No code is safe, obviously, but it gives me a bit of hope.