防止自定义 AJAX 表单提交中的 CSRF

发布于 2025-01-05 10:17:49 字数 576 浏览 4 评论 0原文

我问这个问题关于使用 Drupal 7 的 Forms API 的原因,而不是自己处理表单提交请求并最终调用像 node_save()comment_save()。虽然使用 Forms API 的原因有很多种,但只提出了一个可能的安全漏洞:如果不使用 Drupal 7 的 Forms API,我就会错过它使用的 CSRF 预防技术。据我所知,这基本上涉及使用令牌来验证请求。

我的问题有两个:

  1. 是否可以在我编写的脚本中利用 Drupal 的 CSRF 预防令牌方法来处理 Ajax 请求,从而完全消除我因不使用 Forms API 而承担的额外风险?如果是这样,怎么办?
  2. 除了使用令牌之外,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:

  1. 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?
  2. 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

慢慢从新开始 2025-01-12 10:17:49

令牌由 drupal_get_token() 生成,并且使用 drupal_valid_token()

The token is generated by drupal_get_token() and validated using drupal_valid_token().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文