【问题标题】:CakePHP form tamperingCakePHP 表单篡改
【发布时间】:2015-06-12 11:40:00
【问题描述】:

我在 CakePHP 2 中制作的表单有问题。

表单提交工作正常,但后来我更改了它,现在我也提交了一些其他内容。我也这样做了,以便用户可以选择他要提交的“服务”的数量。

现在表单仅在存在exactley 1“服务”时提交。 我认为问题在于“表单篡改”保护。 由于我希望用户“篡改”表单,我该如何禁用此保护?

我的 beforeFilter 看起来像这样:

parent::beforeFilter();

    $this->Auth->allow('register_new');

    // Security component
    if (isset($this->Security) &&
        $this->RequestHandler->isAjax() &&
        ($this->action == 'statistics'))
    {
        // $this->Security->validatePost = false;
        $this->Security->csrfCheck = false;
    }

    if (isset($this->Security) &&
        $this->RequestHandler->isAjax() &&
        ($this->action == 'markPaid'))
    {
        $this->Security->validatePost = false;
        $this->Security->csrfCheck = false;
    }

有问题的“操作”(没有获取任何数据的操作)是“register_new”。

【问题讨论】:

    标签: forms cakephp cakephp-2.0


    【解决方案1】:

    代码

    $this->Auth->allow('register_new');
    

    使register_new 无需身份验证即可访问,但不会禁用表单篡改保护。

    if($this->request->params['action'] == 'register_new')
    {
        $this->Security->validatePost = false;
    }
    

    或者,您也可以仅使用

    禁用某些字段的 POST 验证
    $this->Security->unlockedFields = array('field_1', ...);
    

    具有保持其他验证的优势。

    http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#form-tampering-prevention

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-06-13
      • 2019-01-06
      • 2017-03-15
      • 2013-11-12
      • 1970-01-01
      • 2015-01-28
      相关资源
      最近更新 更多