Getting 404 Error when URL contains double slash after Spring Boot 2.5 to 2.6 migration

Viewed 2304

The following URL used to return 200 with Spring Boot 2.5

http://localhost:8080//actuator/health

After upgrading to 2.6 it no longer works and returns 404 Not Found

I spotted the error because some of the project's integration tests were failing (requests returned 404). Then I noticed the double slash, and after removing it, the issue was fixed.

I just want to understand which feature causes this new behavior?

I went through the 2.6 release notes several times, but nothing rings a bell.

3 Answers

The issue was that the path matching strategy has changed. The actuator path pattern CANNOT be overwritten by

spring.mvc.pathmatch.matching-strategy=ant-path-matcher

The solution was to manually fix the URLs containing double slashes.

  1. Are you able to access actuator endpoint with single slash? like http://localhost:8080/actuator/health

  2. If yes, then did you configure the spring security for your application? There is a configuration you can define where your application will allow consecutive slashes in url.

    @Bean
    HttpFirewall httpFirewall() {
        StrictHttpFirewall firewall = new StrictHttpFirewall();
        firewall.setAllowUrlEncodedDoubleSlash(true);
        return firewall;
    }
    

here maybe the reason : PathPattern Based Path Matching Strategy for Spring MVC

The default strategy for matching request paths against registered Spring MVC handler mappings has changed from AntPathMatcher to PathPatternParser.

fix:

spring.mvc.pathmatch.matching-strategy=ant-path-matcher
Related