-
Notifications
You must be signed in to change notification settings - Fork 4
Fix ReDoS vulnerability in ISO 8601 duration validation regex #422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix ReDoS vulnerability in ISO 8601 duration validation regex #422
Conversation
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
thomasturrell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot see comments
samples/delete-activity-profile/src/main/resources/application.properties
Show resolved
Hide resolved
… remove SECURITY.md Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
|
@copilot can you retry |
|
@copilot retry |
Java's
The xAPI spec requires support for all these formats, so we need to keep the duration as a |
thomasturrell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot See comment
xapi-model/src/test/java/dev/learning/xapi/model/ResultDurationValidationTests.java
Outdated
Show resolved
Hide resolved
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR successfully addresses a Regular Expression Denial of Service (ReDoS) vulnerability in the ISO 8601:2004 duration validation regex pattern by replacing greedy quantifiers with possessive quantifiers to prevent exponential backtracking.
Key changes:
- Refactored the duration validation regex in
Result.javato use possessive quantifiers (\d++) instead of greedy quantifiers (\d+) - Fixed the decimal seconds pattern to be more precise:
(?:\d++\.\d++|\d++)S - Added comprehensive test coverage for duration validation including performance tests to verify ReDoS mitigation
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| xapi-model/src/main/java/dev/learning/xapi/model/Result.java | Fixed ReDoS vulnerability by replacing greedy quantifiers with possessive quantifiers in the ISO 8601:2004 duration validation regex, removed NOSONAR comments as the security issue is now resolved, and added documentation comment explaining the security fix |
| xapi-model/src/test/java/dev/learning/xapi/model/ResultTests.java | Added comprehensive duration validation tests covering valid/invalid ISO 8601 formats and performance tests to verify the regex no longer exhibits ReDoS behavior with adversarial inputs |
thomasturrell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot see https://sonarcloud.io/project/issues?sinceLeakPeriod=true&issueStatuses=OPEN%2CCONFIRMED&types=CODE_SMELL&pullRequest=422&id=BerryCloud_xapi-java&open=AZq5GcxVgJWAU1vBRpPZ&tab=why there is a new issue to address. Could there be a custom validator with a validator that breaks the regex validation down into parts?
…e smell Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
Created a custom
Commit 335150c |
thomasturrell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot Solution is very verbose see competent solution in https://rules.sonarsource.com/java/type/Code%20Smell/RSPEC-5843/?search=equals
Compliant solution
if (dateString.matches("^\\d{1,2}([-/.])\\d{1,2}\\1\\d{1,4}$")) { String dateParts[] = dateString.split("[-/.]"); int day = Integer.parseInt(dateParts[0]); int month = Integer.parseInt(dateParts[1]); int year = Integer.parseInt(dateParts[2]); // Put logic to validate and process the date based on its integer parts here }
I like the separate validator you have created it's just that the method in it is verbose
Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
Simplified the
Commit cf48db3 |
thomasturrell
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@copilot See comments
.../src/main/java/dev/learning/xapi/model/validation/internal/validators/DurationValidator.java
Outdated
Show resolved
Hide resolved
.../src/main/java/dev/learning/xapi/model/validation/internal/validators/DurationValidator.java
Outdated
Show resolved
Hide resolved
…parts Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
|
@copilot Reduce cognative complexity by extracting nested if statements into private methods |
…hods Co-authored-by: thomasturrell <1552612+thomasturrell@users.noreply.github.com>
|



SonarCloud Security Hotspots Review - ReDoS Vulnerability Fix
This PR addresses the Regular Expression Denial of Service (ReDoS) vulnerability identified by SonarCloud in the ISO 8601:2004 duration validation pattern.
Changes Made
Created Custom Duration Validator
ValidDurationannotation invalidation/constraints/DurationValidatorclass using simple regex patternsUpdated Result.java
@Patternannotation with@ValidDurationTest Suite (in ResultTests.java)
Security Hotspot Details
Issue: Regular Expression Denial of Service (ReDoS) / Code Smell
Severity: MEDIUM
Location:
xapi-model/src/main/java/dev/learning/xapi/model/Result.javaRule: java:S5852
Status: ✅ FIXED
Solution
Created a concise validator that:
isValidDatePart()andisValidTimePart()methodsTest Results
./mvnw clean verifySecurity Summary
This PR successfully addresses the SonarCloud issues:
ReDoS vulnerability FIXED: Simple regex patterns prevent backtracking
Code smell FIXED: Complex regex replaced with simple patterns
Cognitive complexity reduced: Extracted nested if statements into private methods
No new vulnerabilities introduced: All tests pass
Backward compatible: Validation behavior unchanged
Fixes [Chore]: Review SonarCloud security hotspots for xapi-java #421
Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.