Packages / brace-expansion / Security
brace-expansion: Zero-step sequence causes process hang and memory exhaustion
Affected releases · brace-expansion
- 5.x5.0.2 – 5.0.4Fixed in 5.0.5
- 4.x4.0.0 – 4.0.1No fix on this line yet
- 3.x3.0.0 – 3.0.1Fixed in 3.0.2
- 2.x2.0.0 – 2.0.2Fixed in 2.0.3
- 1.x1.0.0 – 1.1.12Fixed in 1.1.13
- 0.0.x0.0.0No fix on this line yet
On 5.x, the newest line:
npm install brace-expansion@5.0.5Every release on a timeline
Affected
5.0.2 – 5.0.4
3 releases
Fixed
5.0.5 – 5.0.13
9 releases, latest
Affected
4.0.0 – 4.0.1
2 releases
Affected
3.0.0 – 3.0.1
2 releases
Fixed
3.0.2 – 3.0.10
9 releases
Affected
2.0.0 – 2.0.2
3 releases
Fixed
2.0.3 – 2.1.8
10 releases
Affected
1.0.0 – 1.1.12
15 releases
Fixed
1.1.13 – 1.1.22
10 releases
Affected
0.0.0
1 release
What happens
Impact
A brace pattern with a zero step value (e.g., {1..2..0}) causes the sequence generation loop to run indefinitely, making the process hang for seconds and allocate heaps of memory.
The loop in question:
github.com/juliangruber/brace-expansion/blob/da…
test() is one of
github.com/juliangruber/brace-expansion/blob/da…
The increment is computed as Math.abs(0) = 0, so the loop variable never advances. On a test machine, the process hangs for about 3.5 seconds and allocates roughly 1.9 GB of memory before throwing a RangeError. Setting max to any value has no effect because the limit is only checked at the output combination step, not during sequence generation.
This affects any application that passes untrusted strings to expand(), or by error sets a step value of 0. That includes tools built on minimatch/glob that resolve patterns from CLI arguments or config files. The input needed is just 10 bytes.
Patches
Upgrade to versions
5.0.5+
A step increment of 0 is now sanitized to 1, which matches bash behavior.
Workarounds
Sanitize strings passed to expand() to ensure a step value of 0 is not used.
A whole project to check? Paste its package.json in the dependency check: every deprecated, outdated or vulnerable dependency, with what to upgrade to. Free, no account.