Spring-boot: REST Endpoint unreachable if ID in URL contains %2F

Created on 19 Sep 2014  路  4Comments  路  Source: spring-projects/spring-boot

Version: Spring Boot 1.1.6

My assumption is that, this issue is related to https://jira.spring.io/browse/SPR-11101

URL:

http://localhost:9090/api/registration/7QMxEZSrvaWPVhq6eBAa4Q%2F%2Fwy6lUL5hdEvDb5QiT4ixdKZpQKnmoM4nmo7Iiu1A

If I remove %2F, it works fine.

http://localhost:9090/api/registration/7QMxEZSrvaWPVhq6eBAa4Qwy6lUL5hdEvDb5QiT4ixdKZpQKnmoM4nmo7Iiu1A

Most helpful comment

I think your assumption that this is related to SPR-11101 is correct. Have you tried following the guidance in that issue? You need to set the Tomcat system property to allow encoded slashes and also disable url decoding on UrlPathHelper. For example:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends WebMvcConfigurerAdapter {

    public static void main(String[] args) throws Exception {
        System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        UrlPathHelper urlPathHelper = new UrlPathHelper();
        urlPathHelper.setUrlDecode(false);
        configurer.setUrlPathHelper(urlPathHelper);
    }

}

All 4 comments

The base64url encoding solved the problem: http://tools.ietf.org/html/rfc4648#page-7

import org.apache.commons.codec.binary.Base64;
...
Base64 b64 = new Base64(0, null, true);

I think your assumption that this is related to SPR-11101 is correct. Have you tried following the guidance in that issue? You need to set the Tomcat system property to allow encoded slashes and also disable url decoding on UrlPathHelper. For example:

@Configuration
@EnableAutoConfiguration
@ComponentScan
public class Application extends WebMvcConfigurerAdapter {

    public static void main(String[] args) throws Exception {
        System.setProperty("org.apache.tomcat.util.buf.UDecoder.ALLOW_ENCODED_SLASH", "true");
        SpringApplication.run(Application.class, args);
    }

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        UrlPathHelper urlPathHelper = new UrlPathHelper();
        urlPathHelper.setUrlDecode(false);
        configurer.setUrlPathHelper(urlPathHelper);
    }

}

Wonderful!!!

Setting this system property works fine only one %2F appear in the URL. In my case, I'm getting two %2F. Can you please advise if there is way this could be handled.

Was this page helpful?
0 / 5 - 0 ratings