Most of Your Code Isn't Yours: npm Package Hijacking and AI Coding Tools
Most of a web service's code is packages written by others. Since Shai-Hulud in September 2025, attacks swapping npm packages for malicious versions continue, now also targeting AI coding tools and MCP servers. Using official npm and GitHub sources, we explain what's happening and what to check.

On this page
- Key Points
- What Happened
- Shai-Hulud (September 2025)
- AI Coding Tools Are Being Targeted
- Publishing Through the Official Process Doesn't Guarantee Safety
- How This Differs from Handling Vulnerabilities
- Changes on the npm Side, and Settings You Can Use
- pnpm as an Option
- What People Responsible for Services Should Check
- December 3: More Details in Our Webinar
When a team builds a web service, only a small part of the code is written from scratch. Features like login, date calculations, and UI components are mostly built by combining packages that developers around the world have published. In the JavaScript world, the place that distributes those packages is npm.
Since September 2025, attacks that swap these packages themselves for malicious ones have continued. Unlike attacks that exploit a vulnerability (a flaw in how something is built), a new version of a legitimate package ships with a theft mechanism built in from the start. Recently, AI coding tools and their extensions (MCP servers) have become targets as well.
Based on official announcements from npm and GitHub, an advisory from the U.S. CISA, and analyses by security firms as of November 23, 2026, this article explains what is happening and what people responsible for services at businesses should check.
Key Points
- Attackers steal package authors' accounts or publishing keys and publish versions of legitimate packages with a theft mechanism inside. These versions steal keys from the PCs and build environments of whoever installs them, then use those keys to taint other packages and spread.
- AI coding tools have been used as instruments of theft, and fake MCP servers have been added to their configurations. In one case, the MCP server itself was a fake.
- The core defenses are pinning the versions you use, not installing just-published versions right away, and not holding publishing keys for long. Since fall 2025, npm has been changing its defaults in this direction.
What Happened
Shai-Hulud (September 2025)
npm was acquired by GitHub in 2020 and is now operated by GitHub. GitHub announced that on September 14, 2025, it received a report of an attack called Shai-Hulud and removed more than 500 compromised packages. The U.S. CISA (Cybersecurity and Infrastructure Security Agency) also issued an alert on September 23.
A self-replicating worm—publicly known as “Shai-Hulud”—has compromised over 500 packages.
Source: CISA, "Widespread Supply Chain Compromise Impacting npm Ecosystem"
According to CISA, it works as follows. In any environment where a compromised package is installed, it searches for and steals GitHub and cloud keys, then uses the stolen npm permissions to inject the same code into that developer's other packages and publish them. Because it spreads without human involvement, it is called a "worm" (something that replicates itself).
In November, Shai-Hulud 2.0 appeared. Datadog's analysis found that 796 packages were hijacked, with combined weekly downloads exceeding 20 million.
Variants have continued since then. According to Sonatype, a new wave (Mini Shai-Hulud) started from the keyv and cacheable packages on August 4, 2026, affecting 2,225 versions.
AI Coding Tools Are Being Targeted
What stands out over the past year is that AI coding tools have been built into attacks.
Having AI search for secrets. In August 2025, compromised versions of the build tool Nx invoked the AI command-line tools installed on developers' PCs (Claude, Gemini, Q) and had them search for keys and secret files (according to Socket's analysis). Instead of writing their own search code, the attackers asked the developers' AI to do it.
The MCP server itself was fake. An MCP server is a component that adds capabilities such as sending email or searching data to AI tools. postmark-mcp, discovered in September 2025, was a fake posing as an MCP server for the email delivery service Postmark. Postmark explained that after the fake built up trust over 15 versions, version 1.0.16 added a mechanism to BCC every sent email to an outside address. According to Koi Security, which discovered it, it was downloaded about 1,500 times a week. Postmark itself had nothing to do with this package.
Rewriting AI tool settings. SANDWORM_MODE, disclosed by Socket in February 2026, consisted of at least 19 malicious packages, three of which impersonated Claude Code. Once installed, it looks for the settings of Claude Code, Claude Desktop, Cursor, Continue for VS Code, and Windsurf on the PC and adds a fake MCP server. From then on, every time the developer asks the AI to do something, the fake server runs alongside it.
AI coding tools run on developers' PCs with broad permissions. That is why the tools themselves, and the components that extend them, can become both the entry point and the exit point for theft.
Publishing Through the Official Process Doesn't Guarantee Safety
There was a new example in November 2026 as well. According to StepSecurity, between November 15 and 16, two npm versions of WPPConnect, a library for WhatsApp, contained a mechanism that sent environment variables and configuration files to an outside server.
These versions were published from the project's own build, using the recommended "trusted publishing" mechanism described later. In other words, an unreviewed commit went straight through the legitimate process.
Valid publishing credentials did not mean reviewed code.
Source: StepSecurity
How This Differs from Handling Vulnerabilities
| Vulnerability | Package hijacking | |
|---|---|---|
| Where the problem is | A flaw in legitimate code | Malicious code inserted into a new version |
| When damage occurs | When attacked from outside | When you install (update) the package |
| Main damage | The server is taken over | Keys on developer PCs and build environments are stolen, and it spreads from there |
| Basic response | Update to the latest version right away | Don't install just-published versions right away. If you installed one, recreate every key |
For vulnerabilities, "update right away" was the right answer. With package hijacking, the faster you update, the more danger you're in. The settings in the next section let you balance the two.
Changes on the npm Side, and Settings You Can Use
In response to Shai-Hulud, GitHub has been changing npm's publishing system step by step.
- On December 9, 2025, it revoked all old-style tokens with no expiration (classic tokens). npm login sessions now expire after two hours, and tokens with write access are limited to a maximum of 90 days.
- In npm v12, generally available on July 8, 2026, scripts that used to run automatically on install (preinstall, install, postinstall) no longer run unless allowed. Shai-Hulud 2.0 also ran via the preinstall mechanism.
- Tokens that bypass 2FA are scheduled to lose the ability to publish directly around January 2027.
Settings that development teams can use are also now in place.
| Measure | Official setting | What it prevents |
|---|---|---|
| Pin versions | Manage a lockfile (package-lock.json, etc.) and use npm ci in builds | Prevents new versions from slipping in unnoticed. npm ci stops instead of rewriting if it disagrees with the lockfile |
| Don't install just-published versions | npm's min-release-age (days), pnpm's minimumReleaseAge (minutes; current default is 1440 minutes = 1 day) | Prevents installing a compromised version in the window before it is found and removed |
| Block install-time scripts | npm v12 default (only scripts allowed via allow-scripts run), ignore-scripts | Prevents theft code from running the moment a package is installed |
| Don't hold publishing keys for long | Trusted publishing (OIDC), 2FA, short-lived tokens | Prevents stolen keys from being used to taint other packages |
pnpm's official documentation explains why waiting helps:
In most cases, malicious releases are discovered and removed from the registry within an hour.
Source: pnpm official documentation
However, a setting that avoids recently published versions also delays urgent security fixes. npm's documentation also says that when a fix is too new to install, you should register it as an exception. You need to decide, together, the procedure for installing vulnerability fixes and who decides on exceptions.
pnpm as an Option
pnpm, a package manager (a tool for installing packages) that can be used instead of npm, has many of the measures above enabled from the start. Here is how its defaults compare with npm v12 (based on each project's official documentation as of November 23, 2026).
| Measure | pnpm default | npm v12 default |
|---|---|---|
| Don't install just-published versions | Waits 1 day (1440 minutes) (minimumReleaseAge) | Doesn't wait. You set min-release-age yourself |
| Block install-time scripts | If any package has a script that isn't allowed, the install itself stops (strictDepBuilds) | Only allowed scripts run (npm v12) |
| Don't pull dependencies of dependencies from git or other external sources | Allowed only for direct dependencies (blockExoticSubdeps) | No equivalent default restriction |
| Don't install versions published by a weaker method than the previous one | Can be rejected by setting trustPolicy: no-downgrade | No equivalent setting |
The most effective point is that the one-day wait after publication is built in from the start. As quoted above, most compromised versions are found and removed within an hour, so simply waiting a day avoids most of them.
That said, pnpm fetches packages from the same npm registry. It doesn't stop hijacked packages themselves; the difference is that "delay installation" and "don't run things automatically" work by default. Nearly the same settings are possible with npm, so the difference is "safe by default, or configured by you."
Switching also takes effort. The lockfile format changes, and CI and build settings need to be updated. Code that implicitly relied on other packages may stop working under pnpm's stricter way of laying out packages.
So the practical approach is to choose pnpm for new services, and for services already running on npm, start by setting min-release-age.
What People Responsible for Services Should Check
Whether you develop in-house or outsource, you'll want to be able to answer the following.
| What to check | Why it matters |
|---|---|
| Is the list of packages and versions in use (the lockfile) managed, and do production builds install exactly that? | It is the starting point for checking "does this news affect us?" CISA also recommends checking with the lockfile |
| Which package manager is used (npm or pnpm), and is a setting in place to avoid recently published versions? | pnpm waits 1 day by default, but npm doesn't wait unless configured |
| Is there a setting to avoid just-published versions, plus a way to decide exceptions when urgent fixes must go in? | Balances preparing for hijacking with applying vulnerability fixes |
| Is there a list of the tokens and keys used in development and builds, and a procedure to recreate them? | If a compromised version is installed, assume every key within reach was stolen and recreate them all |
| Who chooses the AI coding tools and MCP servers used on developer PCs, and where are they installed from? | AI tool settings and extensions have become entry and exit points for theft |
| Are production keys kept on your contractor's developer PCs or build environments? | If a developer PC is compromised, the keys on it are carried off as-is |
| If your company publishes packages to npm, has it moved to trusted publishing and 2FA? | Keeps your own packages from becoming the entry point for the next infection |
Even if you didn't write most of the code, you can decide which packages go in and when. What matters is deciding the packages and versions you install, and keeping a record of those decisions.
December 3: More Details in Our Webinar
Using vulnerability news like the cases in this article as examples, we'll cover everything from vulnerability basics to how to prepare your own services in a free 30-minute webinar (held in Japanese).
What Is a "Vulnerability," Really? Checkpoints for Your Own Services, Drawn from Real News
- Date and time: Thursday, December 3, 2026, 12:15–12:45 JST (lunchtime session; join or leave anytime)
- Format: Online (Zoom), free of charge
- Topics: What is a vulnerability, really? / Why is it in the news so much lately? / How to prepare when you see the news
- For: People at businesses responsible for their company's services or systems
- Bonus: All registrants receive the day's slides, and those who answer the survey receive a checklist of what to check when you see vulnerability news
You can also submit questions in advance through the registration form, such as "Does the vulnerability in this article affect us?"
Webinar details / Register here
Vitalify Asia develops web and mobile services and operates them after release. We have experience with the kinds of work described in this article: updating the software services rely on, responding to vulnerabilities, and reviewing operational setups. If you have any concerns about preparing your services for vulnerabilities, please feel free to contact us.
Since 2008, VFA has been involved in more than 1,000 development projects. Some of our work is not publicly listed, so please feel free to contact us for details.
Vitalify Asia's development portfolio
This article is based on official announcements and documentation from npm and GitHub, CISA's advisory, and analyses by Socket, Datadog, Sonatype, and StepSecurity. Each service's specifications are continuously updated. The content of this article is current as of November 23, 2026.
Vitalify Asia Co., Ltd. https://vitalify.asia/
Struggling to turn ideas into reality? With a proven track record of over 1,000 clients, our agile and flexible team will accelerate your business growth.


