Skip to content

Security: Regular Expression Denial of Service (ReDoS) in glob pattern compilation#243

Closed
tuanaiseo wants to merge 1 commit into
millionco:mainfrom
tuanaiseo:contribai/fix/security/regular-expression-denial-of-service-red
Closed

Security: Regular Expression Denial of Service (ReDoS) in glob pattern compilation#243
tuanaiseo wants to merge 1 commit into
millionco:mainfrom
tuanaiseo:contribai/fix/security/regular-expression-denial-of-service-red

Conversation

@tuanaiseo
Copy link
Copy Markdown

@tuanaiseo tuanaiseo commented May 14, 2026

Problem

The compileGlobPattern function in match-glob-pattern.ts compiles user-provided glob patterns into regular expressions without any timeout or complexity limits. Malicious patterns like **/a* repeated many times or with nested quantifiers could cause catastrophic backtracking.

Severity: high
File: packages/react-doctor/src/core/config/match-glob-pattern.ts

Solution

Implement a regex complexity check or use a library like safe-regex to validate the compiled regex for potential ReDoS. Alternatively, use a glob-to-regex library with built-in protection.

Changes

  • packages/react-doctor/src/core/config/match-glob-pattern.ts (modified)

Testing

  • Existing tests pass
  • Manual review completed
  • No new warnings/errors introduced

Note

Medium Risk
Adds hard limits that now throw errors for overly long or wildcard-heavy ignore patterns, which could break existing configs that relied on very large globs. Change is localized but affects config parsing for ignore rules.

Overview
Mitigates potential ReDoS in compileGlobPattern by enforcing maximum glob length and wildcard count before compiling to a RegExp.

Invalid/overly complex patterns now throw explicit errors, impacting ignore file/override pattern compilation that calls this helper.

Reviewed by Cursor Bugbot for commit 66f7bc6. Bugbot is set up for automated code reviews on this repo. Configure here.

…dos) in gl

The `compileGlobPattern` function in match-glob-pattern.ts compiles user-provided glob patterns into regular expressions without any timeout or complexity limits. Malicious patterns like `**/a*` repeated many times or with nested quantifiers could cause catastrophic backtracking.

Affected files: match-glob-pattern.ts

Signed-off-by: tuanaiseo <221258316+tuanaiseo@users.noreply.github.com>
@reactreview
Copy link
Copy Markdown

reactreview Bot commented May 14, 2026

🔴 React Review0/100 (unchanged) · No new issues

Reviewed by react-review for commit 66f7bc6. Configure here.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 14, 2026

@tuanaiseo is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 66f7bc6. Configure here.

const wildcardCount = (pattern.match(/[*?]/g) || []).length;
if (wildcardCount > MAX_WILDCARDS) {
throw new Error(`Glob pattern exceeds maximum wildcard count of ${MAX_WILDCARDS}`);
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ReDoS mitigation is insufficient despite length/wildcard limits

High Severity

The pattern length and wildcard count limits don't actually prevent catastrophic backtracking. A pattern like **a**a**a**a**a (15 chars, 10 wildcards — well within both limits) compiles to ^.*a.*a.*a.*a.*a.*$, which has multiple overlapping .* quantifiers that cause exponential backtracking on adversarial inputs. The compiled regex complexity is never validated, so the ReDoS vulnerability the PR claims to fix remains exploitable. A proper fix needs to either validate the compiled regex (e.g., via safe-regex) or restructure the generated patterns to avoid overlapping quantifiers.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 66f7bc6. Configure here.

const REGEX_SPECIAL_CHARACTERS = /[.+^${}()|[\]\\]/g;

const MAX_PATTERN_LENGTH = 500;
const MAX_WILDCARDS = 20;
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const MAX_WILDCARDS = 20;
const MAX_WILDCARDS = 10;

MAX_WILDCARDS limit of 20 is insufficient to prevent ReDoS attacks, allowing patterns that cause multi-second or timeout-level delays

Fix on Vercel

@NisargIO NisargIO closed this May 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants