Get the free coreGet core

npm malware: how malicious packages get onto your Mac

Updated 6 min readSection 05 / Threats
SHORT ANSWER

npm malware gets onto a Mac because a package you installed runs code. npm 11 runs install scripts, small commands a package asks for, right after the package lands in node_modules. The package may carry a lookalike name, a name an AI invented, a hijacked version of a real package, or come from a repo a fake recruiter told you to run. If you think it ran, look for known traces first and replace credentials from a clean device second, meaning a computer or phone that never installed the package.

A malicious npm package is ordinary JavaScript with a bad purpose. It does not need a security hole in your Mac. It needs you, or the agent working for you, to install it. This page starts with what to do, then explains how npm malware gets in and how to spot it. The broader history is on the npm supply chain attack page.

01What to do if you think npm malware ran

Do these in order. The order protects you from one trap in the Mini Shai-Hulud variant.

  1. Look for the trap file. Run ls ~/Library/LaunchAgents/com.user.gh-token-monitor.plist in Terminal. If it prints the path, the file is there. That variant installs a background program that polls GitHub and tries to run rm -rf ~/, which deletes your home folder, when the token it checks is revoked.
  2. If the file is there, don't revoke GitHub tokens yet, from any device. The program fires when the token it checks is revoked. Stop it first with launchctl, the command that loads and unloads background agents:
   launchctl bootout gui/$(id -u) ~/Library/LaunchAgents/com.user.gh-token-monitor.plist
   rm ~/Library/LaunchAgents/com.user.gh-token-monitor.plist

The first line removes the background program from your login session, the second deletes its file, as Wiz advises before any token is revoked. Or wait until it exits by itself after 24 hours. Then revoke. The full order is on the Shai-Hulud page.

  1. Replace the credentials the machine could reach, from a clean device, right away if the file is not there, after step 2 if it is. Start with GitHub and npm tokens, then .env files and SSH keys, since payloads like the Nx one searched for exactly those. A token is the secret string that lets a program act as your account.
  2. Check the logs that show a secret being used, and follow leaked API key and the infostealer check for the detail.

02How a malicious npm package starts running

npm has lifecycle scripts, which are commands a package asks npm to run at certain points. In npm 11, preinstall, install and postinstall run after the modules are placed in node_modules, in order. If a package carries a hostile postinstall, the code runs with your user's permissions as soon as the install finishes. npm 12 blocks dependency install scripts by default until you approve them, while npm 11 still runs them by default.

Shai-Hulud worked this way: poisoned versions with a post-install script harvested data. The story and the check order are on the Shai-Hulud page.

You can switch scripts off. If the npm option ignore-scripts is true, npm does not run scripts specified in package.json files. That removes one route, not all of them, and some legitimate packages need their scripts to build. The setting is described in npm's config docs.

03Four ways a bad package gets in

Way inWhat it looks likeSign to look for
Lookalike nameA name one typo away from the real oneA name one letter off a package you know
Invented nameAn AI assistant suggests a package that does not exist, and an attacker registers itA package you never searched for, added by an assistant
Hijacked maintainerPhishing of a maintainer put crypto-stealing code in 18 or more packagesA new version of a trusted package with no change you can explain
A repo you were asked to runA fake recruiter tells you to clone and run an npm packageA "test task" that asks you to run code before reading it

Lookalike and invented names

Package names are easy to copy. A package called nodejs-smtp impersonated nodemailer. On import it unpacked the packed code file of the Atomic Wallet app, app.asar, and swapped one bundle for a malicious one. The mailer still sent email, so tests passed. This is typosquatting, covered in typosquatting. Registering a name an AI made up is slopsquatting. In one study 43% of hallucinated packages repeated on every rerun, so the same fake names come back. Vibe coders may never type or search for a package name by hand, so a suggested name goes straight into the install.

A hijacked maintainer

Here the package name is real. The attacker takes over the account that publishes it. In September 2025, phishing of one maintainer led to crypto-stealing code in 18 or more packages with over 2 billion weekly downloads. The code swapped the destination address in the browser in real time while still showing the original. When a real package gets a new version you did not expect, the name proves nothing.

A repo you were asked to run

Fake recruiters from crypto trading or AI firms tell victims to clone an npm package and run it. It is hosted on GitHub, GitLab or Bitbucket. If you open it in VS Code and trust the author, VS Code runs the task file that fetches the backdoor. Details are on fake job interview malware.

04What npm malware goes after

Most of it aims at secrets and money. Examples from reported cases:

05Signs of npm malware before you install

Few of these prove anything alone. Together they are a reason to stop.

  1. It has install scripts you did not expect. Read the scripts before you install. npm view takes a field name after the package and version, so npm view <package>@<version> scripts prints the scripts without installing anything.
  2. You did not choose it. A name that an assistant added, or one that sits one letter from a well-known package.
  3. It does its job anyway. Working code is not evidence of safety.
  4. Telemetry that is not yours. A call to an analytics endpoint that was never in your design.
  5. A missing signature on a registry that supports signatures. The CLI errors in that case, and npm says it could mean an attacker is trying to get around verification.

All the commands for these checks are on how to check an npm package for malware.

06Traces that npm malware already ran

After an install, look for traces rather than a package list.

07How to lower the odds

To see what a package script starts on your Mac, the free, open-source core of Artificial Immunity watches program starts and reports what it finds.

FAQ

What is npm malware?

It is hostile code shipped inside an npm package. One example is the Shai-Hulud payload, which harvested environment variables and ran TruffleHog to find secrets.

How does a malicious npm package run on my Mac?

Through a script that npm runs during install. npm 11 runs preinstall, install and postinstall scripts after it places modules in node_modules; npm 12 blocks dependency install scripts by default until you approve them.

Can I stop npm from running install scripts?

Yes. If the npm option ignore-scripts is true, npm does not run scripts specified in package.json files. Some packages need their scripts, so test your build afterwards.

Does a working package prove it is safe?

No. A malicious mailer package still sent email, so application tests passed and developers had little reason to doubt it.

Can an AI assistant suggest a malicious npm package?

It can suggest a name that does not exist, and an attacker can register it. In one study the average share of hallucinated package names was at least 5.2% for commercial models and 21.7% for open-source models.

What do I do if I installed one?

First look for the file ~/Library/LaunchAgents/com.user.gh-token-monitor.plist on the Mac. If it is not there, replace the secrets the machine could reach from a clean device. If it is there, read the order on the Shai-Hulud page before you revoke any GitHub token.

Sources

  1. npm docs, scripts
  2. npm docs, config
  3. npm docs, scopes
  4. npm docs, verifying registry signatures
  5. Wiz, Shai-Hulud
  6. Wiz, Mini Shai-Hulud
  7. Socket, wallet-stealing npm and PyPI packages
  8. Socket, nodejs-smtp impersonating nodemailer
  9. Socket, slopsquatting
  10. Socket glossary, dependency confusion
  11. Check Point, the great npm heist
  12. Microsoft, Contagious Interview
  13. Snyk, malicious postmark-mcp on npm
  14. Model Context Protocol, security best practices
  15. arXiv, package hallucination study
  16. Artificial Immunity
Agents install packages for you? Artificial Immunity watches the Mac where your agents work.Get the free core