REST/stateless: CSRF 攻击和记住登录用户

REST/stateless: CSRF attacks and remembering logged in user

我正在使用 Spring-MVC 和 AngularJS 创建我的网络应用程序,但我想这个问题可以适用于任何技术,因为它更像是一个概念性问题而不是特定技术问题。

我正在努力了解有关 CSRF 攻击以及在我的 Web 应用程序上对用户进行身份验证的一些事情。因此,我有以下问题:

Have the clients generate and send the same unique secret value in both a Cookie and a custom HTTP header. Considering a website is only allowed to read/write a Cookie for its own domain, only the real site can send the same value in both headers. Using this approach all your server has to do is check if both values are equal, on a stateless per request basis!

现在,我不明白生成这些秘密值的目的是什么。我的意思是,拥有这两个秘密值并在服务器上比较它们的目的是什么?攻击者不能只在假 cookie 和 http header 中放入 2 个相同的值并仍然提交表单吗?

Now, I don't understand what the purpose is of generating these secret values. I mean, what is the purpose of having these 2 secret values and compare them on the server? Can't an attacker just put 2 identical values inside a fake cookie and http header and still submits the form?

你是对的,攻击者可以添加 HTTP header,但他只能为自己的域(来源)设置 cookie。浏览器不会将 cookie 发送到另一个域:

Considering a website is only allowed to read/write a Cookie for its own domain, only the real site can send the same value in both headers.

服务器将仅接收来自攻击者的 HTTP 请求 header,而不是 cookie。