Panda Mirror: How the Chinese CCP manipulates NPM to horde malware

Paul McCarty (Head of Research · Safety)

BSides Canberra VIII (2025) · Day 3 · Off-Main Track

Overview

In a revealing and urgent presentation at BSides Canberra, Paul McCarty unveiled a critical vulnerability in the global software supply chain, demonstrating how Chinese NPM mirrors have been deliberately configured to retain and serve deleted malicious packages. This talk, titled "Panda Mirror," exposed a systemic flaw that not only undermines the integrity of the world's largest software registry but also raises serious questions about potential state-sponsored hoarding of malware. McCarty, a seasoned security researcher and Head of Research at Safety, presented compelling evidence that five of the eight global NPM mirrors, all located in China, do not comply with deletion events from the central registry, effectively creating a hidden repository of previously identified threats.

Watch on YouTube

Visual summary for Panda Mirror: How the Chinese CCP manipulates NPM to horde malware by Paul McCarty
Visual summary for Panda Mirror: How the Chinese CCP manipulates NPM to horde malware by Paul McCarty

Key moments

  1. 0:00 Welcome and NPM's massive, insecure ecosystem
  2. 4:50 62.5% of global NPM mirrors are in China
  3. 6:25 NPM's inherent security flaws: RCE by design
  4. 14:15 China's RMSV: Disclose vulnerabilities to government first
  5. 16:40 Chinese NPM mirrors deliberately store deleted malware
  6. 18:10 How to download previously deleted malicious packages
  7. 20:45 Collecting unseen NPM malware for threat hunting
  8. 24:50 Speaker's theory on why Chinese mirrors hoard malware

Panda Mirror: How the Chinese CCP manipulates NPM to horde malware

Speakers: Paul McCarty, Head of Research, Safety

Conference: BSides Canberra

YouTube: https://www.youtube.com/watch?v=oBzG7XOByII

Overview

In a revealing and urgent presentation at BSides Canberra, Paul McCarty unveiled a critical vulnerability in the global software supply chain, demonstrating how Chinese NPM mirrors have been deliberately configured to retain and serve deleted malicious packages. This talk, titled "Panda Mirror," exposed a systemic flaw that not only undermines the integrity of the world's largest software registry but also raises serious questions about potential state-sponsored hoarding of malware. McCarty, a seasoned security researcher and Head of Research at Safety, presented compelling evidence that five of the eight global NPM mirrors, all located in China, do not comply with deletion events from the central registry, effectively creating a hidden repository of previously identified threats.

McCarty's findings highlight a significant and underappreciated risk within the open-source ecosystem. Given that NPM (Node Package Manager) hosts 98.5% of all malicious packages observed by Sonatype and that the average JavaScript project relies on over 1000 indirect dependencies, the implications of these rogue mirrors are profound. The ability for threat actors, potentially backed by a nation-state, to access and weaponize malware that the broader security community believes has been eradicated presents a severe challenge to global cybersecurity. This talk not only exposed a novel supply chain attack vector but also provided a blueprint for how security researchers can leverage such anomalies for advanced threat intelligence gathering.

The core of McCarty's investigation centers on the inconsistent behavior of NPM mirrors, particularly those operating within China's digital infrastructure. He detailed how specific Chinese mirrors continue to serve packages that have been either officially marked as malicious by NPM and replaced with placeholders, or privately deleted by their authors. This divergence from standard registry protocols allows for the persistent availability of harmful code, creating a unique opportunity for sophisticated adversaries to collect, analyze, and potentially redeploy these threats. The talk underscored the urgent need for greater transparency and stricter enforcement of security policies across all components of the global software supply chain.

Background

▶ Watch: Welcome and NPM's massive, insecure ecosystem (0:00)

The context for McCarty's findings lies in the immense scale and inherent insecurities of the NPM registry. As the world's largest software registry, NPM handles an astonishing 134,000 updates daily, with the vast majority being new versions of existing packages. It dwarfs other registries like Maven and PyPI by several factors. Despite its ubiquity, McCarty has long criticized NPM for its security posture, a sentiment seemingly validated by recent high-profile supply chain incidents. A Sonatype study revealed that 98.5% of all malicious packages they tracked were hosted or served by NPM, far outstripping other registries. This problem is compounded by JavaScript's promiscuous dependency model; GitHub data indicates the average JavaScript project has 10 direct and over 683 indirect dependencies, a number McCarty notes has now climbed to over a thousand. This exponential increase in dependencies significantly expands the attack surface, making the impact of malicious packages far-reaching.

Several factors contribute to NPM's vulnerability. Firstly, it still allows install scripts (pre and post-install), which essentially enable Remote Code Execution (RCE) by design, a perfect mechanism for attackers. Secondly, the ease of access for publishing packages is alarmingly low; users can sign up with just an email and publish packages within minutes, with minimal validation. Thirdly, JavaScript payloads often bypass conventional security tools, including traditional infosec tools like EDR and antivirus, as well as appsec tools like SAST and SCA, which are not designed to identify malicious packages effectively. McCarty's prior talks, including one at Defcon, delve deeper into these systemic issues.

The problem is further exacerbated by the mechanisms (or lack thereof) for removing malicious packages. Historically, reporting a malicious package to OSV.dev (Google and OpenSSF's open-source vulnerability database) would take 3-4 days to result in an NPM deletion. Direct disclosure to NPM itself was even slower, famously taking five and a half months for a package like express.exp to be removed, leaving users vulnerable for an extended period. While recent events have improved this to a few hours, the historical sluggishness created ample opportunities for malware to persist. NPM's internal team also identifies and removes malicious packages, replacing all versions with a 0.0.1-security placeholder to prevent name reuse, but they do so quietly, often without detailed public advisories (using "terrible" GHSA advisories, as McCarty puts it).

A more recent and concerning trend is malicious authors self-deleting their packages. While this might seem beneficial, it unintentionally breaks NPM's automation, often preventing the creation of public advisories and, crucially, allowing the attacker to reuse the package name in the future. This tactic also serves to obscure the payload, limiting analysis by security researchers.

Against this backdrop, McCarty introduced a geopolitical dimension: the Regulations on the Management of Network Product Security and Vulnerabilities (RMSV), a Chinese government rule mandating that vulnerabilities found in China must first be disclosed to the government, not publicly. The Atlantic Council's white paper, "Slight of Hand: How China Weaponizes Software Vulnerabilities," details how China's internal vulnerability database (which requires Chinese citizenship and phone number for access) acts as a collection mechanism, funneling vulnerability data to government departments for potential offensive security work, rather than sharing it for defensive purposes like other national vulnerability databases (e.g., NVD). This context sets the stage for McCarty's discovery of the unique behavior of Chinese NPM mirrors.

Key Findings

▶ Watch: NPM's inherent security flaws: RCE by design (6:25)

Paul McCarty's central discovery is that Chinese NPM mirrors are intentionally modified to store and serve deleted malicious packages, creating a persistent reservoir of threats that are otherwise removed from the global software supply chain. This finding is particularly alarming given the sheer scale of NPM and the strategic implications of such an archive.

Specifically, McCarty found that five of the eight global NPM mirrors are located in China, representing a staggering 62.5% of the total. More critically, three of these Chinese mirrors — Tencent server, npmir.com, and CNPMJS — consistently exhibited this non-compliant behavior. While the main NPM registry and other global mirrors adhere to deletion protocols, these Chinese counterparts do not.

The key findings can be summarized as follows:

  1. Retention of NPM-deleted packages: When NPM's internal team identifies all versions of a package as malicious, they typically replace them with a 0.0.1-security placeholder version. McCarty demonstrated that the Tencent server, which uses Verdaccio (an NPM mechanism, not CouchDB) and is hosted on an Alibaba Cloud CDN, often continues to serve the original malicious versions of these packages. This means that while the global registry indicates a package is safe (or replaced), the malicious variant remains available through the Tencent mirror.
  2. Retention of author-deleted packages: When a malicious author self-deletes a package, the main NPM registry typically returns a 404 error or an "unpublished" message, indicating the package is no longer available. However, McCarty found that npmir.com (a full Apache CouchDB implementation on Alibaba's Global Traffic Manager CDN) and CNPMJS (a different tech stack) consistently serve these author-deleted packages. This allows adversaries to retrieve packages that authors attempted to conceal, possibly to prevent analysis or to reuse the package name later.
  3. Unique and Consistent Behavior: McCarty emphasized that this retention behavior was unique to the Chinese mirrors and had been consistent for years, unlike any other global mirror. He reported hitting these APIs "millions" of times, confirming the persistent nature of this anomaly.
  4. Novel Threat Intelligence Source: McCarty leveraged this discovery to collect NPM malware for over a year and a half. Approximately 25% of the malware he collected was deleted by NPM's internal team, meaning it had been seen only by NPM researchers and the original author. This provided him with a unique dataset of unanalyzed malicious code.
  5. Advanced Threat Hunting: By analyzing these previously unseen malware samples, McCarty extracted critical Indicators of Compromise (IOCs), including IP addresses, C2 domains, and file hashes, that other threat intelligence teams had missed. He then built a CTI (Cyber Threat Intelligence) portal with a relational database, allowing him to track threat actors, NPM authors, and their associated GitHub accounts. This enabled him to identify large clusters of malicious packages (e.g., 40-50 related packages) when other researchers might only find one or two.

While McCarty stated he has no direct proof linking this behavior to the Chinese Communist Party (CCP) or the RMSV regulations, the consistent and unique nature of these Chinese mirrors, coupled with the CCP's known strategy of weaponizing vulnerabilities, strongly suggests a deliberate, state-aligned effort to hoard and potentially exploit software supply chain threats. He speculated that it could be cloud providers proactively retaining "malicious stuff the Chinese government might give a sh*t about" or a more formal directive. McCarty also noted that, as of his talk, this mirror behavior was becoming inconsistent, suggesting NPM and GitHub were actively addressing the issue.

Technical Deep Dive

▶ Watch: Chinese NPM mirrors deliberately store deleted malware (16:40)

The technical foundation of McCarty's investigation rests on understanding the architecture and distribution of the NPM ecosystem, particularly its global mirroring system. NPM functions as a tripartite entity: a local client, a central registry, and a SaaS platform. The core registry, owned by GitHub (which is owned by Microsoft), historically relied on CouchDB for metadata storage, a choice McCarty lamented. As of February of the talk year, it transitioned to PostgreSQL with a CouchDB compatibility layer to avoid breaking the ecosystem. The actual package tarballs, however, are stored in Amazon S3.

This central registry feeds eight global mirrors. McCarty's critical insight was the geographic distribution and behavior of these mirrors. While there's the main registry, a commercial mirror in the UK (Refinery.dev), and a newer one in Russia (RU), the significant anomaly lies with China: five of the eight global NPM mirrors are located in China, accounting for 62.5% of the total. These Chinese mirrors are not uniform in their implementation; each can use its own tech stack.

The core of the problem stems from how package deletion events are handled, or rather, not handled, by these Chinese mirrors. There are primarily four ways a package can be removed from NPM:

  1. Security Researcher Disclosure: A researcher identifies a malicious package and discloses it, typically to OSV.dev. Historically, this took 3-4 days to propagate to an NPM deletion, but recent improvements have reduced this to 2-3 hours.
  2. OSV Automatic Scanner: OSV.dev has an automated scanner that identifies malicious packages, leading to removal in 3-4 days.
  3. NPM's Internal Team: NPM has its own team that identifies and removes malicious packages. When a package's every version is deemed malicious, they replace it with a 0.0.1-security placeholder. This serves to prevent the package name from being reused. These removals are often quiet, with "terrible" GitHub Security Advisories (GHSAs) and minimal public discussion.
  4. Author Self-Deletion: An author can choose to remove their own package. This results in a 404 error or an "unpublished" message when queried via the API. This method is increasingly used by malicious actors because it breaks NPM's automation (often preventing GHSA advisories) and allows the author to reuse the package name later, effectively wiping their tracks and obscuring the malicious payload from broad analysis.

McCarty's Python script, which he shared in a GitHub repo, was designed to query all eight global mirrors for the status of a specific package. This script revealed the divergent behavior:

  • Tencent Server: This mirror uses Verdaccio, an NPM-compatible registry implementation, and is hosted on an Alibaba Cloud CDN. When the main NPM registry replaced a malicious package with the 0.0.1-security placeholder, McCarty's script showed that the Tencent mirror would often continue to serve the original malicious version. The other global mirrors would correctly return the placeholder, but Tencent would provide the actual malware.
  • npmir.com and CNPMJS: npmir.com is described as a "full implementation of Apache Couch," running on Alibaba's Global Traffic Manager CDN. CNPMJS uses a "totally different tech stack." For packages that authors had self-deleted, McCarty's script demonstrated that while the main registry returned a 404/unpublished status, these two Chinese mirrors would serve the deleted packages. This directly contradicts the expected behavior of a distributed database system, where deletion events from the core registry should propagate and be respected by all mirrors.

The underlying mechanism for this retention, as McCarty speculated, is likely a manual configuration. Both Verdaccio and CouchDB are designed to process and respect deletion signals from the main registry. Therefore, the non-compliance points to a deliberate override. McCarty hypothesized that this could be a proactive measure by Chinese cloud providers, anticipating government interest in certain malicious artifacts, or a direct, formal instruction from the Chinese government, possibly related to the RMSV regulations and their internal vulnerability database. The effect is clear: a unique, persistent repository of malware, accessible only through these specific Chinese mirrors.

Demo / Proof of Concept

▶ Watch: How to download previously deleted malicious packages (18:10)

Paul McCarty’s presentation included a powerful demonstration of his findings, showcasing a custom Python script designed to query the status of NPM packages across all eight global mirrors. This script served as the core Proof of Concept (PoC) for his claims regarding the unique behavior of Chinese mirrors.

The demonstration unfolded in two primary scenarios:

  1. Packages Replaced by NPM's Internal Team: McCarty first queried a package that NPM's internal security team had identified as malicious, leading to all its versions being replaced with the 0.0.1-security placeholder.
  • The script showed that the main NPM registry and non-Chinese global mirrors (like the UK mirror) correctly returned the 0.0.1-security placeholder, indicating the malicious versions were no longer directly accessible.
  • However, when the script queried the Tencent server (a Chinese mirror running Verdaccio on Alibaba Cloud CDN), it astonishingly returned the original malicious version of the package. This visually confirmed that the Tencent mirror was not respecting the official deletion and replacement event from the central registry. McCarty stated that he could then successfully download this malicious version.
  1. Packages Self-Deleted by Authors: Next, McCarty demonstrated the behavior for packages that authors had self-deleted, typically to obscure their tracks.
  • For such a package, the main NPM registry returned an "unpublished" message or a 404 error, indicating it was no longer available.
  • In stark contrast, when the script queried npmir.com (running Apache CouchDB on Alibaba's Global Traffic Manager CDN) and CNPMJS (another Chinese mirror with a different tech stack), both mirrors successfully returned the deleted package. This proved that these mirrors were actively retaining and serving packages that their authors had attempted to remove from the public domain.

McCarty acknowledged that reliably downloading these deleted packages could sometimes be challenging, often requiring "somewhere between three and 20 times to make work" due to factors like load balancers. However, he confirmed that the process was effective, allowing him to consistently retrieve these unique malware samples.

He also referenced Truffle Security's prior discovery in 2022, which identified that these same Chinese mirrors could be used to retrieve secrets and credentials from author-deleted NPM packages (e.g., AWS credentials accidentally committed and then deleted). While Truffle Security focused on secret extraction, McCarty's PoC expanded this concept to the systematic collection and analysis of malicious payloads, demonstrating a new vector for threat intelligence.

McCarty explained that he had been using this very methodology for a year and a half to collect NPM malware. This unique access allowed him to acquire samples, approximately 25% of which had been deleted by NPM's internal team, meaning they were largely unanalyzed by the broader security community. From these samples, he extracted unique IOCs (IP addresses, C2 infrastructure, domain names, file hashes) that were not present in other public threat intelligence feeds. He then used these IOCs to build a sophisticated CTI portal, establishing a relational database to track threat actors, NPM authors, and their associated GitHub accounts. This enabled him to perform advanced threat hunting, often identifying 40-50 related malicious packages when others had only found one or two.

Crucially, McCarty provided his Python script in a GitHub repository, enabling other researchers to potentially replicate his findings. However, he concluded the demo with an important update: as of the time of his talk, this mirror functionality was "mostly not working," suggesting that NPM and GitHub were actively addressing the issue. This indicates that while the PoC was effective for a significant period, the window of opportunity for exploiting this specific vulnerability might be closing.

Defensive Implications

▶ Watch: Speaker's theory on why Chinese mirrors hoard malware (24:50)

The "Panda Mirror" discovery carries profound defensive implications for organizations, developers, and the broader cybersecurity community. The existence of consistently non-compliant NPM mirrors in China, actively retaining and serving deleted malicious packages, introduces a novel and significant risk to the software supply chain.

  1. Supply Chain Exposure for Global Teams: Organizations with development teams or build systems located in China, or those whose network traffic is routed through Chinese CDNs or mirrors (even inadvertently), face a direct threat. They could be unknowingly pulling malicious packages that the rest of the world considers deleted or replaced. This necessitates a re-evaluation of how dependencies are sourced and validated, especially for critical infrastructure projects.
  2. Geo-fencing and Explicit Mirror Selection: Defenders should consider implementing stringent controls over which NPM mirrors their build systems and development environments are allowed to interact with. This could involve geo-fencing to exclude Chinese IP ranges or, more precisely, explicitly configuring NPM clients to use trusted mirrors outside of China. This proactive measure can significantly reduce the attack surface stemming from these compromised mirrors.
  3. Enhanced Software Composition Analysis (SCA) and Static Application Security Testing (SAST): McCarty highlighted that current AppSec tools are ill-equipped to detect malicious JavaScript packages. The RCE-by-design nature of NPM install scripts and the ability of JavaScript payloads to bypass many security controls mean that organizations cannot rely solely on traditional SCA or SAST. There is an urgent need for next-generation tools that can analyze package behavior, identify suspicious install scripts, and detect obfuscated malicious code patterns within JavaScript dependencies.
  4. Improved Runtime Protection and Behavioral Analysis: Given the bypass capabilities of JavaScript payloads, endpoint detection and response (EDR) and antivirus solutions often fall short. Organizations must invest in more sophisticated runtime monitoring and behavioral analysis tools that can detect anomalous activity initiated by installed packages, such as unexpected network connections, file system modifications, or process spawns, even if the initial payload is not flagged.
  5. Proactive Threat Intelligence and Research: McCarty's methodology demonstrates the power of leveraging unique data sources for threat intelligence. While the specific mirror behavior might be changing, the principle of actively hunting for and analyzing "deleted" or obscure malware remains vital. Security teams should dedicate resources to exploring unconventional sources for threat data, building internal CTI capabilities, and sharing findings with the broader community to collectively raise the baseline of defense.
  6. Developer Education and Dependency Hygiene: Developers must be educated on the inherent risks of NPM dependencies. This includes scrutinizing package names for typosquatting, understanding the implications of pre/post install scripts, and practicing meticulous dependency auditing. Tools that visualize the entire dependency tree (including indirect dependencies) and highlight potential risks are crucial.
  7. Advocacy for Registry Transparency and Accountability: The cybersecurity community must advocate for greater transparency and stricter enforcement of security policies across all global software registries and their mirrors. NPM, GitHub, and other registry operators need to ensure consistent deletion events, provide clear reporting on mirror compliance, and potentially implement mechanisms to prevent mirrors from deviating from official registry data. The recent efforts by NPM and GitHub to address the mirror issue are a positive sign but underscore the need for continuous vigilance.
  8. Geopolitical Awareness in Supply Chain Risk: This discovery emphasizes that supply chain security extends beyond technical vulnerabilities to geopolitical considerations. Organizations operating globally must factor in the regulatory environments and potential state-sponsored activities in regions where their software supply chain components (like mirrors or CDNs) are located.

In essence, the "Panda Mirror" serves as a stark reminder that the software supply chain is a complex, interconnected, and often vulnerable ecosystem. Defenders must adopt a multi-layered, proactive, and globally aware approach to mitigate the sophisticated risks posed by actors capable of manipulating its fundamental components.

Key Takeaways

  • Chinese NPM mirrors uniquely retain deleted malicious packages: Five out of eight global NPM mirrors are in China (62.5%), and three of these consistently ignore deletion events from the main registry, effectively creating a persistent archive of malware.
  • A novel threat intelligence source was uncovered: This mirror disparity allowed Paul McCarty to collect unanalyzed malicious packages (approximately 25% of which were NPM-deleted), extract unique Indicators of Compromise (IOCs), and build advanced threat intelligence capabilities to track threat actors.
  • Current security tools are inadequate against JavaScript supply chain attacks: NPM, hosting 98.5% of malicious packages, allows RCE by design via install scripts, and JavaScript payloads frequently bypass traditional EDR, antivirus, SAST, and SCA tools.
  • Geopolitical factors influence software supply chain security: The consistent, unique behavior of Chinese mirrors, potentially linked to the Chinese government's RMSV regulations and internal vulnerability hoarding, highlights a state-level dimension to software supply chain risks.
  • Organizations must re-evaluate NPM dependency management: Defenders should consider geo-fencing, explicit mirror selection, enhanced behavioral analysis, and robust developer education to mitigate exposure to potentially compromised mirrors and hidden malware.
  • The problem is being actively addressed, but vigilance is key: While McCarty noted that the mirror functionality was becoming inconsistent, indicating NPM and GitHub are working on a fix, the historical persistence of this issue underscores the need for continuous monitoring and robust security practices across the entire software supply chain.

About the Speaker(s)

Paul McCarty is a highly experienced cybersecurity professional with 32 years in the IT industry. He is currently the Head of Research at Safety, a Canadian software supply chain company, where he focuses on cutting-edge security challenges. Prior to this, he founded Secure Stack in 2017. McCarty has a diverse background, having worked for both large organizations and small startups, which gives him a broad perspective on industry needs and vulnerabilities. He is an active and vocal security researcher, regularly presenting at major conferences such as Defcon, BSides, and CTI conferences. His expertise extends to open-source initiatives, where he serves as the lead for the OSV.dev malicious package database, a collaborative effort by Google and the OpenSSF foundation. McCarty is known for his candid and analytical approach to exposing critical security flaws and advocating for improved industry practices.

Reviews

  • Heather Calloway (CISO) — MUST SEE ★★★★★

→ Top-rated talks at BSides Canberra VIII (2025)

All talks from BSides Canberra VIII (2025)