防止自定义 AJAX 表单提交中的 CSRF
我问这个问题关于使用 Drupal 7 的 Forms API 的原因,而不是自己处理表单提交请求并最终调用像 node_save()
或comment_save()
。虽然使用 Forms API 的原因有很多种,但只提出了一个可能的安全漏洞:如果不使用 Drupal 7 的 Forms API,我就会错过它使用的 CSRF 预防技术。据我所知,这基本上涉及使用令牌来验证请求。
我的问题有两个:
- 是否可以在我编写的脚本中利用 Drupal 的 CSRF 预防令牌方法来处理 Ajax 请求,从而完全消除我因不使用 Forms API 而承担的额外风险?如果是这样,怎么办?
- 除了使用令牌之外,Forms API 是否还采用了我也应该实现的技术?
请注意,我不希望这个问题成为我是否应该使用 Forms API 的讨论。
I asked this question about reasons to use Drupal 7's Forms API as opposed to just processing form submission requests myself and eventually calling a function like node_save()
or comment_save()
. while a variety of reasons were given for using the Forms API, only one possible security vulnerability was raised: by not using Drupal 7's Forms API, I'd be missing out on the CSRF prevention techniques it uses. From what I've read, this basically involves the use of a token for validating requests.
My question is twofold:
- Is it possible to leverage Drupal's token method of CSRF prevention in the script I write to process the Ajax request, thereby entirely eliminating the added risk I'm assuming by not using the Forms API? If so, how?
- Does the Forms API employ techniques beyond the use of tokens that I should also implement?
Please note that I do not want this question to become a discussion of whether I should use the Forms API or not.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
令牌由 drupal_get_token() 生成,并且使用 drupal_valid_token()。
The token is generated by drupal_get_token() and validated using drupal_valid_token().