CSRF令牌在负载均衡的symfony2应用程序中无效

chr*_*hey 7 mysql session load-balancing symfony

我继承了一个symfony2项目,它在实时环境中运行在2个以上的负载平衡服务器上.会话存储在应用程序使用的mysql数据库中.

我遇到的问题是,在有CSRF保护的表单上,有时令牌回来无效.我猜这是因为生成令牌的服务器并不总是获取表单POST的服务器,并且无法匹配正在发送的令牌.

我对symfony非常非常新,并尝试了一些不同的解决方案来使用Symfony框架中的session和SessionCsrfProvider生成令牌.

任何人都可以指出我正确的方向或有类似的问题吗?

Flo*_*ian 2

CsrfProviders 将通过连接密钥(来自parameters.ini)+意图(默认为null)+会话id来生成令牌。

By default, symfony is configured to use the SessionCsrfProvider, which uses the session storage id.

If you are using the PDOSessionStorage or NativeSessionStorage object, it will return the session_id().

It could mean your session_id() is not the same depending on what machine handles the request.

  • 似乎修复是两个服务器上的parameters.ini密钥不相同,即使我更正了这个问题,直到我清除了应用程序缓存并在两台服务器上重新启动了apache几次之后,它才生效。感谢你的帮助。 (3认同)