nanoid: non-secure generators can loop indefinitely with negative size
Affected releases · nanoid
- 5.x5.0.0 – 5.1.15Fixed in 5.1.16
- 4.x4.0.0 – 4.0.2No fix on this line yet
- 3.x3.0.0 – 3.3.15Fixed in 3.3.16
- 2.x and older0.1.0 – 2.1.11No fix, no longer updated
On 5.x, the newest line:
npm install nanoid@5.1.16Not affected
6.0.0 – 6.0.2
3 releases, latest
Affected
5.0.0 – 5.1.15
26 releases
Fixed
5.1.16
1 release
Affected
4.0.0 – 4.0.2
3 releases
Affected
3.0.0 – 3.3.15
53 releases
Fixed
3.3.16 – 3.3.20
5 releases
Affected
2.0.0 – 2.1.11
17 releases
Affected
1.0.0 – 1.3.4
22 releases
Affected
0.1.0 – 0.2.2
5 releases
Is your project affected?
Paste your package.json, or type the range you declare for nanoid. It is read in your browser and sent nowhere.
What happens
nanoid (Nano ID) before 5.1.16 contains an infinite loop in the customAlphabet and nanoid functions of its non-secure module (nanoid/non-secure). When these functions are given a negative size, the loop counter is decremented from a negative value and never reaches its termination condition, spinning indefinitely and hanging the calling thread. An application that passes an unvalidated, attacker-controlled negative size to these functions is exposed to a denial-of-service condition.