Malicious Code Injection in hardhat-init Package
Summary
MAL-2026-17636: Malicious code in hardhat-init (npm). Affects hardhat-init versions 2.21.0. No fix is published. How to fix ↓
Check if this vulnerability affects your application
Upload a manifest or SBOM and we'll show whether you're affected, plus every other risky package in the same scan.
No signup required · Results in about 60 seconds
Background
The hardhat-init package is designed to facilitate the initialization of Hardhat projects, a popular framework for Ethereum development. It aims to streamline the setup process for developers by providing essential tools and configurations. However, this package has been compromised, leading to significant security risks due to the presence of malicious code.
Vulnerability Detail
The vulnerability in the hardhat-init package arises from the inclusion of a heavily obfuscated JavaScript file (lib/config.js) that executes arbitrary code upon loading the package. This obfuscation employs techniques such as hex-escaped string tables and nested index-lookup helpers, making it difficult to discern the malicious behavior. The package's misleading name and content further exacerbate the issue, as it masquerades as a legitimate initialization tool while executing harmful code on the user's machine.
How To Fix
This package is malicious. Remove it and rotate any credentials it could have accessed.
npm uninstall hardhat-init
If it arrived as a transitive dependency, remove the package that pulled it in, then reinstall.
Tip — Not sure whether your app is affected? Vulert can check the versions your app actually runs. Scan free →
Workaround
As a temporary workaround, avoid using the hardhat-init package until a secure version is released. Instead, consider manually initializing your Hardhat projects by following the official Hardhat documentation.
Conclusion
The hardhat-init package has been compromised with malicious code that executes upon loading. It is essential to update or remove this package to protect your system from potential threats. Utilize tools like Vulert to monitor your applications for vulnerabilities and ensure a secure development environment.
See every vulnerability recorded for hardhat-init →
FAQ
The hardhat-init package is a tool designed to help developers initialize Hardhat projects for Ethereum development.
The malicious code can execute arbitrary commands on your machine, potentially leading to data theft, system compromise, or other harmful actions.
You can use Vulert, which monitors and alerts for open-source vulnerabilities in real-time. Visit Vulert Scanner to check your application without requiring access to the code or installation.
If you have installed the hardhat-init package, immediately remove it and update your project dependencies to eliminate the risk of executing malicious code.
Yes, always stay informed about vulnerabilities in the packages you use. Regularly check for updates and utilize tools like Vulert to monitor your dependencies.