将CSRF过滤器与tomcat 6.0.32一起使用时出现403错误 [英] Getting 403 error when using CSRF filter with tomcat 6.0.32

查看:282
本文介绍了将CSRF过滤器与tomcat 6.0.32一起使用时出现403错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我在web.xml中的文件管理器配置

This is my filer config in web.xml

<filter>
    <filter-name>CSRFPreventionFilter</filter-name>
    <filter-class>org.apache.catalina.filters.CsrfPreventionFilter</filter-class>
    <init-param>
        <param-name>entryPoints</param-name>
        <param-value>/login<param-value>
    </init-param>
</filter>

<filter-mapping>
    <filter-name>CSRFPreventionFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>
<filter>

我错过了什么吗?在tomcat中启用csrf保护是否需要进行任何代码更改

Am I missing something? Are any code-changes necessary to enable csrf protection in tomcat

推荐答案

请注意, 403 CSRFPreventionFilter 响应(如果未提供随机数且过滤器需要一个随机数)。

Note that a 403 is the CSRFPreventionFilter response if a nonce is not provided and the filter expects one.

我不知道 CSRFPreventionFilter 的当前状态,但根据此线程,您需要分别指定每个 entryPoint 资源(没有通配符)-或使用过滤器应用于不包含 / login

I don't know the current state of CSRFPreventionFilter, but according to this thread you need to specify each entryPoint resource individually (no wildcards) - or have the filter apply to a path that does not include /login

因此:

<filter>
<filter-name>CSRFPreventionFilter</filter-name>
<filter-class>org.apache.catalina.filters.CsrfPreventionFilter</filter-class>
<init-param>
    <param-name>entryPoints</param-name>
    <param-value>/login/login.html,/login/image.png,/login/style.css</param-value>
</init-param>
</filter>

或:

<filter-mapping>
<filter-name>CSRFPreventionFilter</filter-name>
<url-pattern>/csrf/*</url-pattern>
</filter-mapping>

2012年12月更新:

Tomcat 7.0.32 修复了 CSRFPreventionFilter

Tomcat 7.0.32 fixes a security vulnerability in CSRFPreventionFilter

这篇关于将CSRF过滤器与tomcat 6.0.32一起使用时出现403错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆