@@ -431,14 +431,20 @@ public FirewalledRequest getFirewalledRequest(HttpServletRequest request) throws
431431 if (!isNormalized (request )) {
432432 throw new RequestRejectedException ("The request was rejected because the URL was not normalized." );
433433 }
434- String requestUri = request .getRequestURI ();
435- if (!containsOnlyPrintableAsciiCharacters (requestUri )) {
436- throw new RequestRejectedException (
437- "The requestURI was rejected because it can only contain printable ASCII characters." );
438- }
434+ rejectNonPrintableAsciiCharactersInFieldName (request .getRequestURI (), "requestURI" );
435+ rejectNonPrintableAsciiCharactersInFieldName (request .getServletPath (), "servletPath" );
436+ rejectNonPrintableAsciiCharactersInFieldName (request .getPathInfo (), "pathInfo" );
437+ rejectNonPrintableAsciiCharactersInFieldName (request .getContextPath (), "contextPath" );
439438 return new StrictFirewalledRequest (request );
440439 }
441440
441+ private void rejectNonPrintableAsciiCharactersInFieldName (String toCheck , String propertyName ) {
442+ if (!containsOnlyPrintableAsciiCharacters (toCheck )) {
443+ throw new RequestRejectedException (String .format (
444+ "The %s was rejected because it can only contain printable ASCII characters." , propertyName ));
445+ }
446+ }
447+
442448 private void rejectForbiddenHttpMethod (HttpServletRequest request ) {
443449 if (this .allowedHttpMethods == ALLOW_ANY_HTTP_METHOD ) {
444450 return ;
@@ -526,6 +532,9 @@ private static boolean decodedUrlContains(HttpServletRequest request, String val
526532 }
527533
528534 private static boolean containsOnlyPrintableAsciiCharacters (String uri ) {
535+ if (uri == null ) {
536+ return true ;
537+ }
529538 int length = uri .length ();
530539 for (int i = 0 ; i < length ; i ++) {
531540 char ch = uri .charAt (i );
0 commit comments