nanoid: custom generators can loop indefinitely when size is zero
Affected releases · nanoid
- 5.x5.0.0 – 5.1.5Fixed in 5.1.6
- 4.x4.0.0 – 4.0.2No fix on this line yet
- 3.x3.0.0 – 3.3.17Fixed in 3.3.18
- 2.x and older0.1.0 – 2.1.11No fix, no longer updated
On 5.x, the newest line:
npm install nanoid@5.1.6Not affected
6.0.0 – 6.0.2
3 releases, latest
Affected
5.0.0 – 5.1.5
16 releases
Fixed
5.1.6 – 5.1.16
11 releases
Affected
4.0.0 – 4.0.2
3 releases
Affected
3.0.0 – 3.3.17
55 releases
Fixed
3.3.18 – 3.3.20
3 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.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.