2015-08-22 128 views
0

我试图让CSRF安全CakePHP的2.0如何蛋糕2.0

我已经包含在我的控制器的安全组件启用安全(CSRF)独自一人。

public $components = array('Security'); 

我想启用此组件只有一个功能,说功能测试。

其他功能必须是自由的安全

我试图做类似

$this->Security->requireSecure('test'); 

我提供像这样因为我想单独启用测试功能的安全性。

在cakephp3.0中,我找到了一个启用CSRF的选项。但我需要的CakePHP 2.0

等待了反馈解决方案,我不需要任何其他证券validatePost,requirePost,requireDelete等。

。提前致谢。

回答

1

默认情况下,应在每个动作/表单中启用CSRF,并禁用所需的任何操作,而不是后退。

public $components = array('Security'); 

private $disabledCSRFForActions = array("test"); 

public function beforeFilter() { 
    parent::beforeFilter(); 

    if (isset($this->Security) && in_array($this->action, $disabledCSRFForActions) { 
      $this->Security->validatePost = false; 
      $this->Security->enabled = false; 
      $this->Security->csrfCheck = false; 
    } 
}