GROOVY-12122: Provide a Regex timeout facility#2668
Draft
paulk-asert wants to merge 5 commits into
Draft
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.7199% +0.1493%
- Complexity 33808 34177 +369
==================================================
Files 1524 1539 +15
Lines 128141 129034 +893
Branches 23292 23402 +110
==================================================
+ Hits 87867 88672 +805
- Misses 32472 32516 +44
- Partials 7802 7846 +44
🚀 New features to boost your workflow:
|
…AL_VARIABLE targets)
…ion, RegexChecker coverage, docs)
✅ All tests passed ✅🏷️ Commit: aba6141 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.