主/从环境中的CSRF令牌

时间:2015-07-20 09:29:56

标签: spring-security csrf

我使用Spring Web服务实现了REST服务,在spring-security.xml中启用了CSRF安全性,如下所示

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/security
                           http://www.springframework.org/schema/security/spring-security-3.2.xsd
                           http://www.springframework.org/schema/beans
                           http://www.springframework.org/schema/beans/spring-beans-4.1.xsd">
    <security:http>
        <security:csrf/>
    </security:http>
</beans>

此应用程序部署在主/从设置中的两个tomcat 7.0服务器上,其中apache用作负载平衡器。

服务器拒绝了某些请求,抛出了CSRF令牌无效的安全异常。

我认为主服务器的具有有效CSRF令牌的请求正被重定向到从属服务器,反之亦然,这导致异常。您是否可以配置安全性,以便另一个服务器接受有效的令牌?

1 个答案:

答案 0 :(得分:0)

默认情况下,CSRF令牌存储在HttpSession中。

这意味着您需要复制HttpSession。一种简单的方法是使用Spring Session

您可以问自己的另一个问题是“您是否正在使用网络浏览器中的其他服务?”如果没有,那么您可以删除CSRF保护。