Inside the Modern npm Supply Chain Breach: How Attackers Hijacked CI/CD Pipelines and Trusted Publishing
A technical analysis of malicious npm packages reveals how threat actors transitioned from token theft to CI/CD pipeline compromise, evading script filters and weaponizing trusted publishing.

What happened
In recent ecosystem analyses, the JavaScript open-source landscape demonstrated a structural shift in how malicious code reaches production systems. Observations across thousands of confirmed malicious npm packages published following registry-wide initiatives to deprecate static authentication tokens show that threat actors have systematically adapted their techniques. Rather than relying on credential stuffing or static token theft, attackers migrated upstream into continuous integration (CI) environments and release automation workflows.
The research uncovers a stark divergence between malware distribution volume and actual real-world exposure. The overwhelming majority of cataloged malicious packages were net-new, attacker-created packages that generated only a minuscule fraction of recorded downloads. Conversely, compromised legitimate packages accounted for a small minority of identified malicious packages, but generated the vast majority of total recorded downloads. The blast radius of the ecosystem remains heavily concentrated in legitimate, established libraries that are hijacked by adversaries.
This shift in adversary targeting coincided with widespread architectural evasion of registry-level protections. Following the deprecation of static tokens and the broader adoption of OIDC-based trusted publishing workflows, threat actors responded by targeting developer CI environments directly to leverage automated publication roles. Among malicious packages observed utilizing trusted publishing mechanisms, the clear majority were legitimate projects compromised directly at the pipeline level.
Simultaneously, traditional package vulnerabilities continued to provide entry points into these environments. Disclosures highlighting critical JavaScript code injection vulnerabilities in widely deployed binary parsing utilities demonstrated how parser definition flaws allow attackers to inject arbitrary code directly into Node.js runtime environments through unsanitized dynamic code-generation parameters.
Why this pattern keeps repeating
Software supply chain attacks continue to succeed because security controls are frequently applied at the wrong layer of the dependency lifecycle. Enterprise defensive postures have historically relied on repository-level static scanning and blocking lifecycle scripts during package installation. However, adversary tactics have evolved past these assumptions, targeting the trust boundary between source code repositories and package registries.
The widespread adoption of OIDC trusted publishing was intended to eliminate the risks associated with static authentication secrets stored in repository settings. While this removed the threat of leaked long-lived tokens, it concentrated risk inside the build runner. If an adversary compromises the continuous integration environment—via compromised build dependencies, workflow misconfigurations, or stolen pipeline credentials—they inherit valid, short-lived publication tokens. The package registry receives a cryptographically valid assertion from a trusted provider and distributes the backdoored release under a trusted namespace.
As security controls increasingly focus on token management and install-time scripts, threat actors adapt by relocating upstream into build environments and deferring malicious activity until application runtime.
Furthermore, developer tooling and execution contexts have expanded faster than corresponding visibility controls. Research identifies an emerging attack surface specifically targeting artificial intelligence development workflows. Malicious npm packages have been observed delivering compromised Model Context Protocol (MCP) servers, altering AI assistant configurations, and harvesting API keys for cloud AI services. Because developer machines and build hosts maintain permissive outbound network egress to support rapid deployment, injected packages can exfiltrate sensitive configuration data immediately upon execution.
The attacker's playbook step-by-step
Modern supply chain compromises follow a systematic execution lifecycle designed to circumvent traditional software composition analysis (SCA) and install-time safeguards.
Step 1: Upstream Pipeline Compromise and Ingress
Rather than attempting to publish typo-squatted packages that yield low installation counts, the attacker identifies maintained packages with existing download velocity. The adversary penetrates the project's continuous integration pipeline or development environment. This is achieved through compromised build-time dependencies, runner misconfigurations, or underlying code injection flaws in parsing and build-time libraries where unsanitized inputs permit arbitrary JavaScript execution inside the host process.
Step 2: Weaponizing Trusted Publishing
Once inside the runner, the attacker does not need to extract static registry secrets. Instead, the adversary triggers or modifies the legitimate deployment workflow. Because the repository is configured for OIDC trusted publishing, the runner requests a short-lived token directly from the package registry using the provider's signed identity token. The attacker injects the malicious payload into the release artifacts before the publish step executes, resulting in an authentic, registry-signed release.
Step 3: Evading Install-Script Controls
Historically, defenders relied on flags like --ignore-scripts to mitigate malicious lifecycle hooks. In observed campaigns, a substantial portion of malicious packages declared no lifecycle scripts (preinstall, install, or postinstall) whatsoever, deferring execution until the package was explicitly imported or invoked by the host application. In notable large-scale operations targeting enterprise environments, attackers systematically minimized lifecycle script usage, alternating between postinstall hooks and import-time execution across successive release waves to defeat static detection.
Step 4: Execution and Propagation
When a downstream consumer installs or imports the compromised package, the payload activates. In developer environments, the malware harvests cloud identity tokens, pipeline secrets, and AI assistant configurations. In advanced campaigns, the malware attempts broader lateral movement, seeking additional environment credentials and access points across connected developer tooling and automated workflows.
What defenders missed
Defenders across the industry consistently misjudged the operational realities of how modern npm malware executes and establishes persistence. The primary failure was an over-reliance on lifecycle script blocking as a standalone control. Teams operating on the assumption that --ignore-scripts neutralizes installation risks remained vulnerable to the large portion of malware designed to execute exclusively upon runtime import.
Second, security operations teams treated OIDC trusted publishing as an absolute security boundary rather than an identity federation mechanism. Trusted publishing successfully prevents the exfiltration of static credentials, but it inherently trusts any build execution running within the specified repository context. When build runners lack integrity verification, the registry cannot distinguish between an authorized release and an adversary-controlled pipeline execution.
Third, static code analysis tools frequently failed to account for dynamic code generation vulnerabilities embedded within deep dependencies. Input validation failures inside runtime code generators often evade regular dependency audits, particularly when dynamic parser compilation logic directly concatenates user-controlled properties into executable runtime code without sufficient sanitization.
Finally, monitoring architectures suffered from severe blind spots regarding AI infrastructure components. Security teams actively monitored standard shell history and environment variables, but lacked observability into local AI assistant configurations and MCP server endpoints. Attackers capitalized on these untracked files to extract service credentials and manipulate automated developer tooling without alerting security information and event management (SIEM) systems.
A practical defensive checklist
Security engineers and enterprise architects should implement the following technical controls across development environments, build systems, and deployment pipelines:
- Isolate CI/CD Build Runners and Ephemeral Jobs: Execute all artifact builds in hardened, single-use ephemeral virtual machines with strict network egress controls to prevent malicious dependencies from contacting external command-and-control servers during compilation.
- Enforce Pipeline Integrity Before OIDC Token Exchange: Require cryptographic verification of all source files, build scripts, and dependencies prior to invoking package trusted publishing actions, ensuring that uncommitted changes cannot be bundled into release archives.
- Audit Code Generation in Transitive Dependencies: Scan application codebases and dependency trees for packages that construct dynamic execution logic from untrusted input, ensuring parsing libraries are regularly updated to mitigate arbitrary code execution risks.
- Implement Runtime Import Controls and Process Sandboxing: Do not rely exclusively on
--ignore-scripts; deploy runtime security policies that monitor and restrict unexpected Node.js child process spawns and outbound network calls initiated during application bootstrap. - Monitor AI Tooling and MCP Configurations: Implement file integrity monitoring and endpoint detection rules covering AI assistant configuration directories, MCP server definitions, and local developer environment variables containing AI platform API keys.
- Restrict Package Installation Sources: Enforce internal artifact registries with quarantine proxies that prevent the automatic retrieval of newly published package versions until automated dynamic analysis has verified package behavior.
How modern offensive testing would have caught this
Traditional application security testing relies heavily on static dependency manifests and periodic software composition scans. These mechanisms fail to catch supply chain attacks where legitimate packages are hijacked through trusted build pipelines or when payloads execute dynamically at import time. Automated offensive testing platforms provide autonomous validation with executable proof-of-concept evaluations, simulating the precise attack vectors that adversaries exploit inside automated environments.
By executing autonomous attack simulations within developer environments and continuous integration pipelines, offensive testing platforms actively evaluate whether short-lived OIDC tokens and build processes can be hijacked to stage unauthorized releases. Rather than simply alerting on package version strings, these tools assess real-world execution paths to demonstrate how unsanitized parameters in dependencies lead to code injection inside running workloads.
Furthermore, modern offensive platforms evaluate the exposure of runtime configurations, AI assistant settings, and CI runner isolation policies against dynamic execution payloads. By producing validated proof of impact, autonomous offensive testing enables security engineering teams to identify permissive pipeline permissions, unmonitored scriptless package imports, and transitive injection vulnerabilities long before an adversary can weaponize them across production software chains.
What to watch next
The software supply chain threat landscape is moving toward deeper automation and tighter exploitation loops. As long-lived tokens continue to disappear from development workflows, adversaries will refine automated techniques to target build runner runtimes directly. The risk of automated propagation highlights how quickly compromised build hosts can be leveraged to distribute backdoored artifacts across public registries.
Defenders must also monitor the evolving attack surface presented by local developer tooling and AI orchestration frameworks. As development teams integrate automated AI assistants and MCP servers into daily workflows, threat actors will increasingly tailor supply chain payloads to tamper with prompt contexts, hijack tool execution parameters, and exfiltrate specialized service keys. Supply chain security can no longer terminate at the dependency manifest; it must encompass continuous validation across build environments, package release pipelines, and runtime execution contexts.
Bài đọc liên quan

Anatomy of an Exposed Cloud Bucket: How Misconfigured Permissions Leak Customer PII
Cloud storage misconfigurations continue to expose customer PII, health records, and proprietary databases. Here is a technical breakdown of how permission flaws occur and how security teams can prevent them.

When Supply Chains Turn Wormable: Deconstructing Modern npm Dependency Threats
A weaponized package release targeting developer environments exposes the escalating risks of wormable, developer-focused software supply chain attacks.

The Collapsing Patch Window: Navigating Critical RCEs in Popular Frameworks
Critical Remote Code Execution (RCE) vulnerabilities in widely adopted frameworks continue to pose an existential threat. This deep dive analyzes a recent incident pattern, dissecting the implications for enterprise security and outlining a proactive defense strategy against a landscape where patch windows are shrinking and exploitation is accelerating.
