Skip to content

Commit 0bf499a

Browse files
committed
limit recursion for **, improve perf considerably
This limits the levels of recursion allowed when encountering multiple non-adjacent `**` portions of a pattern. Update `**` handling, with performance massively improved by limiting the recursive walk much more aggressively. When a `**` portion is present, the entire pattern is split up into sections. The head and tail first have to match, and then each subsequent portion is only tested in the part of the file where it might actually be found, taking advantage of the fact that non-globstar portions must always consume as many path portions as there are pattern portions. Fix: GHSA-7r86-cg39-jmmj
1 parent 9f15c58 commit 0bf499a

File tree

7 files changed

+350
-105
lines changed

7 files changed

+350
-105
lines changed

README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,22 @@ separators in file paths for comparison.)
396396

397397
Defaults to the value of `process.platform`.
398398

399+
### maxGlobstarRecursion
400+
401+
Max number of non-adjacent `**` patterns to recursively walk
402+
down.
403+
404+
The default of `200` is almost certainly high enough for most
405+
purposes, and can handle absurdly excessive patterns.
406+
407+
If the limit is exceeded (which would require very excessively
408+
long patterns and paths containing lots of `**` patterns!), then
409+
it is treated as non-matching, even if the path would normally
410+
match the pattern provided.
411+
412+
That is, this is an intentional false negative, deemed an
413+
acceptable break in correctness for security and performance.
414+
399415
## Comparisons to other fnmatch/glob implementations
400416

401417
While strict compliance with the existing standards is a

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
"@types/node": "^25.3.0",
4646
"mkdirp": "^3.0.1",
4747
"prettier": "^3.6.2",
48-
"tap": "^21.6.1",
48+
"tap": "^21.6.2",
4949
"tshy": "^3.0.2",
5050
"typedoc": "^0.28.5"
5151
},

src/assert-valid-pattern.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const MAX_PATTERN_LENGTH = 1024 * 64
22
export const assertValidPattern: (pattern: any) => void = (
3-
pattern: any,
3+
pattern: unknown,
44
): asserts pattern is string => {
55
if (typeof pattern !== 'string') {
66
throw new TypeError('invalid pattern')

0 commit comments

Comments
 (0)