Malicious Code Injection in hardhat-roof Package
Summary
MAL-2026-17509: Malicious code in hardhat-roof (npm). Affects hardhat-roof 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-roof package is presented as a logger, mimicking the popular pino logger. It includes documentation and keywords that suggest it is a fast and efficient logging tool. However, the package is actually a doppelganger, with a misleading name and author, designed to execute malicious code upon import. This poses a significant risk to users who may unknowingly integrate it into their projects.
Vulnerability Detail
The vulnerability originates from the hardhat-roof package, which contains a large, obfuscated file (lib/config.js) that executes malicious code when the package is imported. This file is significantly larger than typical files found in legitimate packages and employs complex obfuscation techniques to hide its true purpose. Users who import this package inadvertently execute potentially harmful code, which could lead to unauthorized access or data breaches.
How To Fix
This package is malicious. Remove it and rotate any credentials it could have accessed.
npm uninstall hardhat-roof
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-roof package entirely. Instead, use the legitimate pino logger or other trusted logging libraries. If you have already imported hardhat-roof, remove it from your dependencies and replace it with a secure alternative.
Conclusion
The hardhat-roof package poses a significant security risk due to its malicious code disguised as a legitimate logging tool. Users are advised to remove this package and replace it with trusted alternatives to safeguard their applications. Utilizing tools like Vulert can help in monitoring for such vulnerabilities in real-time.
See every vulnerability recorded for hardhat-roof →
FAQ
The hardhat-roof package is a malicious package that pretends to be a logging tool similar to the pino logger but contains harmful code.
You can check your project's dependencies for the hardhat-roof package. Additionally, you can use Vulert to monitor and alert for vulnerabilities in your software.
Uninstall the hardhat-roof package immediately and replace it with a legitimate logging package like pino.
The malicious code is obfuscated and executes upon importing the package, potentially leading to unauthorized access or data breaches.
Yes, Vulert allows you to monitor and alert for open-source vulnerabilities in your software using just the package-lock.json file. You can check your application for vulnerabilities without needing to sign up.