@@ -431,14 +431,20 @@ public FirewalledRequest getFirewalledRequest(HttpServletRequest request) throws
431
431
if (!isNormalized (request )) {
432
432
throw new RequestRejectedException ("The request was rejected because the URL was not normalized." );
433
433
}
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" );
439
438
return new StrictFirewalledRequest (request );
440
439
}
441
440
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
+
442
448
private void rejectForbiddenHttpMethod (HttpServletRequest request ) {
443
449
if (this .allowedHttpMethods == ALLOW_ANY_HTTP_METHOD ) {
444
450
return ;
@@ -526,6 +532,9 @@ private static boolean decodedUrlContains(HttpServletRequest request, String val
526
532
}
527
533
528
534
private static boolean containsOnlyPrintableAsciiCharacters (String uri ) {
535
+ if (uri == null ) {
536
+ return true ;
537
+ }
529
538
int length = uri .length ();
530
539
for (int i = 0 ; i < length ; i ++) {
531
540
char ch = uri .charAt (i );
0 commit comments