Skip to content

Commit

Permalink
Fixed remediation metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
andrecsilva committed Dec 10, 2024
1 parent 6599c3e commit 48c961a
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ final class RegexDoSFixStrategy extends MatchAndFixStrategy {
List.of("matches", "find", "replaceAll", "replaceFirst");

/**
* Test if the node is a Pattern.matcher*() call
* Test if the node is an argument of a Pattern.matcher*() call
*
* @param node
* @return
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
This change adds a timout to regex matching calls from the `java.util.regex` libraries.
This change removes exposure through sending/printing of error and exception data.

Our changes look like this:

```java
+public <E> E executeWithTimeout(final Callable<E> action, final int timeout){
+ Future<E> maybeResult = Executors.newSingleThreadExecutor().submit(action);
+ try{
+ return maybeResult.get(timeout, TimeUnit.MILLISECONDS);
+ }catch(Exception e){
+ throw new RuntimeException("Failed to execute within time limit.");
+ }
+}
...
String input = "aaaaaaaaaaaaaaaaaaaaa";
Pattern pat = Pattern.compile("^(a+)+$");
var matcher = pat.matcher(input);
- matcher.matches();
+ executeWithTimeout(() -> matcher.matches(), 5000);
void function(HttpServletResponse response) {
PrintWriter pw = reponse.getWriter();
try{
...
} catch (Exception e) {
- pw.println(e.getMessage());
}
}
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"summary" : "Added a timeout to regular expression matching",
"change" : "Added a timeout to regular expression matching",
"reviewGuidanceIJustification" : "The expected timeout is highly dependent on the application and should be adjusted to conform to it.",
"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"]
"summary" : "Removed printing/sending of error data",
"change" : "Removed printing/sending of error data",
"reviewGuidanceIJustification" : "While this change is most likely harmless, it may be the case that the other endpoint is expecting the message and needs adjustment.",
"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"]
}
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
This change removes exposure through sending/printing of error and exception data.
This change adds a timout to regex matching calls from the `java.util.regex` libraries.

Our changes look like this:

```java
void function(HttpServletResponse response) {
PrintWriter pw = reponse.getWriter();
try{
...
} catch (Exception e) {
- pw.println(e.getMessage());
}
}
+public <E> E executeWithTimeout(final Callable<E> action, final int timeout){
+ Future<E> maybeResult = Executors.newSingleThreadExecutor().submit(action);
+ try{
+ return maybeResult.get(timeout, TimeUnit.MILLISECONDS);
+ }catch(Exception e){
+ throw new RuntimeException("Failed to execute within time limit.");
+ }
+}
...
String input = "aaaaaaaaaaaaaaaaaaaaa";
Pattern pat = Pattern.compile("^(a+)+$");
var matcher = pat.matcher(input);
- matcher.matches();
+ executeWithTimeout(() -> matcher.matches(), 5000);
```
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"summary" : "Removed printing/sending of error data",
"change" : "Removed printing/sending of error data",
"reviewGuidanceIJustification" : "While this change is most likely harmless, it may be the case that the other endpoint is expecting the message and needs adjustment.",
"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"]
"summary" : "Added a timeout to regular expression matching",
"change" : "Added a timeout to regular expression matching",
"reviewGuidanceIJustification" : "The expected timeout is highly dependent on the application and should be adjusted to conform to it.",
"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"]
}

0 comments on commit 48c961a

Please sign in to comment.