Skip to content

Commit

Permalink
Ensure Polynomial regular expression is used on controlled data
Browse files Browse the repository at this point in the history
  • Loading branch information
sebr72 committed May 15, 2024
1 parent cb17ece commit f43fca7
Showing 1 changed file with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,12 @@ protected final void sendReportFile(
httpServletResponse.setContentType(metadata.getResult().getMimeType());
if (!inline) {
String fileName = metadata.getResult().getFileName();
Matcher matcher = VARIABLE_PATTERN.matcher(fileName);
Matcher matcher = getFileNameMatcher(fileName);
while (matcher.find()) {
final String variable = matcher.group(1);
String replacement = findReplacement(variable, metadata.getCompletionDate());
fileName = fileName.replace("${" + variable + "}", replacement);
matcher = VARIABLE_PATTERN.matcher(fileName);
matcher = getFileNameMatcher(fileName);
}

fileName += "." + metadata.getResult().getFileExtension();
Expand All @@ -108,6 +108,13 @@ protected final void sendReportFile(
}
}

private static Matcher getFileNameMatcher(final String fileName) {
if (fileName.length() > 1000) {
throw new IllegalArgumentException("File name is too long");
}
return VARIABLE_PATTERN.matcher(fileName);

Check failure

Code scanning / CodeQL

Polynomial regular expression used on uncontrolled data High

This
regular expression
that depends on a
user-provided value
may run slow on strings starting with '${' and with many repetitions of '${!'.
This
regular expression
that depends on a
user-provided value
may run slow on strings starting with '${' and with many repetitions of '${!'.
This
regular expression
that depends on a
user-provided value
may run slow on strings starting with '${' and with many repetitions of '${!'.
This
regular expression
that depends on a
user-provided value
may run slow on strings starting with '${' and with many repetitions of '${!'.
This
regular expression
that depends on a
user-provided value
may run slow on strings starting with '${' and with many repetitions of '${!'.
}

/**
* Update a variable name with a date if the variable is detected as being a date.
*
Expand Down

0 comments on commit f43fca7

Please sign in to comment.