Skip to content

Commit 25f1f06

Browse files
committed
Fixed remediation metadata
1 parent 54196e0 commit 25f1f06

File tree

5 files changed

+33
-33
lines changed

5 files changed

+33
-33
lines changed

framework/codemodder-base/src/main/java/io/codemodder/remediation/regexdos/RegexDoSFixStrategy.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ final class RegexDoSFixStrategy extends MatchAndFixStrategy {
3030
List.of("matches", "find", "replaceAll", "replaceFirst");
3131

3232
/**
33-
* Test if the node is a Pattern.matcher*() call
33+
* Test if the node is an argument of a Pattern.matcher*() call
3434
*
3535
* @param node
3636
* @return
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,14 @@
1-
This change adds a timout to regex matching calls from the `java.util.regex` libraries.
1+
This change removes exposure through sending/printing of error and exception data.
22

33
Our changes look like this:
44

55
```java
6-
+public <E> E executeWithTimeout(final Callable<E> action, final int timeout){
7-
+ Future<E> maybeResult = Executors.newSingleThreadExecutor().submit(action);
8-
+ try{
9-
+ return maybeResult.get(timeout, TimeUnit.MILLISECONDS);
10-
+ }catch(Exception e){
11-
+ throw new RuntimeException("Failed to execute within time limit.");
12-
+ }
13-
+}
14-
...
15-
String input = "aaaaaaaaaaaaaaaaaaaaa";
16-
Pattern pat = Pattern.compile("^(a+)+$");
17-
var matcher = pat.matcher(input);
18-
- matcher.matches();
19-
+ executeWithTimeout(() -> matcher.matches(), 5000);
6+
void function(HttpServletResponse response) {
7+
PrintWriter pw = reponse.getWriter();
8+
try{
9+
...
10+
} catch (Exception e) {
11+
- pw.println(e.getMessage());
12+
}
13+
}
2014
```
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"summary" : "Added a timeout to regular expression matching",
3-
"change" : "Added a timeout to regular expression matching",
4-
"reviewGuidanceIJustification" : "The expected timeout is highly dependent on the application and should be adjusted to conform to it.",
5-
"references" : ["https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS", "https://cwe.mitre.org/data/definitions/400.html", "https://github.com/google/re2j"]
2+
"summary" : "Removed printing/sending of error data",
3+
"change" : "Removed printing/sending of error data",
4+
"reviewGuidanceIJustification" : "While this change is most likely harmless, it may be the case that the other endpoint is expecting the message and needs adjustment.",
5+
"references" : ["https://cwe.mitre.org/data/definitions/209.html", "https://owasp.org/www-community/Improper_Error_Handling", "https://www.securecoding.cert.org/confluence/display/java/ERR01-J.+Do+not+allow+exceptions+to+expose+sensitive+information"]
66
}
Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,20 @@
1-
This change removes exposure through sending/printing of error and exception data.
1+
This change adds a timout to regex matching calls from the `java.util.regex` libraries.
22

33
Our changes look like this:
44

55
```java
6-
void function(HttpServletResponse response) {
7-
PrintWriter pw = reponse.getWriter();
8-
try{
9-
...
10-
} catch (Exception e) {
11-
- pw.println(e.getMessage());
12-
}
13-
}
6+
+public <E> E executeWithTimeout(final Callable<E> action, final int timeout){
7+
+ Future<E> maybeResult = Executors.newSingleThreadExecutor().submit(action);
8+
+ try{
9+
+ return maybeResult.get(timeout, TimeUnit.MILLISECONDS);
10+
+ }catch(Exception e){
11+
+ throw new RuntimeException("Failed to execute within time limit.");
12+
+ }
13+
+}
14+
...
15+
String input = "aaaaaaaaaaaaaaaaaaaaa";
16+
Pattern pat = Pattern.compile("^(a+)+$");
17+
var matcher = pat.matcher(input);
18+
- matcher.matches();
19+
+ executeWithTimeout(() -> matcher.matches(), 5000);
1420
```
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"summary" : "Removed printing/sending of error data",
3-
"change" : "Removed printing/sending of error data",
4-
"reviewGuidanceIJustification" : "While this change is most likely harmless, it may be the case that the other endpoint is expecting the message and needs adjustment.",
5-
"references" : ["https://cwe.mitre.org/data/definitions/209.html", "https://owasp.org/www-community/Improper_Error_Handling", "https://www.securecoding.cert.org/confluence/display/java/ERR01-J.+Do+not+allow+exceptions+to+expose+sensitive+information"]
2+
"summary" : "Added a timeout to regular expression matching",
3+
"change" : "Added a timeout to regular expression matching",
4+
"reviewGuidanceIJustification" : "The expected timeout is highly dependent on the application and should be adjusted to conform to it.",
5+
"references" : ["https://owasp.org/www-community/attacks/Regular_expression_Denial_of_Service_-_ReDoS", "https://cwe.mitre.org/data/definitions/400.html", "https://github.com/google/re2j"]
66
}

0 commit comments

Comments
 (0)