The vulnerability is a Denial of Service (DoS) in @isaacs/brace-expansion version 5.0.0 and older. The root cause is the unbounded, synchronous, and eager expansion of brace patterns. An attacker can provide a small string with repeated numeric ranges, which causes the library to attempt to generate an exponentially large set of combinations, leading to excessive CPU and memory usage and crashing the Node.js process.
The security patch was released in version 5.0.1. Analysis of the commit history between the vulnerable version 5.0.0 and the patched version 5.0.1 revealed the fixing commit 59d12f1e23accdec8c395ca824cf942c1fdea860.
The patch addresses the vulnerability by introducing a limit on the number of expansions. The following functions were modified:
-
expand(str, [options]): This is the main, public-facing function. It was modified to accept an options object, which can contain a max property to limit the number of expansions. By default, this limit is set to 100,000. This function serves as the entry point for the vulnerable operation.
-
expand_(str, max, isTop): This is the internal, recursive function that performs the expansion. It was modified to accept and enforce the max limit during its execution. The loops and recursive calls within this function now check against the max limit to terminate the expansion process early if the limit is reached.
When the vulnerability is triggered, a runtime profiler would show a call to expand, followed by a large number of recursive calls to expand_, which is where the resource exhaustion occurs. Therefore, both functions are key indicators of this vulnerability.