为了保护表单,我什么时候发行令牌?
因此,我有一个表单,为了使其更安全并可能有助于防止 CSRF 攻击,我想在隐藏字段中添加一个随机令牌值,该值也存储在服务器端的会话数据中。
我什么时候应该发行新的代币?履行?每页加载哪里有什么表格?每个会话?一旦成功提交表单,我就可以使其无效,但我想知道何时生成表单。
我问,如果我按表单或按页面发布它,如果用户打开一个单独的窗口但提交第一个表单(具有现在被覆盖的值),我是否不会冒重复令牌值覆盖现有(有效)令牌的风险?
So, I have a form, to make it a little more secure and potentially help prevent CSRF attacks I want to add a random token value in a hidden field that value is also stored server side in my session data.
When should I issue a new token? Per form? Per page load where there is any form? Per session? I can render it invalid as soon as a form is successfully submitted but I'm wondering when to generate one.
I ask as if I issue it per form or per page do I not risk the chance of a duplicate token value overwriting the existing (valid) token if a user opens a separate window but submitting the first form (with the now overwritten value)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
防止并发问题的最简单方法是每次登录仅生成一次。攻击者“猜测”您的 CSRF 的机会与窃取您的 PHPSESSID 的机会大致相同(或更低)。您还可以在用户的访问级别更改时重新生成它,例如在更改密码或其他内容之后。
如果您想真正彻底,您可以生成并存储一组令牌,每个令牌对应网站上的每个表单。但如果他们能够窃取 CSRF 令牌,那么他们可能只是窃取了会话 ID 并造成了一些真正的损害。
The simplest way to prevent concurrency issues is to generate it only once per login. The chance of an attacker "guessing" your CSRF is about the same chance (or lower) as them stealing your PHPSESSID. You could also regenerate it whenever the user's access level changes, such as after they change their password or something.
If you want to be really thorough, you can generate and store an array of tokens, one for each form on the website. But if they can steal a CSRF token, they might as well have just stolen a session ID and done some real damage.
那么你需要一种技术来检查
重复提交的表单(当用户
刷新页面或点击返回
按钮)。
多页,然后只有最后一页
形式将起作用。
每个会话生成的令牌,以及
当提交令牌时,它应该是
已删除。我读到这种方法可能是
如果您的音量很大,请注意
交通网站。
我不确定您之前是否读过这篇文章,但我认为这是有关 CSRF 安全性的重要资源:
http://shiflett.org/articles/cross-site-request-forgeries
then you need a technique to check
duplicate submitted forms (when user
refreshes a page or click back
button).
multiple pages then only the last
form will work.
generated tokens per session, and
when a token is submitted it should be
removed. I read that this approach might be a
concern if you have high volume
traffic website.
I am not sure if you read this article before, but I think it is great resource about CSRF security:
http://shiflett.org/articles/cross-site-request-forgeries