<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Simon Kobler</title>
    <description>The latest articles on DEV Community by Simon Kobler (@koblers).</description>
    <link>https://dev.to/koblers</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3935442%2Fa0bf9713-7b2c-4b39-a56e-2472e56fcf14.jpeg</url>
      <title>DEV Community: Simon Kobler</title>
      <link>https://dev.to/koblers</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/koblers"/>
    <language>en</language>
    <item>
      <title>Stop letting npm install run untrusted code on your machine — meet np-audit</title>
      <dc:creator>Simon Kobler</dc:creator>
      <pubDate>Sat, 16 May 2026 20:06:33 +0000</pubDate>
      <link>https://dev.to/koblers/stop-letting-npm-install-run-untrusted-code-on-your-machine-meet-np-audit-3kj4</link>
      <guid>https://dev.to/koblers/stop-letting-npm-install-run-untrusted-code-on-your-machine-meet-np-audit-3kj4</guid>
      <description>&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnudl3iep4szs6b3gdcdg.webp" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnudl3iep4szs6b3gdcdg.webp" alt=" " width="800" height="450"&gt;&lt;/a&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You type it dozens of times a day. You probably typed it this morning. And every time you did, you handed arbitrary code execution to every maintainer in your dependency tree — and every attacker who has phished one of them.&lt;/p&gt;

&lt;p&gt;Over the last eight months, attackers have noticed. The &lt;strong&gt;Shai-Hulud&lt;/strong&gt; family of worms has compromised hundreds of npm packages, created tens of thousands of malicious GitHub repos, and harvested thousands of developer secrets. The November 2025 wave alone hit &lt;strong&gt;700+ packages, 27,000 malicious repos, and ~14,000 exposed secrets across 487 organizations&lt;/strong&gt; — in under 48 hours.&lt;/p&gt;

&lt;p&gt;I got tired of waiting for npm to fix this, so I built &lt;strong&gt;&lt;a href="https://github.com/KoblerS/np-audit" rel="noopener noreferrer"&gt;np-audit&lt;/a&gt;&lt;/strong&gt; — a zero-dependency CLI that statically analyzes install scripts &lt;em&gt;before&lt;/em&gt; npm executes them. This post is partly about why you need it, and mostly about how to use it.&lt;/p&gt;




&lt;h2&gt;
  
  
  The attack that keeps working
&lt;/h2&gt;

&lt;p&gt;Every Shai-Hulud variant relies on the same three lines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"preinstall"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node setup.mjs"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That's it. The second &lt;code&gt;npm install&lt;/code&gt; resolves a compromised version, &lt;code&gt;setup.mjs&lt;/code&gt; runs &lt;strong&gt;before&lt;/strong&gt; your code, before your tests, before any human looks at anything. Same user, same env vars, same network access as you.&lt;/p&gt;

&lt;p&gt;The payload is always some flavor of the same recipe:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Download a second runtime (Bun is the current favorite — bypasses Node-pattern detection).&lt;/li&gt;
&lt;li&gt;Run an obfuscated harvester that scans for GitHub tokens, npm credentials, AWS/Azure/GCP keys, Kubernetes service account tokens, Vault creds, browser-saved passwords, and CI runner secrets.&lt;/li&gt;
&lt;li&gt;Encrypt and exfiltrate by pushing to public GitHub repos via the GraphQL API — looks like normal git activity from the outside.&lt;/li&gt;
&lt;li&gt;Use any stolen GitHub PAT to inject malicious workflows into other repos the victim can write to. One dev becomes patient zero for their entire org.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;A nice touch from the Mini Shai-Hulud variant:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;if &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;locale&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ru&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;||&lt;/span&gt; &lt;span class="nx"&gt;lang&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;startsWith&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;ru&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;process&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;exit&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; &lt;span class="c1"&gt;// do nothing&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The same Russian-locale guardrail appears in three separate campaigns now attributed to &lt;strong&gt;TeamPCP&lt;/strong&gt;.&lt;/p&gt;




&lt;h2&gt;
  
  
  This is not a vulnerability. This is the feature.
&lt;/h2&gt;

&lt;p&gt;There is no CVE to patch here. npm &lt;code&gt;preinstall&lt;/code&gt;, &lt;code&gt;install&lt;/code&gt;, and &lt;code&gt;postinstall&lt;/code&gt; scripts run automatically by design — that's how packages compile native addons, fetch platform binaries, set up build tooling. It's documented, intentional, and useful.&lt;/p&gt;

&lt;p&gt;It's also a loaded gun in every Node project on Earth, and it has been getting fired regularly since 2018: &lt;code&gt;event-stream&lt;/code&gt;, &lt;code&gt;ua-parser-js&lt;/code&gt;, &lt;code&gt;node-ipc&lt;/code&gt;, &lt;code&gt;colors&lt;/code&gt;, &lt;code&gt;faker&lt;/code&gt;, the Bitwarden CLI in April. The attackers aren't getting more sophisticated. They don't need to.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;--ignore-scripts&lt;/code&gt; is the official advice. It also breaks &lt;code&gt;bcrypt&lt;/code&gt;, &lt;code&gt;node-sass&lt;/code&gt;, &lt;code&gt;puppeteer&lt;/code&gt;, &lt;code&gt;sharp&lt;/code&gt;, and half your toolchain. Nobody actually runs it in CI.&lt;/p&gt;

&lt;p&gt;So we live with the gun pointed at us. Or we look at what the scripts actually do before we let them run.&lt;/p&gt;




&lt;h2&gt;
  
  
  Meet np-audit (&lt;code&gt;npa&lt;/code&gt;)
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;&lt;a href="https://github.com/KoblerS/np-audit" rel="noopener noreferrer"&gt;np-audit&lt;/a&gt;&lt;/strong&gt; is a static analyzer for npm lifecycle scripts. It downloads the tarballs npm is about to install, reads every &lt;code&gt;preinstall&lt;/code&gt; / &lt;code&gt;install&lt;/code&gt; / &lt;code&gt;postinstall&lt;/code&gt; script, and flags the patterns that every documented supply chain attack has used:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;eval()&lt;/code&gt; and &lt;code&gt;new Function()&lt;/code&gt; calls&lt;/li&gt;
&lt;li&gt;Obfuscator.io-style mangling (&lt;code&gt;var _0x3f2a = [...]&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;High-entropy strings (encrypted/compressed payloads)&lt;/li&gt;
&lt;li&gt;Hex escape density and &lt;code&gt;String.fromCharCode()&lt;/code&gt; chains&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;Buffer.from(x, 'base64')&lt;/code&gt; followed by &lt;code&gt;eval&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Shell spawning via &lt;code&gt;child_process&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;process.env&lt;/code&gt; access combined with outbound network calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Each signal contributes to a score. Anything over a configurable threshold blocks the install. &lt;strong&gt;Zero runtime dependencies&lt;/strong&gt;, pure Node built-ins, and — obviously — no install scripts of its own. The whole point of a supply chain auditor is that you can audit it in an afternoon.&lt;/p&gt;

&lt;h3&gt;
  
  
  Install
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; np-audit
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Daily use
&lt;/h3&gt;

&lt;p&gt;Just swap the verb:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npa &lt;span class="nb"&gt;install&lt;/span&gt;   &lt;span class="c"&gt;# audit, then npm install&lt;/span&gt;
npa ci        &lt;span class="c"&gt;# audit, then npm ci&lt;/span&gt;
npa scan      &lt;span class="c"&gt;# audit only, no install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a package is suspicious, you get a clean report and a non-zero exit code — drop-in safe for CI:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;✗ evil-pkg@1.0.0  postinstall: install.js  DANGER (score: 9)
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Interactive review for the paranoid
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npa i &lt;span class="nt"&gt;--review&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Drops you into a TUI listing every install script in your tree. You decide one by one which ones get to run. Under the hood it's &lt;code&gt;npm install --ignore-scripts&lt;/code&gt; followed by manual execution of only the scripts you approved — basically informed consent for lifecycle scripts.&lt;/p&gt;

&lt;h3&gt;
  
  
  Set and forget
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npa &lt;span class="nb"&gt;alias&lt;/span&gt; &lt;span class="nt"&gt;--install&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Installs a shell hook so every &lt;code&gt;npm install&lt;/code&gt; and &lt;code&gt;npm ci&lt;/code&gt; you type is scanned first. Clean tree, npm proceeds. Suspicious tree, npm never runs.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="gp"&gt;$&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;npm &lt;span class="nb"&gt;install &lt;/span&gt;lodash
&lt;span class="go"&gt;[npa] Scanning dependencies before npm install...
✔ No packages with install scripts found.
[npa] Scan passed. Running npm install...
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  CI example
&lt;/h3&gt;

&lt;p&gt;GitHub Actions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight yaml"&gt;&lt;code&gt;&lt;span class="pi"&gt;-&lt;/span&gt; &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="s"&gt;Install dependencies (audited)&lt;/span&gt;
  &lt;span class="na"&gt;run&lt;/span&gt;&lt;span class="pi"&gt;:&lt;/span&gt; &lt;span class="pi"&gt;|&lt;/span&gt;
    &lt;span class="s"&gt;npm install -g np-audit&lt;/span&gt;
    &lt;span class="s"&gt;npa ci&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If a transitive dep gets compromised between your last green build and this one, the job fails &lt;em&gt;before&lt;/em&gt; the malicious script touches your runner's env vars.&lt;/p&gt;




&lt;h2&gt;
  
  
  What it doesn't do
&lt;/h2&gt;

&lt;p&gt;np-audit is not magic. A determined attacker writing clean, readable, plain-JavaScript malware can slip past a static heuristic check — that's a fundamental limit of static analysis.&lt;/p&gt;

&lt;p&gt;The point isn't to be perfect. The point is to raise the cost from &lt;em&gt;"drop in a &lt;code&gt;preinstall&lt;/code&gt; and harvest 14,000 secrets in a weekend"&lt;/em&gt; to something that requires real effort. Every Shai-Hulud variant so far has leaned on heavy obfuscation precisely because the maintainers were trying to slip past human review. np-audit is human review at machine speed.&lt;/p&gt;




&lt;h2&gt;
  
  
  TL;DR
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;npm install&lt;/code&gt; runs untrusted code on your machine. This is by design.&lt;/li&gt;
&lt;li&gt;The Shai-Hulud worms are exploiting that design at industrial scale and getting away with it.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;--ignore-scripts&lt;/code&gt; breaks too much to be realistic.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://github.com/KoblerS/np-audit" rel="noopener noreferrer"&gt;np-audit&lt;/a&gt;&lt;/strong&gt; looks at install scripts &lt;em&gt;before&lt;/em&gt; they run, scores them, and blocks the obviously malicious ones.
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; np-audit
npa ci
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Issues, PRs, and stars welcome: &lt;strong&gt;&lt;a href="https://github.com/KoblerS/np-audit" rel="noopener noreferrer"&gt;github.com/KoblerS/np-audit&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Stay safe out there. And maybe read the next &lt;code&gt;preinstall&lt;/code&gt; script before you let it read your &lt;code&gt;~/.aws/credentials&lt;/code&gt;.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>node</category>
      <category>security</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
