Skip to content

Commit 11d0df6

Browse files
committed
limit nested extglob recursion, flatten extglobs
This flattens nested extglobs where that can be done correctly. In other cases, the recursion into nested extglobs is limited to 2, in order to prevent runaway ReDOS patterns. fix: GHSA-23c5-xmqv-rm74
1 parent c3448c4 commit 11d0df6

File tree

4 files changed

+279
-37
lines changed

4 files changed

+279
-37
lines changed

README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,26 @@ match the pattern provided.
412412
That is, this is an intentional false negative, deemed an
413413
acceptable break in correctness for security and performance.
414414

415+
### maxExtglobRecursion
416+
417+
Max depth to traverse for nested extglobs like `*(a|b|c)`
418+
419+
Default is 2, which is quite low, but any higher value swiftly
420+
results in punishing performance impacts. Note that this is _not_
421+
relevant when the globstar types can be safely coalesced into a
422+
single set.
423+
424+
For example, `*(a|@(b|c)|d)` would be flattened into
425+
`*(a|b|c|d)`. Thus, many common extglobs will retain good
426+
performance and never hit this limit, even if they are
427+
excessively deep and complicated.
428+
429+
If the limit is hit, then the extglob characters are simply not
430+
parsed, and the pattern effectively switches into `noextglob:
431+
true` mode for the contents of that nested sub-pattern. This will
432+
typically _not_ result in a match, but is considered a valid
433+
trade-off for security and performance.
434+
415435
## Comparisons to other fnmatch/glob implementations
416436

417437
While strict compliance with the existing standards is a

0 commit comments

Comments
 (0)