The request was rejected because the URL contained a potentially malicious String “%2e“
日志出現(xiàn):
[http-nio-80-exec-3] ERROR o.a.c.c.C.[.[localhost].[/].[dispatcherServlet] - Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception
org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL contained a potentially malicious String "%2e"
原因:
在我使用的 Spring Security 框架中提供了一個(gè) HttpFirewall,這是一個(gè)請(qǐng)求防火墻,它可以自動(dòng)處理掉一些非法請(qǐng)求,請(qǐng)求地址格式中不能包含;、// 、 % .......等字符或編碼,必須是標(biāo)準(zhǔn)化 URL。
解決方法:
如果希望請(qǐng)求地址中可以出現(xiàn) ; 或編碼后的字符 %3b 或者 %3B,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowSemicolon(true);return firewall; } // 設(shè)置完成上一步之后,再次訪問(wèn)相同的接口錯(cuò)誤是 404 需要再配置SpringMVC 使 ; 不要被自動(dòng)移除 @Configuration public class WebMvcConfig extends WebMvcConfigurationSupport {@Overrideprotected void configurePathMatch(PathMatchConfigurer configurer) {UrlPathHelper urlPathHelper = new UrlPathHelper();urlPathHelper.setRemoveSemicolonContent(false);configurer.setUrlPathHelper(urlPathHelper);} }如果你希望請(qǐng)求地址中可以出現(xiàn) // ,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowUrlEncodedDoubleSlash(true);return firewall; }如果希望請(qǐng)求地址中可以出現(xiàn) %,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowUrlEncodedPercent(true);return firewall; }如果希望請(qǐng)求地址中出現(xiàn) / 編碼后的字符 %2F 或者 %2f ,可以按照如下方式配置:
如果希望請(qǐng)求地址中出現(xiàn) \ 編碼后的字符 %5C 或者 %5c ,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowBackSlash(true);firewall.setAllowUrlEncodedSlash(true);return firewall; }如果希望請(qǐng)求地址中出現(xiàn) . 或編碼之后的字符 %2e、%2E,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowUrlEncodedPeriod(true);return firewall; }總結(jié):
雖然我們可以手動(dòng)修改 Spring Security 中的這些限制,但是不建議大家做修改,每一條限制都有它的原由,每放開一個(gè)限制,就會(huì)帶來(lái)未知的安全風(fēng)險(xiǎn)。
總結(jié)
以上是生活随笔為你收集整理的The request was rejected because the URL contained a potentially malicious String “%2e“的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: C语言循环计算输出圆周长
- 下一篇: 使用selenium爬取智联招聘