Malicious code in hardhat-cap (npm)
The npm package hardhat-cap contained malicious obfuscated code that executed arbitrary code on installation. The package used a Hardhat-themed name as a typosquat lure while containing copied pino logger code as cover, with a ~4 MB obfuscated payload that self-executed at require time.
- Disclosed
- Last updated
- Blast radius
- Any developer or system that installed the hardhat-cap package
- Ecosystems
- Attack vectors
- Affected entities
- hardhat-capnpm package
The npm package hardhat-cap was identified as a malicious typosquat targeting developers working with Hardhat. The package masqueraded as legitimate by copying the README, LICENSE, and type definitions from the pino logger library, with author metadata pointing to jsonspack.com.
The malicious payload was embedded in lib/config.js, a ~4 MB single-line obfuscated module transformed with obfuscator.io. This module employed multiple obfuscation techniques including a rotated string array of approximately 23,931 entries, dual decoders, RC4+base64 string decoding, and control-flow flattening. The obfuscated code was wrapped in a self-invoking IIFE that executed automatically at load time when the package was required.
When developers installed and imported hardhat-cap, the malicious payload executed unconditionally on their host system, providing arbitrary code execution capabilities to an attacker. The combination of the Hardhat-themed package name, copied pino source code as cover, and the opaque obfuscated third module is consistent with a supply chain attack designed to compromise developer environments.
The incident was identified and credited to the OpenSSF's malicious-packages repository.
Indicators of compromise
- Packages
- hardhat-cap
Remediation
- Immediately uninstall the hardhat-cap package from all systems and projects
- Audit npm install logs and package-lock.json files to identify if hardhat-cap was ever installed
- Review system logs and process execution history on any machine where hardhat-cap was installed for signs of unauthorized activity
- Rotate any credentials or secrets that may have been exposed on affected systems
- Use npm audit to check for other malicious packages and verify the integrity of remaining dependencies
- Consider using npm package verification tools and private registries to prevent similar typosquat attacks
Sources
- GitHub Advisory GHSA-hxmr-mqp4-pfpx · GitHub Advisory Database
Cite this entry
"Malicious code in hardhat-cap (npm)." supplychainattack.org, Supply Chain Attack Incident Catalog. Disclosed August 7, 2026; last updated August 7, 2026. https://supplychainattack.org/incident/malicious-code-in-hardhat-cap-npm-dbdpo2
Suggest a correction
Found an error or have a newer source? Corrections to factual errors take priority over new entries.
Related incidents
- resolvedcritical
Malicious code in @finaxis/common-js (npm)
The npm package @finaxis/common-js was published with a README and keywords copied from lodash v4.18.1, but contained a heavily obfuscated Xelis (XEL) proof-of-work cryptominer instead of lodash functionality. Consumers installing this package would unknowingly run a covert CPU/GPU miner on their systems.
npmCompromised packageTyposquatting - resolvedcritical
Malicious code in depcruise-wrap-stream-in-html (npm)
depcruise-wrap-stream-in-html@99.9.1 is a malicious npm package that mimics an internal helper of dependency-cruiser. It is a hollow package that downloads and executes arbitrary code from a Google Cloud Storage bucket during installation.
npmCompromised packageDependency confusionTyposquatting - resolvedcritical
Malicious code in akamai-sensor (npm)
A malicious npm package named akamai-sensor impersonated Akamai's legitimate sensor_data anti-bot SDK. The package contained hidden JavaScript code concealed using invisible Unicode characters and implemented a dynamic command-and-control channel via a Google Calendar dead-drop, enabling arbitrary code execution on installation.
npmCompromised packageTyposquatting - resolvedcritical
Malicious code in wct-st (npm)
The npm package wct-st contained malicious code in its postinstall lifecycle script that collected and exfiltrated host identifiers to a remote endpoint. The package name resembles the deprecated web-component-tester, consistent with a typosquatting attack.
npmCompromised packageTyposquatting