- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
不确定这是否是 Spring 5.0.3 的一个错误,或者是一个新功能来解决我的问题。
升级后,我收到此错误。有趣的是,这个错误仅出现在我的本地计算机上。使用 HTTPS 协议(protocol)的测试环境中的相同代码运行良好。
继续...
我收到此错误的原因是因为我用于加载结果 JSP 页面的 URL 是 /location/thisPage.jsp
。评估代码 request.getRequestURI()
给出结果 /WEB-INF/somelocation//location/thisPage.jsp
。如果我将 JSP 页面的 URL 固定到此 location/thisPage.jsp
,则一切正常。
所以我的问题是,我是否应该从代码中的 JSP
路径中删除 /
,因为这是 future 所需要的。或者 Spring 引入了一个错误,因为我的机器和测试环境之间的唯一区别是协议(protocol) HTTP 与 HTTPS。
org.springframework.security.web.firewall.RequestRejectedException: The request was rejected because the URL was not normalized.
at org.springframework.security.web.firewall.StrictHttpFirewall.getFirewalledRequest(StrictHttpFirewall.java:123)
at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:194)
at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:186)
at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:357)
at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:270)
最佳答案
Spring Security Documentation在请求中提到了阻止//的原因。
For example, it could contain path-traversal sequences (like /../) or multiple forward slashes (//) which could also cause pattern-matches to fail. Some containers normalize these out before performing the servlet mapping, but others don’t. To protect against issues like these, FilterChainProxy uses an HttpFirewall strategy to check and wrap the request. Un-normalized requests are automatically rejected by default, and path parameters and duplicate slashes are removed for matching purposes.
所以有两种可能的解决方案 -
第 1 步创建允许 URL 中包含斜线的自定义防火墙。
@Bean
public HttpFirewall allowUrlEncodedSlashHttpFirewall() {
StrictHttpFirewall firewall = new StrictHttpFirewall();
firewall.setAllowUrlEncodedSlash(true);
return firewall;
}
第2步然后在websecurity中配置这个bean
@Override
public void configure(WebSecurity web) throws Exception {
//@formatter:off
super.configure(web);
web.httpFirewall(allowUrlEncodedSlashHttpFirewall());
....
}
第2步是可选步骤,Spring Boot只需要声明一个HttpFirewall
类型的bean,它就会在过滤器链中自动配置它。
Spring Security 5.4 更新
在 Spring security 5.4 及更高版本 (Spring Boot >= 2.4.0) 中,我们可以通过创建以下 bean 来消除太多提示请求被拒绝的日志。
import org.springframework.security.web.firewall.RequestRejectedHandler;
import org.springframework.security.web.firewall.HttpStatusRequestRejectedHandler;
@Bean
RequestRejectedHandler requestRejectedHandler() {
return new HttpStatusRequestRejectedHandler();
}
关于spring-mvc - Spring 5.0.3 RequestRejectedException : The request was rejected because the URL was not normalized,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48453980/
我在我的 Tomcat 日志中看到 大量 RequestRejectedException 条目(示例粘贴在下面)。在几个月前的次要版本升级(Spring Security 4.2.4,IIRC)之后
当我发布 Spring Boot 应用程序的登录凭据时,出现以下异常。 org.springframework.security.web.firewall.RequestRejectedExcepti
不确定这是否是 Spring 5.0.3 的一个错误,或者是一个新功能来解决我的问题。 升级后,我收到此错误。有趣的是,这个错误仅出现在我的本地计算机上。使用 HTTPS 协议(protocol)的测
我是一名优秀的程序员,十分优秀!