npm malware: how malicious packages get onto your Mac
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.
- Look for the trap file. Run
ls ~/Library/LaunchAgents/com.user.gh-token-monitor.plistin Terminal. If it prints the path, the file is there. That variant installs a background program that polls GitHub and tries to runrm -rf ~/, which deletes your home folder, when the token it checks is revoked. - 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.plistThe 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.
- 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
.envfiles 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. - 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 in | What it looks like | Sign to look for |
|---|---|---|
| Lookalike name | A name one typo away from the real one | A name one letter off a package you know |
| Invented name | An AI assistant suggests a package that does not exist, and an attacker registers it | A package you never searched for, added by an assistant |
| Hijacked maintainer | Phishing of a maintainer put crypto-stealing code in 18 or more packages | A new version of a trusted package with no change you can explain |
| A repo you were asked to run | A fake recruiter tells you to clone and run an npm package | A "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:
- Environment variables and secrets found with TruffleHog, a secret scanner.
- Wallets, keystores,
.envfiles and SSH keys on Linux and macOS. - Seed phrases and private keys. One package sent wallet keys to a Google Analytics endpoint disguised as telemetry.
- Email contents. The postmark-mcp package was reportedly changed to add a blind copy to an outside address.
- npm tokens and GitHub credentials, taken by the GlassWorm editor extensions.
05Signs of npm malware before you install
Few of these prove anything alone. Together they are a reason to stop.
- It has install scripts you did not expect. Read the scripts before you install.
npm viewtakes a field name after the package and version, sonpm view <package>@<version> scriptsprints the scripts without installing anything. - You did not choose it. A name that an assistant added, or one that sits one letter from a well-known package.
- It does its job anyway. Working code is not evidence of safety.
- Telemetry that is not yours. A call to an analytics endpoint that was never in your design.
- 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.
- A public repo in your GitHub account named Shai-Hulud. Open your profile, go to Repositories and search for the name. The first Shai-Hulud wave sent data to repos with that name.
- The trap file from step 1 above.
ls ~/Library/LaunchAgentslists every background job you have. Anything you did not install deserves a look. - Odd activity on your accounts. If a token may have been used, look at the account's logs or audit trail for signs that someone used it.
07How to lower the odds
- Review what an agent adds. Auto mode in Claude Code allows installing dependencies declared in lock files or manifests by default. A lock file is where npm records exact versions.
- Do not run unreviewed repos from strangers, and do not trust a folder just because someone sent it.
- Install only versions that have been public for some days. The npm option
min-release-agedoes that; it is in the same config docs.
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.
Related guides
Sources
- npm docs, scripts
- npm docs, config
- npm docs, scopes
- npm docs, verifying registry signatures
- Wiz, Shai-Hulud
- Wiz, Mini Shai-Hulud
- Socket, wallet-stealing npm and PyPI packages
- Socket, nodejs-smtp impersonating nodemailer
- Socket, slopsquatting
- Socket glossary, dependency confusion
- Check Point, the great npm heist
- Microsoft, Contagious Interview
- Snyk, malicious postmark-mcp on npm
- Model Context Protocol, security best practices
- arXiv, package hallucination study
- Artificial Immunity