Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
"zod": "^4.6.6"
},
"patchedDependencies": {
"http-cache-semantics@4.3.0": "patches/http-cache-semantics@4.3.0.patch"
"http-cache-semantics@4.3.0": "patches/http-cache-semantics@4.3.0.patch",
"picomatch@4.0.7": "patches/picomatch@4.0.7.patch",
"picomatch@2.3.2": "patches/picomatch@2.3.2.patch"
}
}
}
87 changes: 87 additions & 0 deletions docs/patches/picomatch@2.3.2.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
diff --git a/lib/parse.js b/lib/parse.js
index caa2b86aa5a567df33cef4bda3c7a97794f439f8..b5e0a33480897aef82fe9c6dfb6e8ee2b56afd63 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -280,7 +280,36 @@ const repeatedExtglobRecursion = pattern => {
return depth;
};

-const analyzeRepeatedExtglob = (body, options) => {
+// A branch built only from single-character matchers and `*` wildcards, with no
+// slash: literal characters, `?`, and plain bracket classes that cannot match `/`.
+const ABSORBING_BRANCH_REGEX = /^(?:[^\\/()[\]{}|!@+*?"']|\?|\[[^\]\\/!^]+\]|\*(?!\*))+$/;
+
+// A bracket range such as `[+-0]` can still match `/`, so check the compiled class.
+const bracketMatchesSlash = tok => {
+ try {
+ return new RegExp(`^(?:${tok.output || tok.value})$`).test('/');
+ } catch (err) {
+ return true;
+ }
+};
+
+const isAbsorbingBranch = (body, bodyTokens) => {
+ return ABSORBING_BRANCH_REGEX.test(body) &&
+ body.replace(/\[[^\]]*\]/g, '').includes('*') &&
+ !bodyTokens.some(tok => tok.type === 'bracket' && bracketMatchesSlash(tok));
+};
+
+// Wildcard tokens in an extglob body, not counting a `*` that opens a nested `*(...)`.
+const hasWildcardToken = bodyTokens => {
+ return bodyTokens.some((tok, i) => {
+ if (tok.type !== 'star' && tok.type !== 'globstar') return false;
+ if (tok.value === '') return false;
+ const next = bodyTokens[i + 1];
+ return !(next && next.type === 'paren' && next.extglob === true && next.value === '(');
+ });
+};
+
+const analyzeRepeatedExtglob = (body, options, bodyTokens = []) => {
if (options.maxExtglobRecursion === false) {
return { risky: false };
}
@@ -292,6 +321,24 @@ const analyzeRepeatedExtglob = (body, options) => {

const branches = splitTopLevel(body).map(branch => branch.trim());

+ // A single branch holding a wildcard, such as `+(*a)` or `+(a*)b`, nests an
+ // unbounded quantifier and backtracks exponentially (GHSA-fc5q-39xc-vjpf).
+ if (branches.length === 1 && hasWildcardToken(bodyTokens)) {
+ // For a branch P made of single-character matchers and `*`, P repeated
+ // matches exactly what P matches: the first `*` absorbs every later repeat.
+ // So `+(P)` is `(P)` and `*(P)` is `(P)?`, with no nested quantifier.
+ if (isAbsorbingBranch(body, bodyTokens)) {
+ return { risky: false, collapse: true };
+ }
+
+ // A literal slash fixes where each repeat starts, since `*` cannot cross
+ // it outside bash mode, so the repeat cannot backtrack.
+ const hasSlash = bodyTokens.some(tok => tok.type === 'slash');
+ if (options.bash === true || !hasSlash) {
+ return { risky: true };
+ }
+ }
+
if (branches.length > 1) {
if (
branches.some(branch => branch === '') ||
@@ -510,7 +557,7 @@ const parse = (input, options) => {
const extglobClose = token => {
const literal = input.slice(token.startIndex, state.index + 1);
const body = input.slice(token.startIndex + 2, state.index);
- const analysis = analyzeRepeatedExtglob(body, opts);
+ const analysis = analyzeRepeatedExtglob(body, opts, tokens.slice(token.tokensIndex + 2));

if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
const safeOutput = analysis.safeOutput
@@ -536,6 +583,10 @@ const parse = (input, options) => {
return;
}

+ if (analysis.collapse === true && (token.type === 'plus' || token.type === 'star')) {
+ token.close = token.type === 'plus' ? ')' : ')?';
+ }
+
let output = token.close + (opts.capture ? ')' : '');
let rest;

87 changes: 87 additions & 0 deletions docs/patches/picomatch@4.0.7.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
diff --git a/lib/parse.js b/lib/parse.js
index 29207512c60183b4bb9bf5112be3b9b5f4a9a9fd..296afb16b857e181315a800630978fea9f139929 100644
--- a/lib/parse.js
+++ b/lib/parse.js
@@ -284,7 +284,36 @@ const repeatedExtglobRecursion = pattern => {
return depth;
};

-const analyzeRepeatedExtglob = (body, options) => {
+// A branch built only from single-character matchers and `*` wildcards, with no
+// slash: literal characters, `?`, and plain bracket classes that cannot match `/`.
+const ABSORBING_BRANCH_REGEX = /^(?:[^\\/()[\]{}|!@+*?"']|\?|\[[^\]\\/!^]+\]|\*(?!\*))+$/;
+
+// A bracket range such as `[+-0]` can still match `/`, so check the compiled class.
+const bracketMatchesSlash = tok => {
+ try {
+ return new RegExp(`^(?:${tok.output || tok.value})$`).test('/');
+ } catch (err) {
+ return true;
+ }
+};
+
+const isAbsorbingBranch = (body, bodyTokens) => {
+ return ABSORBING_BRANCH_REGEX.test(body) &&
+ body.replace(/\[[^\]]*\]/g, '').includes('*') &&
+ !bodyTokens.some(tok => tok.type === 'bracket' && bracketMatchesSlash(tok));
+};
+
+// Wildcard tokens in an extglob body, not counting a `*` that opens a nested `*(...)`.
+const hasWildcardToken = bodyTokens => {
+ return bodyTokens.some((tok, i) => {
+ if (tok.type !== 'star' && tok.type !== 'globstar') return false;
+ if (tok.value === '') return false;
+ const next = bodyTokens[i + 1];
+ return !(next && next.type === 'paren' && next.extglob === true && next.value === '(');
+ });
+};
+
+const analyzeRepeatedExtglob = (body, options, bodyTokens = []) => {
if (options.maxExtglobRecursion === false) {
return { risky: false };
}
@@ -296,6 +325,24 @@ const analyzeRepeatedExtglob = (body, options) => {

const branches = splitTopLevel(body).map(branch => branch.trim());

+ // A single branch holding a wildcard, such as `+(*a)` or `+(a*)b`, nests an
+ // unbounded quantifier and backtracks exponentially (GHSA-fc5q-39xc-vjpf).
+ if (branches.length === 1 && hasWildcardToken(bodyTokens)) {
+ // For a branch P made of single-character matchers and `*`, P repeated
+ // matches exactly what P matches: the first `*` absorbs every later repeat.
+ // So `+(P)` is `(P)` and `*(P)` is `(P)?`, with no nested quantifier.
+ if (isAbsorbingBranch(body, bodyTokens)) {
+ return { risky: false, collapse: true };
+ }
+
+ // A literal slash fixes where each repeat starts, since `*` cannot cross
+ // it outside bash mode, so the repeat cannot backtrack.
+ const hasSlash = bodyTokens.some(tok => tok.type === 'slash');
+ if (options.bash === true || !hasSlash) {
+ return { risky: true };
+ }
+ }
+
if (branches.length > 1) {
if (
branches.some(branch => branch === '') ||
@@ -539,7 +586,7 @@ const parse = (input, options) => {
const extglobClose = token => {
const literal = input.slice(token.startIndex, state.index + 1);
const body = input.slice(token.startIndex + 2, state.index);
- const analysis = analyzeRepeatedExtglob(body, opts);
+ const analysis = analyzeRepeatedExtglob(body, opts, tokens.slice(token.tokensIndex + 2));

if ((token.type === 'plus' || token.type === 'star') && analysis.risky) {
const safeOutput = analysis.safeOutput
@@ -565,6 +612,10 @@ const parse = (input, options) => {
return;
}

+ if (analysis.collapse === true && (token.type === 'plus' || token.type === 'star')) {
+ token.close = token.type === 'plus' ? ')' : ')?';
+ }
+
let output = token.close + (opts.capture ? ')' : '');
let rest;

Loading
Loading