@ -523,7 +523,8 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
protected String processPath ( String path ) {
protected String processPath ( String path ) {
path = StringUtils . replace ( path , "\\" , "/" ) ;
path = StringUtils . replace ( path , "\\" , "/" ) ;
path = cleanDuplicateSlashes ( path ) ;
path = cleanDuplicateSlashes ( path ) ;
return cleanLeadingSlash ( path ) ;
path = cleanLeadingSlash ( path ) ;
return normalizePath ( path ) ;
}
}
private String cleanDuplicateSlashes ( String path ) {
private String cleanDuplicateSlashes ( String path ) {
@ -565,6 +566,21 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
return ( slash ? "/" : "" ) ;
return ( slash ? "/" : "" ) ;
}
}
private static String normalizePath ( String path ) {
if ( path . contains ( "%" ) ) {
try {
path = URLDecoder . decode ( path , StandardCharsets . UTF_8 ) ;
}
catch ( Exception ex ) {
return "" ;
}
if ( path . contains ( "../" ) ) {
path = StringUtils . cleanPath ( path ) ;
}
}
return path ;
}
/ * *
/ * *
* Check whether the given path contains invalid escape sequences .
* Check whether the given path contains invalid escape sequences .
* @param path the path to validate
* @param path the path to validate
@ -623,7 +639,7 @@ public class ResourceWebHandler implements WebHandler, InitializingBean {
return true ;
return true ;
}
}
}
}
if ( path . contains ( ".." ) & & StringUtils . cleanPath ( path ) . contains ( ".. /" ) ) {
if ( path . contains ( "../" ) ) {
if ( logger . isWarnEnabled ( ) ) {
if ( logger . isWarnEnabled ( ) ) {
logger . warn ( LogFormatUtils . formatValue (
logger . warn ( LogFormatUtils . formatValue (
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]" , - 1 , true ) ) ;
"Path contains \"../\" after call to StringUtils#cleanPath: [" + path + "]" , - 1 , true ) ) ;