-
Notifications
You must be signed in to change notification settings - Fork 38.5k
MappedInterceptor in 5.3 does not support all AntPatternMatcher patterns #26690
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
The idea is that the syntax is largely the same and it shouldn't matter, and especially a mapped interceptor isn't going to run into the number and variety of patterns that one might see on annotated controllers. That said there are indeed some differences which make this a regression for your application. Keep in mind that mapping by extension has been deprecated in 5.3 as explained in this section of the reference and there are an inherent security threat. Before we discuss how to address, can you confirm the exact types of pattern issues you ran into? Is it something like "/foo" that should also support "/foo.*" or is there more? One obvious option would be to explicitly add the extension patterns. |
Any suffixes like I agree with suffixes being a security issue and the apparent ambiguity of ‘**’ in the middle patterns, however, the MappedInterceptor constructor makes these impossible, whereas the documentation and the code elsewhere, including in the class itself, assumes the compatibility with AntPathMatcher is still there, hence the problem. In reality, Spring 5.3 doesn’t just deprecate but eliminates the use of AntPathMatcher and that is a big regression, hence the proposed fix. |
That's what I'm trying to narrow down. The first |
I'm trying to establish which patterns you have. If it is about suffix pattern matching, then this is not related to the changes in |
I've used the documented PathMatchConfigurer specifically for the old behavior, see below, to no avail. As shown above, it will @Configuration
@EnableWebMvc
public class WebConfig implements WebMvcConfigurer {
@Override
public void configurePathMatch(final PathMatchConfigurer configurer) {
configurer
.setPathMatcher(new AntPathMatcher())
.setUseSuffixPatternMatch(true)
.setUseRegisteredSuffixPatternMatch(true)
// .setPatternParser(null)
.setUrlPathHelper(UrlPathHelper.defaultInstance);
}
@Override
public void configureContentNegotiation(final ContentNegotiationConfigurer configurer) {
configurer.favorPathExtension(true);
}
@Override
public void addInterceptors(final InterceptorRegistry registry) {
registry
.addInterceptor(new MyInterceptor())
.addPathPatterns("/**")
.excludePathPatterns("/", "/**/*.css", "/path1/**/path2");
}
} |
This should be fixed now. If you can please give it a try with 5.3.6 snapshots. |
Thank you so much, @rstoyanchev, it works! |
@rstoyanchev this issue is happening with spring 6.0.8. Did something change again? I can see that this constructor is getting called - And the parser being passed is always null, so PathPatternParser is used. And if the pattern has I am already overriding I am not sure if something has changed by default in 6.0.8, but if you can suggest how to fix this, it would be great. This is a major blocker for moving to Spring 6. |
Nothing significant has changed in |
Spring Framework 5.3 (up to 5.3.5)
MappedInterceptor
's constructor effectively prevents the use of anyPathMatcher
, including legacyAntPathMatcher
, making it completely incompatible with all earlier versions. Here is why:InterceptorRegistration#getInterceptor
tries to createMappedInterceptor
, however it'll fail, due to 2.MappedInterceptor
's base constructor calls MappedInterceptor#initPatterns, which would use the defaultPathPatternParser
and will fail for the Ant-like patterns and suffixes (old style) no matter whether set inPathMatchConfigurer
or not:The problem is that include/excludePatterns type have changed from String[] to PathPattern[]. As a possible solution to this could be having a chameleon PathPattern, i.e. NOOP PathPattern holding just the String underneath and having isNoop() to differentiate from the real ones, to be used in concert with the MappedInterceptor constructor with a PathMatcher parameter, and the rest of the MappedInterceptor code checking for isNoop() accordingly.
In addition,
MappedInterceptor(@Nullable String[] includePatterns, @Nullable String[] excludePatterns, HandlerInterceptor interceptor)
can be using such NOOP PathPattern and be compatible withInterceptorRegistration#getInterceptor
and friends.Unless there is a simple and obvious solution/config already, this is a major, showstopper bug.
Thanks much in advance,
David
The text was updated successfully, but these errors were encountered: