ajax 请求的安全令牌问题
在构建应用程序时,我使用令牌来防止
每次呈现表单时对表单的攻击,它都会获得一个新的一次性安全令牌,我将其作为隐藏字段包含在表单中。该令牌也存储在会话中。
发送表单时,将根据会话中的令牌验证令牌,以确保表单合法。这对于标准页面非常有用。
问题 当使用Ajax发送表单时,一个页面上可能有多个表单,一旦您发送其中一个表单,该令牌对于其他表单来说就无效了,因为它是一次性令牌。
有人对此有建议吗?或者是否足够安全,可以为每个会话生成一个令牌并仅使用它,而不是在每次发送表单时使令牌失效?
when building apps I use a token to prevent attacks on the forms
each time a form is rendered it gets a new ONE TIME security token that i include in the form as a hidden field. this token is also stored in the session.
when the form is sent, the token is verified against the token in the session to make sure the form is legit. This works great for standard pages.
PROBLEM
when using Ajax to send forms, there may be multiple on a page, once you send one of these forms, the token is then invalid for the others as its a one time token.
does anyone have advise for this? or is it secure enough to generate one token per session and just use that instead of invalidating the token each time a form is sent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想遵循当前的方法,您可以在每次执行 AJAX 请求时生成一个安全令牌,在 AJAX 响应中返回它,并在获取它时将其注入到隐藏中。
但是,我会重新考虑您当前的安全令牌方法。 此处在 OSWAP wiki 中提供了一些相关提示。
If you want to follow your current approach, you can generate a security token each time you do a an AJAX request, return it in the AJAX response, and inject it into the hidden when you get it.
However, I'd go rethinking your current approach for security tokens. Here you have some tips about that in the OSWAP wiki.