【问题标题】:How to implement CSRF Protection in Zend Framework 3?如何在 Zend Framework 3 中实现 CSRF 保护?
【发布时间】:2017-11-22 20:04:05
【问题描述】:

我需要在 Zend Framework 3 中实现针对 CSRF 攻击的保护。我阅读了该文档,但无法弄清楚它是针对 ZF3 描述的哪些部分,我只能为 ZF2 获取它。请帮忙。

【问题讨论】:

    标签: zend-framework3


    【解决方案1】:

    在表单中添加CSRF,类似于添加任何FORM ELEMENTCSRF 是隐藏输入。

    <?php
    
    namespace YOUR_MODULE\Form;
    
    
    use Zend\Form\Form;
    use Zend\Form\Element;
    
    class AnimationCategoryForm extends Form
    {
        public function __construct($name = null, array $options = [])
        {
            parent::__construct($name, $options);
        }
    
        public function init()
        {
    
            $this->add([
                'type' => Element\Csrf::class,
                'name' => 'csrf',
                'options' => [
                'csrf_options' => [
                   'timeout' => 600,
                ],
            ],
         ]);
    
            $this->add([
                'type' => Element\Submit::class,
                'name' => 'submit',
                'attributes' => [
                    'value' => 'Submit',
                ],
            ]);
        }
    }
    

    以上是表单示例。您还应该在视图文件中显示它。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-09-23
      • 1970-01-01
      • 1970-01-01
      • 2022-06-18
      • 2023-03-31
      • 1970-01-01
      • 2019-12-31
      • 2016-07-04
      相关资源
      最近更新 更多