gpt4 book ai didi

spring-mvc - Spring Security 4.2中的StrictHttpFirewall与Spring MVC @MatrixVariable

转载 作者:行者123 更新时间:2023-12-03 14:14:54 26 4
gpt4 key购买 nike

升级到Spring Security 4.2.4之后,我发现StrictHttpFirewall现在是默认设置。
不幸的是,由于“;”,它不能与Spring MVC @MatrixVariable一起很好地使用。不再被允许。
如何解决?

例:

@GetMapping(path = "/{param}")
public void example(@PathVariable String param,
@MatrixVariable Map<String, String> matrix) {
//...
}


可以这样称呼:

mockMvc.perform(get("/someparam;key=value"))


并且将填充矩阵图。
现在,Spring Security阻止了它。

org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL contained a potentially malicious String ";"

at org.springframework.security.web.firewall.StrictHttpFirewall.rejectedBlacklistedUrls(StrictHttpFirewall.java:140)


我可以使用允许分号的自定义HttpFirewall。
有没有一种方法可以使用@MatrixVariable而不使用禁止的字符?

顺便说一句:javadoc是不正确的 https://docs.spring.io/autorepo/docs/spring-security/4.2.x/apidocs/index.html?org/springframework/security/web/firewall/StrictHttpFirewall.html


以来:

5.0.1


我想它被反向移植了吗?

最佳答案

您可以使用自定义定义的StrictHttpFirewall实例来稀释默认的spring安全防火墙(后果自负)

@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
StrictHttpFirewall firewall = new StrictHttpFirewall();
firewall.setAllowUrlEncodedSlash(true);
firewall.setAllowSemicolon(true);
return firewall;
}


然后在WebSecurity中使用此自定义防火墙bean(Spring启动不需要此更改)

@Override
public void configure(WebSecurity web) throws Exception {
super.configure(web);
// @formatter:off
web.httpFirewall(allowUrlEncodedSlashHttpFirewall());
...
}


可以在Spring Security 4.2.4+上使用,但是当然会带来一些风险!

关于spring-mvc - Spring Security 4.2中的StrictHttpFirewall与Spring MVC @MatrixVariable,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48580584/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com