CVE-2024-55565: Infinite Loop Vulnerability in nanoid Package
Summary
CVE-2024-55565: Predictable results in nanoid generation when given non-integer values. Affects nanoid across 2 version ranges.
< 3.3.8
>= 4.0.0, < 5.0.9
Fixed in 3.3.8 or 5.0.9, depending on the release line you run. How to fix ↓
Also tracked for
- node-mocha · Debian:11
The same CVE-2024-55565 is tracked separately for each ecosystem and vendor. Its fix information is the same; the package and affected versions differ.
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 is a popular library used for generating unique IDs in JavaScript applications. It is known for its performance and small size, making it a preferred choice for developers needing to create unique identifiers efficiently. However, certain versions of nanoid are vulnerable to an infinite loop issue when handling non-integer values, which can lead to application hangs or crashes.
Vulnerability Detail
The vulnerability arises from the mishandling of non-integer values in the nanoid package versions prior to 5.0.9. When these non-integer values are processed, the library enters an infinite loop, causing the application to become unresponsive. This issue is particularly concerning as it can be triggered by unexpected input, potentially leading to denial of service conditions in applications that rely on nanoid for ID generation.
How To Fix
Latest published version: 6.0.2 as of 22 Oct 2026
npm install nanoid@6.0.2
Upgrading to it may include breaking changes; the versions below are the minimum fixed release for this vulnerability.
If you can't move to the latest
The minimum fixed version depends on the release line you run.
-
< 3.3.83.3.8npm install nanoid@3.3.8 -
>= 4.0.0, < 5.0.95.0.9npm install nanoid@5.0.9
Tip — Not sure which release line you're on? Vulert can find the fix for the version you are using. Scan free →
Workaround
As a temporary workaround, ensure that all inputs to the nanoid function are validated to be integers before processing. This can prevent the infinite loop from occurring. For example, you can implement a check like this:
if (typeof input !== 'number' || !Number.isInteger(input)) {
throw new Error('Input must be an integer');
}
Conclusion
The infinite loop vulnerability in the nanoid package can lead to significant issues in applications that rely on it for ID generation. By updating to the patched versions and implementing input validation, developers can mitigate the risks associated with this vulnerability.
See every vulnerability recorded for nanoid →
FAQ
Versions of nanoid prior to 5.0.9 and 3.3.8 are affected by this vulnerability.
If you do not update, your application may become unresponsive when non-integer values are processed, leading to potential denial of service.
You can use Vulert's playground at Vulert Scanner to check if your application is affected by this vulnerability without any signup.
Yes, you can validate inputs to the nanoid function to ensure they are integers, as described in the workaround section.
Vulert monitors and alerts for open-source vulnerabilities in your software using just the package-lock.json file, providing real-time insights without requiring code access.
Related vulnerabilities
Recent vulnerabilities recorded for nanoid.