nanoid: custom generators can loop indefinitely when size is zeroGHSA-2v37-7h3g-55p8
MEDIUMFix: ai/nanoid@cb3626dGHSA-2v37-7h3g-55p8 is a medium-severity (CVSS 5.9) CWE-835 vulnerability in nanoid. A fix is available for nanoid — see the affected versions and patch details below.
Exploitation Status
No confirmed exploitation observed yet
- CISA’s own triage has not observed active exploitation or public proof-of-concept code for this CVE as of its last assessment.
Exploitation and automatability from CISA’s SSVC triage for GHSA-2v37-7h3g-55p8.
EPSS Exploitation Probability
Probability of exploitation in the next 30 days, from FIRST.org EPSS.
How urgent is this, really
Where this sits among everything scored
Real-World Exposure
How broadly this vulnerability is actually deployed: weekly install volume shows current usage, and reverse-dependency count shows how many other packages break if it stays unpatched.
nanoidnpmDescription
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.
Affected Packages
| Ecosystem | Package | Vulnerable range | Fix |
|---|---|---|---|
| 📦npm | nanoid | all versions | 3.3.18npm install nanoid@3.3.18 |
| 📦npm | nanoid | ≥ 4.0.0&&< 5.1.6 | 5.1.6npm install nanoid@5.1.6 |
Affected Products
nanoidnanoid_projectDetection & mitigation playbook
Open-source dependencyDetect
Scan your dependency tree (package-lock.json, pnpm-lock.yaml, requirements.txt, go.sum, etc.) for nanoid, including transitive dependencies — a direct dependency you never call can still pull in a vulnerable version.
Fix
Update nanoid to 3.3.18 or later, then make sure no transitive (indirect) dependency still pins the vulnerable range — O3 confirms GHSA-2v37-7h3g-55p8 is resolved across your whole dependency graph.
Workarounds
Cap what an attacker can consume: apply request size, rate and timeout limits in front of the affected component, and run it with memory and CPU limits so exhaustion degrades one worker rather than the whole service.
Fixing This On Your OS
If you run this on a Linux distribution, patch through your package manager against the distro's own security advisory below — it tracks the exact backported fix for your release, which can ship on a different timeline (and sometimes a different severity) than the upstream project.
An algorithmic denial of service flaw was found in the `nanoid` library. When calling `customAlphabet` or `customRandom` with a `size` parameter of `0`, the internal generation loop fails to meet its termination condition. In Node.js or browser execution contexts, an attacker who supplies an unvalidated, zero-value…
To mitigate this issue, ensure application code validates the size parameter passed to customAlphabet or customRandom, rejecting or sanitizing zero-value inputs before passing them to nanoid.Source: Red Hat security advisory for GHSA-2v37-7h3g-55p8 (CC BY 4.0)
| Product | Fixed in | Advisory |
|---|---|---|
| multicluster engine for Kubernetes 2.17 | multicluster-engine/console-mce-rhel9:1786668856 | RHSA-2026:59593 |
| multicluster engine for Kubernetes 2.8 | multicluster-engine/console-mce-rhel9:1787259048 | RHSA-2026:59558 |
| multicluster engine for Kubernetes 2.9 | multicluster-engine/console-mce-rhel9:1787079359 | RHSA-2026:59559 |
| Network Observability (NETOBSERV) 1.12.3 | network-observability/network-observability-console-plugin-pf5-rhel9:1789978780 | RHSA-2026:70593 |
| Red Hat Advanced Cluster Management for Kubernetes 2.11 | rhacm2/console-rhel9:1787687062 | RHSA-2026:60387 |
| Red Hat Advanced Cluster Management for Kubernetes 2.13 | rhacm2/console-rhel9:1787339249 | RHSA-2026:60390 |
| Red Hat Advanced Cluster Management for Kubernetes 2.14 | rhacm2/console-rhel9:1787339248 | RHSA-2026:60388 |
| Red Hat Advanced Cluster Management for Kubernetes 2.17 | rhacm2/console-rhel9:1787335105 | RHSA-2026:60386 |
Frequently Asked Questions
Is GHSA-2v37-7h3g-55p8 in your dependencies?
Find it across npm, including transitive dependencies.