|
|
|
@ -431,14 +431,20 @@ public class StrictHttpFirewall implements HttpFirewall { |
|
|
|
if (!isNormalized(request)) { |
|
|
|
if (!isNormalized(request)) { |
|
|
|
throw new RequestRejectedException("The request was rejected because the URL was not normalized."); |
|
|
|
throw new RequestRejectedException("The request was rejected because the URL was not normalized."); |
|
|
|
} |
|
|
|
} |
|
|
|
String requestUri = request.getRequestURI(); |
|
|
|
rejectNonPrintableAsciiCharactersInFieldName(request.getRequestURI(), "requestURI"); |
|
|
|
if (!containsOnlyPrintableAsciiCharacters(requestUri)) { |
|
|
|
rejectNonPrintableAsciiCharactersInFieldName(request.getServletPath(), "servletPath"); |
|
|
|
throw new RequestRejectedException( |
|
|
|
rejectNonPrintableAsciiCharactersInFieldName(request.getPathInfo(), "pathInfo"); |
|
|
|
"The requestURI was rejected because it can only contain printable ASCII characters."); |
|
|
|
rejectNonPrintableAsciiCharactersInFieldName(request.getContextPath(), "contextPath"); |
|
|
|
} |
|
|
|
|
|
|
|
return new StrictFirewalledRequest(request); |
|
|
|
return new StrictFirewalledRequest(request); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void rejectNonPrintableAsciiCharactersInFieldName(String toCheck, String propertyName) { |
|
|
|
|
|
|
|
if (!containsOnlyPrintableAsciiCharacters(toCheck)) { |
|
|
|
|
|
|
|
throw new RequestRejectedException(String.format( |
|
|
|
|
|
|
|
"The %s was rejected because it can only contain printable ASCII characters.", propertyName)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void rejectForbiddenHttpMethod(HttpServletRequest request) { |
|
|
|
private void rejectForbiddenHttpMethod(HttpServletRequest request) { |
|
|
|
if (this.allowedHttpMethods == ALLOW_ANY_HTTP_METHOD) { |
|
|
|
if (this.allowedHttpMethods == ALLOW_ANY_HTTP_METHOD) { |
|
|
|
return; |
|
|
|
return; |
|
|
|
@ -526,6 +532,9 @@ public class StrictHttpFirewall implements HttpFirewall { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private static boolean containsOnlyPrintableAsciiCharacters(String uri) { |
|
|
|
private static boolean containsOnlyPrintableAsciiCharacters(String uri) { |
|
|
|
|
|
|
|
if (uri == null) { |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
int length = uri.length(); |
|
|
|
int length = uri.length(); |
|
|
|
for (int i = 0; i < length; i++) { |
|
|
|
for (int i = 0; i < length; i++) { |
|
|
|
char ch = uri.charAt(i); |
|
|
|
char ch = uri.charAt(i); |
|
|
|
|