GROOVY-12122: Provide a Regex timeout facility#2668
Open
paulk-asert wants to merge 1 commit into
Open
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR (GROOVY-12122) introduces an opt-in regex timeout facility to help mitigate catastrophic backtracking (ReDoS) by adding a runtime guard and a compile-time AST transform that rewrites Groovy’s regex operators within an annotated scope.
Changes:
- Added
groovy.util.regex.RegexGuard+RegexTimeoutExceptionto enforce evaluation deadlines via a guardedCharSequence. - Added
@groovy.transform.SafeRegexandSafeRegexASTTransformationto rewrite==~/=~usages in annotated classes/methods/constructors intoRegexGuardcalls. - Added tests covering runtime guard behavior and AST transform rewriting, including timeout and semantic-compatibility cases.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| src/main/java/groovy/util/regex/RegexGuard.java | Implements deadline-guarded regex matching/matcher creation and guarded CharSequence. |
| src/main/java/groovy/util/regex/RegexTimeoutException.java | Introduces the unchecked exception signifying a timeout during guarded evaluation. |
| src/main/java/groovy/transform/SafeRegex.java | Adds the @SafeRegex annotation that enables guarded regex operator rewriting in scope. |
| src/main/java/org/codehaus/groovy/transform/SafeRegexASTTransformation.java | AST transform that rewrites regex operators to RegexGuard calls using the configured timeout. |
| src/test/groovy/groovy/util/regex/RegexGuardTest.groovy | Tests runtime guard behavior (matches, matcher, guard, validation, and timeout behavior). |
| src/test/groovy/org/codehaus/groovy/transform/SafeRegexTransformTest.groovy | Tests AST rewrite coverage and preserves expected operator semantics within annotated scope. |
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## master #2668 +/- ##
==================================================
+ Coverage 68.5706% 68.5741% +0.0035%
- Complexity 33808 33842 +34
==================================================
Files 1524 1527 +3
Lines 128141 128238 +97
Branches 23292 23306 +14
==================================================
+ Hits 87867 87938 +71
- Misses 32472 32492 +20
- Partials 7802 7808 +6
🚀 New features to boost your workflow:
|
✅ All tests passed ✅🏷️ Commit: b43a2a6 Learn more about TestLens at testlens.app. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.