|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2010 the original author or authors. |
| 2 | + * Copyright 2002-2011 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
@@ -75,7 +75,7 @@ public ResourceHttpRequestHandler() {
|
75 | 75 | * for serving static resources.
|
76 | 76 | */
|
77 | 77 | public void setLocations(List<Resource> locations) {
|
78 |
| - Assert.notEmpty(locations, "Location list must not be empty"); |
| 78 | + Assert.notEmpty(locations, "Locations list must not be empty"); |
79 | 79 | this.locations = locations;
|
80 | 80 | }
|
81 | 81 |
|
@@ -142,7 +142,7 @@ protected Resource getResource(HttpServletRequest request) {
|
142 | 142 | HandlerMapping.PATH_WITHIN_HANDLER_MAPPING_ATTRIBUTE + "' is not set");
|
143 | 143 | }
|
144 | 144 |
|
145 |
| - if (!StringUtils.hasText(path) || path.contains("WEB-INF") || path.contains("META-INF")) { |
| 145 | + if (!StringUtils.hasText(path) || isInvalidPath(path)) { |
146 | 146 | if (logger.isDebugEnabled()) {
|
147 | 147 | logger.debug("Ignoring invalid resource path [" + path + "]");
|
148 | 148 | }
|
@@ -172,6 +172,17 @@ else if (logger.isTraceEnabled()) {
|
172 | 172 | return null;
|
173 | 173 | }
|
174 | 174 |
|
| 175 | + /** |
| 176 | + * Validates the given path: returns {@code true} if the given path is not a valid resource path. |
| 177 | + * <p>The default implementation rejects paths containing "WEB-INF" or "META-INF" as well as paths |
| 178 | + * with relative paths ("../") that result in access of a parent directory. |
| 179 | + * @param path the path to validate |
| 180 | + * @return {@code true} if the path has been recognized as invalid, {@code false} otherwise |
| 181 | + */ |
| 182 | + protected boolean isInvalidPath(String path) { |
| 183 | + return (path.contains("WEB-INF") || path.contains("META-INF") || StringUtils.cleanPath(path).startsWith("..")); |
| 184 | + } |
| 185 | + |
175 | 186 | /**
|
176 | 187 | * Determine an appropriate media type for the given resource.
|
177 | 188 | * @param resource the resource to check
|
|
0 commit comments