Hello everyone! I'm Nauchter, you can find me online if you type Nauchter anyway, nauchter.pl Nauchter.pl is my website, it has a bunch of other material on JavaScript, security and other things.
And today, we're going to look at running someone else's code. Speaking of that, if I gave you a string of text and asked you to put it in your application and run it, would you do that? Would you put my code in production without looking at it much? Well, I guess the answer is going to be no. But would it help if I put it in a tar.gz file? Is it more appealing that way? Somehow it is, because that's what NPM packages are. And they're great, and everyone's using them, but they're actually unsanitized input from the internet, that we put in our applications and run. Okay? So yes, that's what we're doing, we're doing that all the time. I'm installing NPM packages all the time. What if some of the packages in there aren't great? And by that, I don't mean lousy packages. I published some lousy packages, and nothing bad happened. But I mean malicious packages, dangerous packages, that want to hurt your application, your users. What do we do about that? Well, there's tools for supply chain security, right? So, a tool might say, hey, some researchers found out that this package is not great, and they reported it. So, that package that you shipped to production a few weeks ago, now we know that it's not a good one. Please do something about it. Is that a great situation to be in? Not necessarily. Okay, there's SocketDev. You can use that and get a much better feedback loop, because SocketDev is automating finding suspicious qualities about packages. So, SocketDev, within a few hours of the package being published, is going to be able to tell you that there's possibly something wrong with it. But then you need to investigate it. At Lavamote we decided to be proactive instead of reactive, so we're running with the assumption that one of the dependencies in the dependency graph is already malicious when the application runs. So, how does it work? I do have a demo, if that was a longer talk, you can check that demo out, but let's look at the situation where you install a build tool for your project, and then someone puts this in your build tool's code somewhere. So it takes your GitHub token, while running in CI, and sends it somewhere. Is that great? Probably not. What LavaMode is doing, LavaMode is allowing you to generate a policy for your entire application, in this case a build process, and then run it based on that policy. The policy is automatically generated, it detects almost everything that is needed for the app to run, then you proceed to tweak the policy to the sideline, which things should be ok to allow and which shouldn't. If our analysis fails to find something, it doesn't show up in the policy, and is by default not allowed. In this case, the policy is generated with the HTTPS request and Process.env being there. What we can do is either remove those, or change them to false, which means they are not allowed, and running your build with lavamode is going to cause one of these errors to show up. Either this evil dependency requesting HTTPS package, which is not available, or failing to read env from process because process is undefined. How is that even possible? Well, it's thanks to Hardened JavaScript. We're using Hardened JavaScript behind the scenes to isolate each dependency within the same process.
Comments