Skip to content

Fix ReDoS vulnerability in ParameterMetadataExtractor regex#111

Open
Vipin-Sharma wants to merge 1 commit intomasterfrom
fix/parameter-extractor-redos
Open

Fix ReDoS vulnerability in ParameterMetadataExtractor regex#111
Vipin-Sharma wants to merge 1 commit intomasterfrom
fix/parameter-extractor-redos

Conversation

@Vipin-Sharma
Copy link
Copy Markdown
Owner

Summary

Fixed Regular Expression Denial of Service (ReDoS) vulnerability in ParameterMetadataExtractor by using possessive quantifiers throughout the regex pattern.

Changes

  • Before: (\w+\.\w+|\w+)\s*=\s*\?
  • After: (\w++(?:\.\w++)?+)\s*+=\s*+\?

Why This Works

The fix uses possessive quantifiers (++) which prevent backtracking completely:

  • \w++ - matches word characters without backtracking
  • (?:\.\w++)?+ - possessive optional group with possessive inner match
  • \s*+ - possessive whitespace matching

This eliminates the polynomial runtime vulnerability while maintaining identical functionality.

Technical Explanation

Possessive quantifiers commit to their matches immediately and never backtrack, making catastrophic backtracking impossible. This is the recommended approach for preventing ReDoS in complex patterns.

Test plan

  • All 28 existing ParameterMetadataExtractorTest tests pass
  • Regex functionality unchanged (matches same patterns)
  • No performance regression

🤖 Generated with Claude Code

Fixed regex pattern that was vulnerable to catastrophic backtracking:
- Changed from: (\w+\.\w+|\w+)\s*=\s*\?
- Changed to: (\w++(?:\.\w++)?+)\s*+=\s*+\?

Key improvements:
- Used possessive quantifiers (\w++ instead of \w+) to prevent backtracking
- Used possessive optional (?:...)++ to prevent nested backtracking
- This eliminates polynomial runtime vulnerability while maintaining functionality

All 28 tests pass successfully.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
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.

1 participant