UrttEncodedSlash被HttpFirewall阻止(Grails 3.3.0.RC1; Spring-security-core 3.2.0.M1)

时间:2017-07-06 06:50:52

标签: grails spring-security grails3

我在日志中发现了这个错误:

org.springframework.security.web.firewall.RequestRejectedException: The requestURI cannot contain encoded slash. Got /;lm=1488887514;m=js;asset=delayedElements%2Fsnippet;tf;ucm=353df4434086482d9d1d7b89758e156e/
        at org.springframework.security.web.firewall.DefaultHttpFirewall.getFirewalledRequest(DefaultHttpFirewall.java:56)
        at org.springframework.security.web.FilterChainProxy.doFilterInternal(FilterChainProxy.java:193)
        at org.springframework.security.web.FilterChainProxy.doFilter(FilterChainProxy.java:177)
        at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:239)
        at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at org.grails.web.servlet.mvc.GrailsWebRequestFilter.doFilterInternal(GrailsWebRequestFilter.java:77)
        at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:107)
...

我发现这个解决方案可能适用于Spring Boot。 Spring security DefaultHttpFirewall - The requestURI cannot contain encoded slash

我可以,以及如何在Grails中应用它? 非常感谢提前!

编辑1:

这是我实施Sudhir建议的方式:

我在这里创建了新类:

Here I created the new class:

这是实现的样子:

package fnx.security;

import org.springframework.security.web.firewall.DefaultHttpFirewall;

public class CustomHttpFirewall extends DefaultHttpFirewall {
    CustomHttpFirewall() {
        boolean allowUrlEncodedSlash = true;
    }
}

这就是它包含在application.yml中的方式:

 grails:
     plugin:
        springsecurity:
            httpFirewallBeanClass: 'fnx.security.CustomHttpFirewall'

有什么遗漏或错误吗?

1 个答案:

答案 0 :(得分:3)

默认情况下,spring security core plugin使用DefaultHttpFirewall您可以通过扩展DefaultHttpFirewall创建子类,并将属性allowUrlEncodedSlash设置为true。

 CustomHttpFirewall extends DefaultHttpFirewall {
   CustomHttpFirewall() {
     allowUrlEncodedSlash = true
   }
}

然后配置spring security以使用您的自定义防火墙类,如下所示。

grails.plugin.springsecurity.httpFirewallBeanClass = "full name of your class"

注意测试,但这应该有效。