CVE-2026-67213: nanoid: custom generators can loop indefinitely when size is zero
High CVSS 5.9
- OSV id
- GHSA-2v37-7h3g-55p8
- Also known as
- CVE-2026-67213
- Published
- Last modified
Affected packages
Versions we track that it affects: nanoid 3.3.7; nanoid 3.3.7
How to fix it
nanoid (npm)
Upgrade nanoid to 3.3.18 or later.
npm install nanoid@3.3.18
# if it is an indirect dependency: npm update nanoid (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
nanoid (npm)
Upgrade nanoid to 5.1.6 or later.
npm install nanoid@5.1.6
# if it is an indirect dependency: npm update nanoid (or npm audit fix)
- If it is an indirect dependency, upgrade the package that depends on it, or force the version with "overrides" (npm), "resolutions" (Yarn) or "pnpm.overrides" (pnpm) in package.json.
- Check the changelog for breaking changes (especially across major versions), update the lockfile with the package manager, and run your tests.
Not sure whether your project uses an affected version? Check your lockfile below for free.
Details
nanoid (Nano ID) before 5.1.6 contains an infinite loop in the customAlphabet and customRandom functions. When these functions are configured with a size of 0, the internal generation loop never satisfies its exit condition and spins indefinitely, hanging the calling thread. An application that passes an unvalidated, attacker-controlled size of 0 to these functions is exposed to a denial-of-service condition.
References
- GHSA-2v37-7h3g-55p8 on OSV.dev
- Advisory: https://nvd.nist.gov/vuln/detail/CVE-2026-67213
- Web: https://github.com/ai/nanoid/commit/cb3626d0f3342fdf179cd425fd9c4fbb92c7d0e7
- Web: https://github.com/ai/nanoid/commit/e10f8d40ce9d1ab47f66d65a16b48086432730d0
- Web: https://github.com/ai/nanoid/commit/f9d13f150847d117877adee3460a46eceb0cf49b
- Package: https://github.com/ai/nanoid
- Web: https://github.com/ai/nanoid/releases/tag/3.3.17
- Web: https://github.com/ai/nanoid/releases/tag/3.3.18
- Web: https://github.com/ai/nanoid/releases/tag/5.1.6
- Web: https://www.vulncheck.com/advisories/nanoid-before-infinite-loop-via-zero-size-in-customalphabet-and-customrandom
Am I affected?
Upload or paste your lockfile. We check every package version in it against OSV.dev, this advisory included, and email you the vulnerable ones with the version that fixes them. Free, and no account needed.
About this data
Source: GitHub Advisory Database via OSV.dev (CC-BY 4.0). Severity comes from the advisory's own rating when it has one, else from its CVSS score.