The npm Worm That Turned Trusted Code Into a Global Credential-Hunting Machine

Listen to this Post

Featured ImageIntroduction: When a Routine Package Update Becomes an Enterprise Security Crisis

Modern software development depends on trust. Developers install open-source packages, automated pipelines download dependencies, and organizations assume that a familiar package name and a small version update are unlikely to cause serious harm. But a newly analyzed npm supply-chain campaign demonstrates how quickly that trust can be weaponized.

Microsoft Threat Intelligence identified a large-scale attack involving more than 400 npm packages linked to multiple unrelated publishers. The malicious releases reportedly carried a variant of the Mini Shai-Hulud worm, a self-propagating credential-stealing threat designed to execute before a package installation is even complete. Instead of waiting for a user to open a malicious file or manually run suspicious code, the malware abused npm lifecycle behavior to activate automatically through a preinstall hook.

The danger was not limited to one infected developer workstation. Once active, the malware searched for credentials connected to npm, GitHub, cloud platforms, Kubernetes environments, and secret-management systems. It could then use stolen publishing permissions to compromise additional packages, creating a worm-like cycle in which one stolen identity could lead to many new malicious releases.

This incident is a warning that software supply-chain security can no longer focus only on vulnerable dependencies. Organizations must also defend the identities, build systems, package registries, automated workflows, and release mechanisms that connect the modern development ecosystem.

The Main Story: More Than 400 Packages Pulled Into a Single Campaign

The campaign appeared as a rapid wave of unauthorized patch releases affecting more than 400 npm packages maintained by otherwise unrelated publishers. Many of the suspicious versions reportedly had no matching source-code commit, pull request, release tag, or visible development history.

That detail is especially important. It suggests that attackers may not have needed to compromise every public source repository individually. Instead, stolen publishing credentials could have allowed them to modify package archives directly and publish malicious versions under legitimate package identities.

For developers, the affected updates may have looked ordinary. A patch version usually implies a small fix, a maintenance improvement, or a low-risk change. In this campaign, however, a seemingly harmless version increase could conceal a credential-stealing payload.

The attack therefore exploited more than a technical weakness. It exploited the confidence developers place in familiar package names, trusted maintainers, and routine dependency updates.

The Silent Entry Point: Why the preinstall Hook Was So Dangerous

The malicious package versions reportedly added a preinstall lifecycle script that launched a file named setup.mjs. That loader then executed a large and heavily obfuscated JavaScript bundle associated with the Bun runtime.

Because npm lifecycle scripts can run during installation, the malicious code could begin operating before the installation process finished. This reduced the opportunity for application tests, dependency reviews, or conventional runtime monitoring to identify the threat.

A simplified example of the risky behavior looks like this:

{

scripts: {

preinstall: node setup.mjs

}
}

The presence of a lifecycle script does not automatically mean a package is malicious. Many legitimate packages use installation scripts. The security concern arises when an unexpected script appears in a new release, particularly when the release has no corresponding source-code change or when the script launches heavily obfuscated code.

The incident highlights an uncomfortable reality: package installation is not always a passive download operation. In some cases, installing a dependency can also mean executing code with access to the developer’s machine or the build environment.

Workstations and CI/CD Systems Faced Different Risks

The malware reportedly examined its environment to determine whether it was running on a developer workstation or inside a CI/CD system.

On a developer workstation, the payload could detach itself and continue operating in the background. This behavior may allow credential collection and persistence to continue after the original package installation ends.

Inside CI/CD environments, the malware reportedly remained connected to the active build job. That approach could provide access to workflow secrets, temporary credentials, deployment tokens, package-publishing permissions, and OpenID Connect identities.

CI/CD systems are especially attractive targets because they often sit at the center of the software delivery process. A single compromised runner may have access to source repositories, package registries, cloud environments, container registries, signing systems, and production deployment workflows.

An attack against a build pipeline can therefore become much larger than a compromise of one machine. It can threaten the integrity of the software produced by that machine.

Credential Theft: The Malware Looked Beyond Simple Token Files

According to the analysis, the payload collected information from environment variables, local files, shell histories, command-line tools, cloud configuration, SSH keys, and GitHub Actions runner memory.

The malware did not reportedly limit itself to searching for strings that resembled passwords or API keys. It also attempted to use discovered identities to authenticate to services and retrieve additional information that those identities were authorized to access.

This approach makes the threat more serious because a valid credential can act as a bridge. A token found on one workstation may provide access to a repository. That repository may expose workflow configuration. A workflow may contain permissions that lead to cloud resources or package-publishing capabilities.

The attack therefore followed identity relationships rather than treating each secret as an isolated target.

Cloud and Infrastructure Environments Became Part of the Attack Surface

The recovered payload reportedly included collectors for Amazon Web Services, Kubernetes, and HashiCorp Vault, among other services.

Once credentials were found, the malware could attempt to validate them, enumerate accessible resources, and retrieve secrets available to the compromised identity.

This matters because modern development environments are deeply interconnected. Developers frequently use cloud credentials locally, while CI/CD pipelines may receive temporary permissions automatically during builds.

A stolen identity does not need unrestricted administrative access to cause damage. Even a narrowly scoped credential may expose sensitive configuration, allow access to a package repository, modify a workflow, or reveal another credential with broader privileges.

The campaign demonstrates why least privilege must apply not only to human users but also to automated build identities and service accounts.

GitHub Access Could Expand the Attack Beyond npm

The malware reportedly validated discovered GitHub tokens, examined their permissions, and identified repositories where the compromised identity could make changes.

It also searched for repositories and workflows that might expose additional secrets or provide another route to package publication.

The campaign allegedly included the ability to inject files into configuration paths associated with Claude and Visual Studio Code, including:

.claude/settings.json

.claude/setup.mjs

.vscode/tasks.json

.vscode/setup.mjs

These modifications could create a secondary persistence mechanism. Future activity involving the affected development tools might restart the malicious payload even after the original npm installation had finished.

This is a notable shift in supply-chain attacks. The threat was not limited to a poisoned dependency. It reportedly attempted to move into the developer environment itself, where tools, repositories, and automation systems could become new channels for persistence and propagation.

GitHub Actions OIDC Could Make Malicious Releases Look Legitimate

One of the most concerning elements was the reported abuse of GitHub Actions OpenID Connect publishing workflows.

Trusted publishing is designed to reduce dependence on long-lived package tokens. Instead, an authorized workflow can receive a short-lived identity and publish a package through an approved process.

However, if attackers gain the ability to modify or control a legitimate workflow, the same trust mechanism can become an advantage for the attacker.

A malicious package published through a legitimate workflow identity may still carry valid provenance information because the release technically originated from an authorized automation environment.

This does not mean that trusted publishing is unsafe. It means that identity security and workflow integrity are essential to the trust model. Provenance can confirm where a release came from, but it cannot automatically prove that the authorized environment itself was not compromised.

Encrypted Exfiltration Made the Campaign Harder to Track

The collected information was reportedly serialized, compressed, and encrypted before transmission.

The payload used AES-256-GCM encryption with a randomly generated key and initialization vector. The encryption key was then protected using the attacker’s RSA public key.

This layered approach made the stolen data difficult to inspect if defenders intercepted the traffic.

The malware reportedly attempted to communicate with an attacker-controlled HTTPS endpoint and included fallback mechanisms involving GitHub repositories. In one fallback scenario, it could create a public repository and upload encrypted result files.

Using legitimate platforms as fallback infrastructure can complicate detection because defenders may be reluctant to block widely used services entirely.

The reported infrastructure also included the domains:

npm-cache[.]com

pypi-get[.]com

js-mirror[.]com

Organizations should treat these indicators as investigation leads rather than relying on them as a complete detection strategy. Infrastructure can change, and attackers may replace domains faster than security teams update blocklists.

The Worm Mechanism: One Stolen Token Could Poison Many Packages

The most dangerous feature was the malware’s automated propagation process.

After obtaining an npm publishing token, the payload reportedly checked whether the identity had permission to write to packages and whether available publishing capabilities could bypass or satisfy two-factor authentication requirements.

It then performed a sequence resembling the following:

Conceptual defensive model of the propagation chain

download-latest-package

extract-package-tarball

insert-malicious-loader

add-preinstall-hook

increment-patch-version

publish-modified-package

The actual campaign used malicious automation, but the sequence explains why the attack spread so rapidly.

A single compromised publisher account may control multiple packages. If the malware can automatically modify and republish every accessible package, one stolen credential can produce many malicious releases without the attacker manually preparing each one.

This behavior explains why suspicious versions could appear as ordinary patch updates without matching commits or pull requests.

The result is a supply-chain worm: compromised packages steal credentials, stolen credentials compromise more packages, and newly compromised packages expose more developers and build systems.

Why Patch Versions Became a Security Blind Spot

Developers often treat patch releases as low-risk updates. Semantic versioning encourages the idea that patch numbers represent backward-compatible fixes rather than major changes.

Attackers can exploit that expectation.

A version change from 1.4.7 to 1.4.8 may not attract the same scrutiny as a major upgrade. Automated dependency tools may install it quickly, CI systems may retrieve it without human review, and developers may assume that a familiar package remains trustworthy.

This campaign shows why version numbers cannot be used as a security signal.

A patch release should still be evaluated through provenance, source-code history, release timing, package integrity, and behavior during installation.

Deep Analysis: The Supply Chain Is Now an Identity Graph

The deeper lesson is that the modern software supply chain is no longer a simple chain.

It is an identity graph.

A developer identity may connect to GitHub.

GitHub may connect to CI/CD workflows.

Those workflows may connect to cloud infrastructure.

Cloud infrastructure may connect to secret stores.

Secret stores may provide credentials for package registries.

Package registries may distribute code to thousands of downstream environments.

An attacker who compromises one identity may be able to move through several of these relationships.

This is why traditional endpoint-only security is insufficient. A security team may detect suspicious JavaScript on a workstation but miss the unauthorized package publication that caused the infection. Another team may rotate the affected npm token but fail to inspect GitHub workflows or cloud credentials exposed during execution.

A complete response must examine the entire trust path.

The organization should ask:

Review package lifecycle scripts

npm view <package-name>@<version> scripts

Inspect the package archive before installation

npm pack <package-name>@<version>
tar -tf <package-name>-<version>.tgz

Review dependency relationships

npm ls --all

Identify outdated or unexpected dependencies

npm outdated

Check npm configuration

npm config list

Review lockfile changes

git diff -- package-lock.json

These commands are defensive inspection examples. They should be performed from a clean and controlled environment when investigating a suspected compromise.

Deep Analysis: Why CI/CD Runners Deserve the Highest Priority

CI/CD systems should be treated as high-value security assets rather than ordinary automation servers.

Build runners may contain temporary secrets that disappear after a job finishes. That can create a false sense of safety.

Temporary credentials are still dangerous while active.

If malware executes during the build window, it may use those credentials immediately to publish packages, access cloud resources, alter repositories, or retrieve additional secrets.

Organizations should therefore review:

Search workflow files for publishing and identity permissions

grep -R "id-token: write" .github/workflows/

Search for npm publication steps

grep -R "npm publish" .github/workflows/

Review recent workflow changes

git log -p -- .github/workflows/

Search for unexpected setup files

find . -type f ( -name "setup.mjs" -o -name "Math_.js" )

Inspect suspicious lifecycle hooks

grep -R

Security teams should also review workflow approvals, protected environments, branch protections, token scopes, and the identities allowed to publish packages.

Deep Analysis: Detection Must Combine Endpoint and Supply-Chain Evidence

A single indicator may not prove compromise.

A suspicious Node.js process may be legitimate.

A Bun process may be part of normal development.

A package patch release may be harmless.

However, several signals appearing together can create a strong case for investigation.

Examples include:

Unexpected package patch release

+

No matching source-code commit

+

New preinstall lifecycle hook

+

Node.js launching setup.mjs

+

Bun runtime executing obfuscated code

+

Cloud credential enumeration

+

Unexpected npm publication

Security teams should correlate endpoint telemetry with package-registry activity, repository changes, workflow execution, and cloud audit logs.

The strongest detections are likely to come from relationships between events rather than from a single malware hash.

Deep Analysis: Advanced Hunting Queries for Microsoft Defender XDR

Microsoft provided example hunting logic for identifying execution related to the malicious setup.mjs loader.

DeviceProcessEvents

| where Timestamp > ago(3d)
| where FileName in~ ("node", "node.exe")
| where ProcessCommandLine in~ ("node setup.mjs", "node setup.mjs")

Analysts can also look for Bun execution following the suspicious Node.js process:

DeviceProcessEvents

| where Timestamp > ago(3d)
| where InitiatingProcessFileName in~ ("node", "node.exe")
| where InitiatingProcessCommandLine in~ ("node setup.mjs", "node setup.mjs")
| where FileName in~ ("bun", "bun.exe")
| where FolderPath contains "bun-dl-"
or ProcessCommandLine has "node_modules"

To identify known malicious file hashes:

DeviceFileEvents

| where Timestamp > ago(3d)
| where SHA256 in~ (
"9fc2570b7cef51c1b8df116d144d11ff4096357be7d2c4c6367cfc2509cf1bcc",
"fd3ca4007b225fdf8de7af4345a19179d5efa8c4bb9205f88cda806e5684b1eb",
"54dc7ea54a1317cca0e890a2770630cf7fa6c97813e0cb9d2caa93012b350668"
)

These queries should be adapted to the organization’s environment and retained telemetry. A clean result does not automatically rule out compromise, especially if logs are incomplete or the malware has changed its filenames or execution pattern.

Immediate Response: Treat Affected Systems as Potentially Compromised

Organizations that installed an affected package with lifecycle scripts enabled should treat the associated workstation or build runner as potentially compromised.

The first priority should be containment and credential protection.

Recommended response actions include:

Stop using the affected environment for publishing or deployment
Do not rotate secrets from the potentially compromised host

Clear npm cache after collecting required forensic evidence

npm cache clean --force

Verify npm version

npm --version

Review installed dependency tree

npm ls --all

Search for suspicious files

find "$HOME" -type f \n( -name "Math_Symbol.js" -o -name "Math_init.js" -o -name "math_.js" ) \n2>/dev/null

Credential rotation should occur from a known-clean environment.

Security teams should consider rotating:

npm publishing tokens

GitHub personal access tokens

GitHub App credentials

Cloud access keys

Kubernetes credentials

HashiCorp Vault tokens

SSH keys

CI/CD secrets

Deployment credentials

Package-signing credentials

The order matters. Organizations should first understand which identities were exposed and then rotate credentials in a controlled sequence to avoid allowing attackers to reuse an overlooked credential.

Recovery: Rebuild Trust Instead of Only Cleaning Files

Deleting the visible malware is not enough.

If a compromised build runner created software artifacts, those artifacts may also be untrusted.

Organizations should rebuild affected projects from known-good dependency versions and trusted source states.

Shared CI caches should be purged.

Golden images and reusable build containers should be rebuilt.

Artifact repositories should be checked for compromised archives.

Package lockfiles should be reviewed for unauthorized version changes.

Release histories should be examined for unexpected patch publications.

Recovery should focus on restoring trust in the entire build process, not only restoring the affected machine.

What Undercode Say:

The Real Target Was Trust, Not Just Credentials

This campaign shows that attackers increasingly target the trust relationships that make software development efficient.

A Package Registry Can Become a Distribution Engine

When a trusted package is compromised, the attacker does not need to contact every victim individually.

One Legitimate Publisher Can Reach Thousands

A single publisher identity may control many packages and influence a large downstream ecosystem.

Lifecycle Scripts Need More Security Attention

Installation hooks are powerful because they can execute code before developers fully inspect the package.

Small Updates Can Carry Large Risks

A patch version should never be treated as automatically safe.

The Absence of a Source Commit Is a Critical Signal

A package release without a matching commit, pull request, or tag deserves immediate investigation.

CI/CD Systems Are Now Prime Attack Targets

Build systems often hold the permissions required to transform a local compromise into a supply-chain incident.

Temporary Credentials Are Still Valuable

Short-lived tokens can cause major damage if malware captures and uses them during their active window.

OIDC Improves Security but Does Not Remove Risk

Trusted publishing is valuable, but the workflow issuing the identity must also be protected.

Provenance Is Not a Complete Guarantee

A release can have valid provenance while the authorized publishing environment is compromised.

Identity Security Has Become Supply-Chain Security

Protecting developer and automation identities is now part of protecting the software itself.

Least Privilege Must Reach Every Workflow

Build jobs should receive only the permissions they require for the specific task.

Package Publishing Should Be Closely Monitored

Unexpected patch releases should trigger alerts, especially outside normal release schedules.

Security Teams Must Correlate Multiple Data Sources

Endpoint logs alone may not reveal the full attack.

Package Registries Need Behavioral Monitoring

Organizations should watch for unusual publishing patterns, not only known malicious hashes.

Developer Tools Can Become Persistence Channels

Configuration files for editors and AI-assisted development tools may become attractive targets.

AI Development Environments Need Security Governance

As AI coding tools become integrated into repositories, their configuration should be reviewed like executable automation.

Shared Caches Can Spread Compromise

A poisoned dependency cache can infect multiple builds after the original incident.

Golden Images Can Preserve Hidden Persistence

If a compromised image is reused, every future build may inherit the threat.

Credential Rotation Must Be Performed Cleanly

Rotating secrets from an infected machine may expose the replacement credentials.

Incident Response Must Include Release Integrity

Teams must verify what was produced during the compromise window.

Software Artifacts May Need Rebuilding

A clean endpoint does not guarantee that previously generated binaries are trustworthy.

Supply-Chain Defense Requires Multiple Layers

No single control can fully prevent this type of attack.

Dependency Pinning Reduces Surprise

Known-good versions can limit exposure to unexpected releases.

Release-Age Policies Can Slow Malicious Adoption

Delaying automatic installation of newly published packages can provide time for detection.

Maintainer Accounts Need Strong Protection

Publishing identities should use phishing-resistant authentication and minimal permissions.

Repository Changes Should Be Protected

Sensitive workflow and configuration files require strong review controls.

Automated Publishing Needs Anomaly Detection

A package release should be evaluated against normal publisher behavior.

Attackers Are Automating Their Own Operations

The worm reduced the need for manual package-by-package compromise.

Automation Increases Both Speed and Scale

A single stolen token can become an ecosystem-wide problem within a short period.

Detection Must Assume Indicators Will Change

Domains, filenames, and hashes can be replaced.

Behavior Is More Durable Than Infrastructure

Unexpected credential enumeration and package publication may remain useful detection signals.

Security Teams Need Package-Level Visibility

Organizations should know which packages are installed across development and production systems.

Open Source Trust Requires Continuous Verification

Trust should be monitored rather than granted permanently.

The Developer Workstation Is a Strategic Asset

It is no longer only a coding environment; it is often an identity and deployment hub.

Build Runners Need Strong Isolation

Sensitive publishing and deployment jobs should be separated from routine builds.

Secrets Should Be Narrowly Scoped

A compromised token should not automatically expose unrelated systems.

Incident Exercises Should Include npm Scenarios

Teams should practice package compromise, cache poisoning, and unauthorized publication response.

Supply-Chain Security Is Becoming Operational Security

The question is no longer only “Is this dependency vulnerable?”

The New Question Is “Who Can Publish It?”

Control of the publishing identity may be as important as control of the source code.

This Campaign May Influence Future npm Defenses

Registry-level release-age controls and stronger publisher monitoring may become more common.

The Industry Must Reduce Blind Trust

Automation should accelerate development without silently expanding attacker access.

✅ Microsoft Identified a Large npm Supply-Chain Campaign

The source states that Microsoft Threat Intelligence identified malicious releases affecting more than 400 npm packages associated with unrelated publishers.

The campaign reportedly involved a Mini Shai-Hulud variant delivered through heavily obfuscated Bun-based JavaScript.

The malware used npm lifecycle behavior to execute before package installation completed.

✅ The Malware Had Automated Worm-Like Propagation

The analysis describes a process in which stolen npm publishing access was used to download package tarballs, insert malicious components, increase patch versions, and republish the modified packages.

This capability could allow one compromised publisher identity to affect multiple packages.

The reported propagation model explains the rapid appearance of suspicious patch releases.

✅ The Threat Targeted Developer and CI/CD Credentials

The payload reportedly searched workstations and build environments for npm, GitHub, cloud, Kubernetes, and secret-management credentials.

It could use recovered identities to enumerate additional resources and retrieve accessible secrets.

This made the attack broader than a conventional package-based malware infection.

✅ Microsoft Recommended Credential Rotation and Clean Rebuilds

The source recommends rotating exposed credentials from a known-clean environment and rebuilding affected systems and downstream artifacts from trusted sources.

It also advises reviewing caches, dependency trees, package versions, and build integrity.

These recommendations reflect the possibility that the compromise could extend beyond the initially affected endpoint.

❌ A Clean Endpoint Scan Does Not Prove Full Recovery

The source does not support the assumption that removing one malicious file guarantees complete remediation.

Because the campaign involved credentials, package publication, repositories, CI/CD systems, and downstream artifacts, recovery requires broader validation.

Organizations should investigate identity exposure and release integrity rather than relying only on endpoint cleanup.

Prediction

(-1) Automated Supply-Chain Worms Will Become Faster and More Difficult to Contain

The next generation of package-registry attacks is likely to place greater emphasis on automation, identity abuse, and rapid propagation.

Attackers may increasingly use stolen publishing permissions to compromise multiple packages before maintainers or registries detect unusual activity.

AI-assisted coding environments, developer configuration files, and automated workflows may also become more attractive persistence and propagation targets.

Organizations that continue to treat package updates as passive downloads may face a growing risk of silent execution during installation.

The most effective defenses will likely combine delayed adoption of newly released dependencies, stronger publisher authentication, least-privilege CI/CD identities, protected workflow changes, package provenance verification, behavioral monitoring, and rapid credential rotation.

The long-term lesson is clear: the software supply chain is no longer protected only by reviewing code. It must be defended through continuous verification of the identities, systems, automation, and trust relationships that move code from a developer’s machine into the global ecosystem.

🕵️‍📝Let’s dive deep and fact‑check.

🎓 Live Courses & Certifications:

Join Undercode Academy for Verified Certifications

🚀 Request a Custom Project:

Secure, high-velocity infrastructure and disruptive technological engineering. Contact our engineering team for high-tier development and proprietary systems:
[email protected]
💎 Smart Architecture | 🛡️ Secure by Design | ⭐ Trusted by Thousands

References:

Reported By: www.microsoft.com
Extra Source Hub (Possible Sources for article):
https://www.medium.com
Wikipedia
OpenAi & Undercode AI

Image Source:

Unsplash
Undercode AI DI v2

🔐JOIN OUR CYBER WORLD [ CVE News • HackMonitor • UndercodeNews ]

💬 Whatsapp | 💬 Telegram

📢 Follow UndercodeNews & Stay Tuned:

𝕏 formerly Twitter 🐦 | @ Threads | 🔗 Linkedin | 🦋BlueSky | 🐘Mastodon | 📺Youtube