|
15 | 15 | */ |
16 | 16 | package org.geowebcache.rest.controller; |
17 | 17 |
|
| 18 | +import java.io.File; |
18 | 19 | import java.io.IOException; |
19 | 20 | import java.io.InputStream; |
20 | | -import java.io.UnsupportedEncodingException; |
21 | 21 | import java.net.URL; |
22 | 22 | import java.net.URLDecoder; |
23 | 23 | import java.util.List; |
@@ -79,22 +79,21 @@ protected URL getResource(String path) { |
79 | 79 |
|
80 | 80 | // "gwc/rest/web/openlayers3/ol.js" -> openlayers3/ol.js |
81 | 81 | // "/rest/web/openlayers3/ol.js" -> openlayers3/ol.js |
82 | | - String getFileName(HttpServletRequest request) { |
83 | | - String path = request.getPathInfo(); |
84 | | - if (path.indexOf("/rest/web") != 0) { |
85 | | - path = path.substring(path.indexOf("/rest/web")); |
86 | | - } |
87 | | - return path.substring("/rest/web/".length()); |
| 82 | + String getFileName(HttpServletRequest request) throws IOException { |
| 83 | + String path = |
| 84 | + URLDecoder.decode(request.getRequestURI(), "UTF-8") |
| 85 | + .substring(request.getContextPath().length()) |
| 86 | + .replace(File.separatorChar, '/'); |
| 87 | + int index = path.indexOf("/rest/web/"); |
| 88 | + return index < 0 ? null : path.substring(index + "/rest/web/".length()); |
88 | 89 | } |
89 | 90 |
|
90 | 91 | @RequestMapping(value = "/web/**", method = RequestMethod.GET) |
91 | | - ResponseEntity<?> doGet(HttpServletRequest request, HttpServletResponse response) { |
92 | | - final String filename; |
93 | | - try { |
94 | | - filename = URLDecoder.decode(getFileName(request), "UTF-8"); |
95 | | - } catch (UnsupportedEncodingException e1) { |
96 | | - throw new IllegalStateException( |
97 | | - "Could not decode encoding UTF-8", e1); // Should never happen |
| 92 | + ResponseEntity<?> doGet(HttpServletRequest request, HttpServletResponse response) |
| 93 | + throws IOException { |
| 94 | + final String filename = getFileName(request); |
| 95 | + if (filename == null || filename.isEmpty()) { |
| 96 | + return new ResponseEntity<>(HttpStatus.NOT_FOUND); |
98 | 97 | } |
99 | 98 |
|
100 | 99 | // Just to make sure we don't allow access to arbitrary resources |
|
0 commit comments