这是我在 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 保护
最佳答案
请注意,403 是 CSRFPreventionFilter如果未提供随机数且过滤器需要一个随机数,则响应。
我不知道 CSRFPreventionFilter 的当前状态,但根据 this thread您需要单独指定每个 entryPoint 资源(无通配符) - 或者将过滤器应用于不包含 /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
中的安全漏洞关于security - 在 tomcat 6.0.32 中使用 CSRF 过滤器时出现 403 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13151768/