The request was rejected because the URL contained a potentially malicious String “%2e“
日志出現:
[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 框架中提供了一個 HttpFirewall,這是一個請求防火墻,它可以自動處理掉一些非法請求,請求地址格式中不能包含;、// 、 % .......等字符或編碼,必須是標準化 URL。
解決方法:
如果希望請求地址中可以出現 ; 或編碼后的字符 %3b 或者 %3B,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowSemicolon(true);return firewall; } // 設置完成上一步之后,再次訪問相同的接口錯誤是 404 需要再配置SpringMVC 使 ; 不要被自動移除 @Configuration public class WebMvcConfig extends WebMvcConfigurationSupport {@Overrideprotected void configurePathMatch(PathMatchConfigurer configurer) {UrlPathHelper urlPathHelper = new UrlPathHelper();urlPathHelper.setRemoveSemicolonContent(false);configurer.setUrlPathHelper(urlPathHelper);} }如果你希望請求地址中可以出現 // ,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowUrlEncodedDoubleSlash(true);return firewall; }如果希望請求地址中可以出現 %,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowUrlEncodedPercent(true);return firewall; }如果希望請求地址中出現 / 編碼后的字符 %2F 或者 %2f ,可以按照如下方式配置:
如果希望請求地址中出現 \ 編碼后的字符 %5C 或者 %5c ,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowBackSlash(true);firewall.setAllowUrlEncodedSlash(true);return firewall; }如果希望請求地址中出現 . 或編碼之后的字符 %2e、%2E,可以按照如下方式配置:
@Bean HttpFirewall httpFirewall() {StrictHttpFirewall firewall = new StrictHttpFirewall();firewall.setAllowUrlEncodedPeriod(true);return firewall; }總結:
雖然我們可以手動修改 Spring Security 中的這些限制,但是不建議大家做修改,每一條限制都有它的原由,每放開一個限制,就會帶來未知的安全風險。
總結
以上是生活随笔為你收集整理的The request was rejected because the URL contained a potentially malicious String “%2e“的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: C语言循环计算输出圆周长
- 下一篇: 使用selenium爬取智联招聘