Skip to content

Static resource support does not handle requests for a file with % character in its name #23463

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wilkinsona opened this issue Aug 14, 2019 · 2 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Milestone

Comments

@wilkinsona
Copy link
Member

wilkinsona commented Aug 14, 2019

Affects: 5.2.0.RC1 (earlier versions may also be affected)

When a request is made for a static resource with a % in its file name, PathResourceResolver attempts to decode the path to check for the presence of encoded ../ or ..\. This fails when the path is, for example, test%file.txt from a GET request for /test%25file.txt. The failure is the following:

Caused by: java.lang.IllegalArgumentException: URLDecoder: Illegal hex characters in escape (%) pattern - For input string: "fi"
	at java.net.URLDecoder.decode(URLDecoder.java:194) ~[na:1.8.0_181]
	at org.springframework.web.servlet.resource.PathResourceResolver.isInvalidEncodedPath(PathResourceResolver.java:285) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.PathResourceResolver.isResourceUnderLocation(PathResourceResolver.java:254) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.PathResourceResolver.checkResource(PathResourceResolver.java:211) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:186) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.PathResourceResolver.getResource(PathResourceResolver.java:154) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.PathResourceResolver.resolveResourceInternal(PathResourceResolver.java:136) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.AbstractResourceResolver.resolveResource(AbstractResourceResolver.java:45) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.DefaultResourceResolverChain.resolveResource(DefaultResourceResolverChain.java:74) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.getResource(ResourceHttpRequestHandler.java:526) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.resource.ResourceHttpRequestHandler.handleRequest(ResourceHttpRequestHandler.java:451) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.mvc.HttpRequestHandlerAdapter.handle(HttpRequestHandlerAdapter.java:53) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1039) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:942) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1005) ~[spring-webmvc-5.2.0.RC1.jar:5.2.0.RC1]
	... 47 common frames omitted
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 14, 2019
@Sauhardstark
Copy link
Contributor

@wilkinsona Hi
I have checked and this issue is present in at least one more place.

ResourceHttpRequestHandler.isInvalidEncodedPath(String) line: 607

This is when I try to map a URI to the same path (/test%file) with any http method and request the path /test%25file

@rstoyanchev rstoyanchev added in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Aug 20, 2019
@rstoyanchev rstoyanchev added this to the 5.1.10 milestone Aug 20, 2019
@rstoyanchev rstoyanchev self-assigned this Aug 20, 2019
@rstoyanchev
Copy link
Contributor

@Sauhardstark, are you actually getting this error? ResourceHttpRequestHandler#isInvalidEncodedPath catches and suppresses IllegalArgumentException so I don't think it's exposed to this problem. There is even a test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants