【问题标题】:Spring boot exact comma next to the path variable路径变量旁边的Spring Boot精确逗号
【发布时间】:2020-04-02 22:32:07
【问题描述】:

我有一个 2.1.0.RELEASE 版本的 Spring Boot 应用。

我的 url 中有一个路径变量,例如 @GetMapping("/{type}/car"),我调用我的应用程序:

http://localhost:8080/BMW;AAAAAAAAAAAAA/car 

但我只得到宝马字符串。 Spring跳过精确的逗号和“AAAAAAAAAAAAA”。

我应用了一个过滤器,我对它有相同的体验。我想得到像“BMW;AAAAAAAAAAAAAA”这样的路径变量,但我不明白。

之所以要过滤这种呼出,是因为它是一个安全漏洞。

【问题讨论】:

标签: java spring-boot security


【解决方案1】:

先尝试编码,值将是这个BMW%3BAAAAAAAAAAAAA,可以使用UriUtils进行编码和解码。

【讨论】:

    【解决方案2】:

    我找到了一个可能的解决方案:

    @Configuration
    public class SolutionConfig extends WebMvcConfigurationSupport {
    
    @Override
    protected PathMatchConfigurer getPathMatchConfigurer() {
        PathMatchConfigurer pathMatchConfigurer = super.getPathMatchConfigurer();
        UrlPathHelper urlPathHelper = new UrlPathHelper();
        urlPathHelper.setRemoveSemicolonContent(false);
        pathMatchConfigurer.setUrlPathHelper(urlPathHelper);
        return pathMatchConfigurer;
        }
    }
    

    源码链接:https://github.com/spring-projects/spring-framework/blob/master/spring-web/src/main/java/org/springframework/web/util/UrlPathHelper.java

    关键方法名称是“removeSemicolonContent”。

    【讨论】:

      猜你喜欢
      • 2020-09-26
      • 2019-01-03
      • 1970-01-01
      • 2020-05-10
      • 1970-01-01
      • 2021-12-04
      • 2015-03-15
      • 2020-11-30
      • 1970-01-01
      相关资源
      最近更新 更多