我正在 Magento 中查看自定义表单。我看到了这些教程
http://fastdivision.com/2012/03/29/diy-magento-create-ajax-login-registration-forms-for-your-magento-theme/ http://fastdivision.com/2012/03/29/diy-magento-create-ajax-login-registration-forms-for-your-magento-theme/
http://inchoo.net/ecommerce/magento/magento-email/magento-custom-email-contact-form-with-notification-system/ http://inchoo.net/ecommerce/magento/magento-email/magento-custom-email-contact-form-with-notification-system/
我没有看到任何提及 CSRF 预防的内容,例如使用存储在用户会话中的令牌检查客户端令牌。我还查看了 Magento 联系我们表单,并看到了此内容,但我认为它与 CSRF 无关:
<input type="text" name="hideit" id="hideit" value="" style="display:none !important;">
Magento 有任何默认代码来防止 CSRF 吗? Mage_Core_Controller_Front_Action 的 $this->getRequest()->getParams() 方法是否会自动执行任何操作来防止我可能丢失的 CSRF?
其实有一个前端CSRF 令牌验证 https://www.owasp.org/index.php/Cross-Site_Request_Forgery_%28CSRF%29_Prevention_Cheat_Sheet#General_Recommendation:_Synchronizer_Token_PatternMagento 中的方法,您可以使用将唯一的基于会话的表单密钥添加到自定义表单中,并在控制器的操作中验证它。
要在提交表单时随请求发送 CSRF 表单密钥,请插入<?php echo $this->getBlockHtml('formkey') ?>
代码到表单的主体中。
这将生成如下输入:<input type="hidden" value="unique16codehere" name="form_key">
。
要验证密钥,请使用_validateFormKey()
相应控制器操作中的方法。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)