Almost every week you can read about attacks performed through compromised npm libraries. The npm ecosystem is vast and unmanageable and for it-sec people it is frustrating to deal with all the possible threats that come with using npm.
There are a lot of best practices out there how to deal with third party libraries in general, but to be honest, it's not enough in my eyes. Most of these explain how to avoid a breach, but in fact it seems more realistic to discuss an assume-breach-approach.
Regarding npm supply chain attacks I have the impression that they could be performed by either
- Executing scripts on a machine
or
- Communicating from within the application
One would now say wait wait there are tons of attacks that can happen through a compromised npm package, like remote code execution, sensitive data stealing, encryption/ransomware and so one (1, 2). You are right, but to make those things work, you have to either run a script on a machine or communicate from within the application with an external threat actor controlled command and control server, e.g.:
- Perform data exfiltration --> communicating from within the application
- Spawn a reverse shell --> executing scripts
- Cryptominer --> executing scripts
- Ransomware --> executing scripts
- RCE --> executing scripts
- Stealing sensitive application data --> communicating from within the application
So bottom line it would be enough to sandbox the running application (e.g. through using a firewall with a whitelist of connections) and block any script execution during the installation process (3)?
In a (very shorten) scenario a developer downloads an arbitrary compromised npm library and installs it on his machine. Then this library is integrated in the developed piece of software which will be build in the CI/CD and finally deployed.
In that case I have three layers on which I need to block scripts and sandbox my application. The hardest part in my eyes is sandboxing the running application on the developer's machine since you need to ponder productivity against security by restricting internet access.
I know all the best practices to work with third party libraries:
- Using a private repository
- Scanning the libraries
- Do not automatically update libraries
- Using a four-eyes principle when including new libs
- and so on
And you can also monitor (your) packages looking for possible breach signals (4). But still it might be possible that a compromised library slips into the company. Mistakes happen. But in that case one wants to make sure that no damage can happen, right?
Although this picture is kinda superficial, do I miss a thing? I just want to get a handle on that frustrating topic.
[1] https://snyk.io/blog/snyk-200-malicious-npm-packages-cobalt-strike-dependency-confusion-attacks/
[2] https://www.shiftleft.io/blog/node.js-vulnerability-cheatsheet/