2015-08-22 154 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; 
    } 
}