I spent months studying how malicious npm packages actually work. Most of them do the same thing eg run a preinstall script, read your .env and credentials, and send them to a remote server. All
before your app starts.
npm install will run this code automatically. No prompt, no warning.
I built Dependency Guardian a behavioral analysis engine that scans packages for malicious patterns before they touch your system.
it has:
- 26 detectors (shell execution, credential theft, exfiltration, obfuscation, time bombs)
- 53 cross-signal amplifiers that correlate findings across detectors
- ~2,900 tests across 76 test files
- Benchmarked against 11,356 real packages at 99.95% precision
It would have caught Shai-Hulud, the Chalk/Debug hijack, and the S1ngularity campaign.
Snyk, Dependabot, and npm audit all missed these because they rely on CVE databases. If there's no CVE filed yet, they're blind. Dependency Guardian reads the actual code.
curious if anyone here has been exposed/experiences to supply chain attacks and how they handled them
Once this or something like it becomes widespread, won't sophisticated attackers simply test their attacks against this? So, for example, if it checks for `rm` invocations, just implemented the functionally of `rm` in the malware, or if it checks for exfiltration of data, then shell out to curl to do that in a different process.
If you think of making it so robust that this is impossible, you're just describing a container, which we already have.
There's a long history of people trying to build software that detects bad software. It's known as Antivirus software. It doesn't work very well, because you're up against fundamental truths of computational theory (the halting problem).
this is actually an interesting idea to re-implement! imagine a JS runtime with hooks all over the place. these hooks look for `chmod`, `rm -r ~`/`rm -rf /` and such, intercept network requests, and scan variables for known API key patterns, e.g `sk_****`.
I spent months studying how malicious npm packages actually work. Most of them do the same thing eg run a preinstall script, read your .env and credentials, and send them to a remote server. All before your app starts.
npm install will run this code automatically. No prompt, no warning.
I built Dependency Guardian a behavioral analysis engine that scans packages for malicious patterns before they touch your system.
it has: - 26 detectors (shell execution, credential theft, exfiltration, obfuscation, time bombs) - 53 cross-signal amplifiers that correlate findings across detectors - ~2,900 tests across 76 test files - Benchmarked against 11,356 real packages at 99.95% precision
It would have caught Shai-Hulud, the Chalk/Debug hijack, and the S1ngularity campaign.
Snyk, Dependabot, and npm audit all missed these because they rely on CVE databases. If there's no CVE filed yet, they're blind. Dependency Guardian reads the actual code.
curious if anyone here has been exposed/experiences to supply chain attacks and how they handled them
Once this or something like it becomes widespread, won't sophisticated attackers simply test their attacks against this? So, for example, if it checks for `rm` invocations, just implemented the functionally of `rm` in the malware, or if it checks for exfiltration of data, then shell out to curl to do that in a different process.
If you think of making it so robust that this is impossible, you're just describing a container, which we already have.
Thanks for sharing.
I still wonder why this is not an official npm / node effort to better secure the ecosystem...
Well...
There's a long history of people trying to build software that detects bad software. It's known as Antivirus software. It doesn't work very well, because you're up against fundamental truths of computational theory (the halting problem).
this is actually an interesting idea to re-implement! imagine a JS runtime with hooks all over the place. these hooks look for `chmod`, `rm -r ~`/`rm -rf /` and such, intercept network requests, and scan variables for known API key patterns, e.g `sk_****`.
This is called dynamic analysis!
This seems very nice! But is there a way to use it without an Google account?
How is it different from the established player in the game, Socket.dev?