预防CSRF? [英] Preventing CSRF?
问题描述
我已经在这里看到了一些问题(stackoverflow)和 这是 帖子,但我仍然有一些疑问...
-
使用隐藏值
- 隐藏值可以很容易地复制并像真实值一样发送,难以猜测(例如md5)将无济于事。 (对吗?)
-
在到达表单时设置cookie并将cookie值作为隐藏值发送。
p> - 您可以轻松地更改cookie值或使用相同的真实隐藏值发送与真实的cookie完全相同的自定义cookie。 (对吗?)
-
使用超时,POST值不能太晚。
- 因此,如果您操作缓慢,则尝试使用隐藏值设置所有内容时都会失败。如果速度很快,它会起作用。 (对吗?)
我想保护CSRF ...但是我该怎么做?
我发现防止CSRF问题的最简单方法是:
-
在服务器端,分配一个使用随机(不可使用的)令牌向客户端发送的HttpOnly cookie
-
在具有该cookie值的表单上放置一个隐藏字段
-
提交表单后,请确保隐藏字段值等于cookie值(在服务器端)
I already seen some question from here (stackoverflow) and THIS post, but I still have some questions...
Using hidden value in the post form and check it when post reach the server.
- The hidden value can easy be copied and send exactly like the real one, "hard to guess" (like md5) will not help. (right?)
Setting a cookie when you reach the form and send the cookie value as a hidden value.
- You can easily change a cookie value or send a custom cookie exactly like the real one using the same real hidden value. (right?)
Using 'timeout', the POST values cannot reach too late.
- So, if you're slow you will fail when you try to set everything up with the hidden value. If you're fast it gonna work. (right?)
I want to be protected about CSRF...but how exactly I do it?
The easiest way I found to prevent CSRF issues is:
On the server side, assign an HttpOnly cookie to the client with a random (unguessable) token
Place a hidden field on the form with that cookie value
Upon form submit, ensure the hidden field value equals the cookie value (on the server side of things)
这篇关于预防CSRF?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!