-
Notifications
You must be signed in to change notification settings - Fork 38.5k
ResourceUrlEncodingFilter causes LookupPathIndexException resulting in HTTP 400 when processing URLs indirectly referencing Welcome Files #25013
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
Comments
Thanks for your repro project @tknall, this is really useful to understand such complex issues. I'll try first to summarize the problem. Previously , the Now the error message displayed comes from #22851, because without that fix, we'd get an out of bounds exceptions instead. This happens because of what you've pointed out: if the request URI and the lookup path are out of sync, we can't derive the required information. So this issue really happens because of a combination between #21954 (extracting earlier) and #22851 (checking that the request URI and lookup path are related). In this example, the request URI and lookup path don't share a common prefix, since the Servlet container rewrites the servlet path from I'm wondering about two solutions:
@rstoyanchev what do you think? |
This is based on the default Servlet mapping @Configuration
@EnableWebMvc
public class MyWebApplicationConfig implements WebMvcConfigurer {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper pathHelper = new UrlPathHelper();
pathHelper.setAlwaysUseFullPath(true);
configurer.setUrlPathHelper(pathHelper);
}
// ...
} The app should now work just the same but more efficiently because @Configuration
@EnableWebMvc
public class MyWebApplicationConfig implements WebMvcConfigurer {
@Override
public void configurePathMatch(PathMatchConfigurer configurer) {
UrlPathHelper pathHelper = new UrlPathHelper();
pathHelper.setAlwaysUseFullPath(true);
configurer.setUrlPathHelper(pathHelper);
}
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addRedirectViewController("app", "app/");
registry.addViewController("app/").setViewName("forward:index.html");
}
// ...
} This is really worth doing in any case in order to avoid any sort of reliance on the Servlet path which is bad in all sorts of ways. Some of that is explained under #25100 where you can also see that in 5.3 we are going to automatically set |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
@rstoyanchev Your approach (making UrlPathHelper always perform full patch lookup and adding a dedicated view for the respective welcome file) indeed does the trick but imho its more or less still a kind of workaround (imho) which does not appear very intuitive. The problem still remains part of the code... |
Given what's been done in #25100 and spring-projects/spring-boot#21499 (where this configuration option is used whenever possible), I don't think we can really consider this as a workaround, but rather a sensible configuration option to align with your Servlet container configuration. As explained in #25100, this is not really about Spring Framework optimizing for a specific case, but rather choosing the safest approach to avoid mapping mismatches or security issues in applications. I'm closing this issue since this option fixes the underlying problem and the two linked issues have improved the discoverability of this option since it's mostly done for you now. Thanks! |
Affects: 5.2.6
When the ResourceUrlEncodingFilter receives a parcial request like
/somecontext/app/
- actually referencing Welcome Files (like/somecontext/app/index.html
) - the initialization of the filter fails raising a LookupPathIndexException which finally leads to a HTTP 400 response status code.When requesting URIs like
/somecontext/app/
, the servlet container (e.g. Apache Tomcat) implicitely adds the path to the respective Welcome File to the servlet path within the HttpServletRequest. This is done according to the Servlet Spec:Servlet 3.1, section 10.10 - "Welcome Files"
The ResourceUrlEncodingFilter fails when trying to match lookupPath against requestUri:
The issue was introduced with Spring 4.3.21/5.1.2 probably with commit 50a47691.
I've prepared a minimum demo project to show the issue:
https://github.com/tknall/spring-mvc-demo
Build the maven project, deploy the resulting war file with a Servlet container (e.g. Tomcat 8.5) and run http://localhost:8080/spring-webmvc-demo/app/ actually referencing an underlying welcome file
spring-webmvc-demo/app/index.html
with the browser of your choice.The request fails with
The text was updated successfully, but these errors were encountered: