CVE-2024-55565: Infinite Loop Vulnerability in nanoid Package

nanoid Updated 02 Oct 2025

Summary

09/12/2024
Yes i
Moderate
4.3

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

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.

Free scan

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.

Check my app free

No signup required · Results in about 60 seconds

Upload your dependency manifest or SBOM

Drag & drop your file here or

Java Javascript PHP Python Go Rust Ruby Dart C/C++ Elixir CycloneDX SPDX

Upload a supported dependency manifest or SBOM. No installation or source-code access required.

See supported files and SBOM formats
SBOM sbom.json · bom.json · bom.xml · *.spdx.json · *.cdx.json · *.cdx.xml
Java pom.xml · gradle.lockfile · buildscript-gradle.lockfile
Javascript package-lock.json · yarn.lock · pnpm-lock.yaml
PHP composer.lock
Python poetry.lock · requirements.txt · Pipfile.lock
Go go.mod
Rust Cargo.lock
Ruby Gemfile.lock
Dart pubspec.lock
C/C++ conan.lock
Elixir mix.lock
Enter your work email to receive your report link.

Verify your email to view the full report and start 30 days of continuous monitoring. No credit card required.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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.8 3.3.8
    npm install nanoid@3.3.8
  • >= 4.0.0, < 5.0.9 5.0.9
    npm 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 →

Share this vulnerability

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.

Sponsored Lume, the Habilume companion Habilume Habit tracker with a companion that grows with you Complete habits, earn Lume Points, and watch your Lume grow as you stay consistent. App Store Google Play

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.8 3.3.8
    npm install nanoid@3.3.8
  • >= 4.0.0, < 5.0.9 5.0.9
    npm 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 →

Subscribe to Vulert on Telegram
Daily digest of new CVEs, critical and high severity, affected packages and fixes — plus a weekly roundup.
Join the channel →
Help improve this record
Report an issue or send feedback