Malicious Code Detected in nanoid-js Package - Immediate Action Required
Summary
MAL-2026-418: Malicious code in nanoid-js (npm). Affected versions are not published. 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
nanoid-js is a popular npm package used for generating unique IDs with a focus on performance and security. It is widely utilized in various applications to ensure that identifiers are unique and collision-resistant. However, a recent discovery has revealed that the package contains malicious code, posing significant security risks to systems that utilize it.
Vulnerability Detail
The vulnerability originates from the inclusion of malicious code within the nanoid-js package. This code can compromise any computer that has the package installed, potentially allowing unauthorized access to sensitive information such as secrets and keys. The malicious nature of the code means that systems may be fully compromised, and simply removing the package may not eliminate all traces of the malicious software.
How To Fix
This package is malicious. Remove it and rotate any credentials it could have accessed.
npm uninstall nanoid-js
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, you can replace the nanoid-js package with an alternative library for generating unique IDs, such as uuid. You can install it using the command: npm install uuid. This will help mitigate the risk while you assess the situation with nanoid-js.
Conclusion
The discovery of malicious code in the nanoid-js package poses a serious threat to systems that utilize it. Immediate action is required to remove the package and secure any sensitive information. Utilizing tools like Vulert can help monitor for such vulnerabilities in the future.
See every vulnerability recorded for nanoid-js →
FAQ
You should immediately remove the nanoid-js package from your project and consider rotating any sensitive keys or secrets stored on the affected system.
You can use Vulert, which monitors open-source vulnerabilities in your software. By analyzing your package-lock.json file, Vulert can alert you to any vulnerabilities, including this one.
Regularly monitor your dependencies for vulnerabilities using tools like Vulert, and keep your packages up to date to minimize the risk of malicious code.
Failing to address this vulnerability could lead to unauthorized access to sensitive data, system compromise, and potential data breaches.
Trust in the package will depend on the actions taken by its maintainers to address the issue. Always review the package's repository for updates and community feedback before reintroducing it.