Predictable results in nanoid generation when given non-integer values
Published 9 Dec 2024 · Updated 10 Sept 2026
Affected packages
- Affected
- >=4.0.0 <5.0.9
- Fixed in
- 5.0.9
npm install nanoid@5.0.9- Affected
- <3.3.8
- Fixed in
- 3.3.8
npm install nanoid@3.3.8Details
When nanoid is called with a fractional value, there were a number of undesirable effects:
1. in browser and non-secure, the code infinite loops on while (size--) 2. in node, the value of poolOffset becomes fractional, causing calls to nanoid to return zeroes until the pool is next filled 3. if the first call in node is a fractional argument, the initial buffer allocation fails with an error
Version 3.3.8 and 5.0.9 are fixed.
Is GHSA-mwcw-c2x4-8c55 in any of your client repos?
Checking one package by hand is fine. Checking it across forty client projects is not. NPMscan reads the lockfiles in every GitHub repo you pick, finds each project with an affected nanoid, and gives you the command that fixes it.
References
- Advisorynvd.nist.gov/vuln/detail/CVE-2024-55565
- Linkgithub.com/ai/nanoid/pull/510
- Packagegithub.com/ai/nanoid
- Linkgithub.com/ai/nanoid/compare/3.3.7...3.3.8
- Linkgithub.com/ai/nanoid/releases/tag/5.0.9
- Linklists.debian.org/debian-lts-announce/2024/12/msg00025.html
- Linklists.debian.org/debian-lts-announce/2025/01/msg00006.html
Advisory data from OSV.dev (opens OSV.dev in a new tab), refreshed daily.