Skip to content

Commit f046a06

Browse files
committed
Simplified separator check within isInvalidEncodedPath
Issue: SPR-16616
1 parent 6e1cac9 commit f046a06

File tree

2 files changed

+14
-19
lines changed

2 files changed

+14
-19
lines changed

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/PathResourceResolver.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -285,13 +285,9 @@ private boolean isInvalidEncodedPath(String resourcePath) {
285285
// Use URLDecoder (vs UriUtils) to preserve potentially decoded UTF-8 chars...
286286
try {
287287
String decodedPath = URLDecoder.decode(resourcePath, "UTF-8");
288-
int separatorIndex = decodedPath.indexOf("..") + 2;
289-
if (separatorIndex > 1 && separatorIndex < decodedPath.length()) {
290-
char separator = decodedPath.charAt(separatorIndex);
291-
if (separator == '/' || separator == '\\') {
292-
if (logger.isTraceEnabled()) {
293-
logger.trace("Resolved resource path contains \"../\" after decoding: " + resourcePath);
294-
}
288+
if (decodedPath.contains("../") || decodedPath.contains("..\\")) {
289+
if (logger.isTraceEnabled()) {
290+
logger.trace("Ignoring invalid resource path with escape sequences [" + resourcePath + "]");
295291
}
296292
return true;
297293
}

spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,24 +69,23 @@
6969
* according to the guidelines of Page Speed, YSlow, etc.
7070
*
7171
* <p>The {@linkplain #setLocations "locations"} property takes a list of Spring
72-
* {@link Resource} locations from which static resources are allowed to
73-
* be served by this handler. Resources could be served from a classpath location,
74-
* e.g. "classpath:/META-INF/public-web-resources/", allowing convenient packaging
72+
* {@link Resource} locations from which static resources are allowed to be served
73+
* by this handler. Resources could be served from a classpath location, e.g.
74+
* "classpath:/META-INF/public-web-resources/", allowing convenient packaging
7575
* and serving of resources such as .js, .css, and others in jar files.
7676
*
7777
* <p>This request handler may also be configured with a
7878
* {@link #setResourceResolvers(List) resourcesResolver} and
7979
* {@link #setResourceTransformers(List) resourceTransformer} chains to support
80-
* arbitrary resolution and transformation of resources being served. By default a
81-
* {@link PathResourceResolver} simply finds resources based on the configured
82-
* "locations". An application can configure additional resolvers and
83-
* transformers such as the {@link VersionResourceResolver} which can resolve
84-
* and prepare URLs for resources with a version in the URL.
80+
* arbitrary resolution and transformation of resources being served. By default
81+
* a {@link PathResourceResolver} simply finds resources based on the configured
82+
* "locations". An application can configure additional resolvers and transformers
83+
* such as the {@link VersionResourceResolver} which can resolve and prepare URLs
84+
* for resources with a version in the URL.
8585
*
86-
* <p>This handler also properly evaluates the {@code Last-Modified} header (if
87-
* present) so that a {@code 304} status code will be returned as appropriate,
88-
* avoiding unnecessary overhead for resources that are already cached by the
89-
* client.
86+
* <p>This handler also properly evaluates the {@code Last-Modified} header
87+
* (if present) so that a {@code 304} status code will be returned as appropriate,
88+
* avoiding unnecessary overhead for resources that are already cached by the client.
9089
*
9190
* @author Keith Donald
9291
* @author Jeremy Grelle

0 commit comments

Comments
 (0)