2012-10-03 29 views
0

我試圖使用安全組件來避免CSRF攻擊,並且如果我使用formHelper使用postLink創建票證,如下所示,它將失敗:在CakePHP 2.2中避免使用Form-> postLInk來實現CSRF

<?php echo $this->Form->postLink(__('Delete'), array('action' => 'delete', $user['User']['id']), array('class' => 'button mini'), __('Are you sure?', $user['User']['id'])); ?> 

我不知道這是可能的,或只是CakePHP的允許此功能使用create()和()結束表單助手的方法。

CakePHP documentation只說是強制使用formHelper,但它沒有指定更多。

+1

定義「失敗」。 – burzum

+0

好的,這可能是一個錯誤,因爲我不能再次重現它。抱歉。不管怎麼說,還是要謝謝你 :) – Alvaro

回答

2

當您啓用安全組件並且您對所有表單使用FormHelper方法時,您不必擔心這一點。你也不需要配置任何東西。它開箱即用。

對於CSRF您可以使用以下選項:

property SecurityComponent::$csrfCheck 
Whether to use CSRF protected forms. Set to false to disable CSRF protection on forms. 

property SecurityComponent::$csrfExpires 
The duration from when a CSRF token is created that it will expire on. Each form/page request will generate a new token that can only be submitted once unless it expires. Can be any value compatible with strtotime(). The default is +30 minutes. 

property SecurityComponent::$csrfUseOnce 
Controls whether or not CSRF tokens are use and burn. Set to false to not generate new tokens on each request. One token will be reused until it expires. This reduces the chances of users getting invalid requests because of token consumption. It has the side effect of making CSRF less secure, as tokens are reusable. 

如果你擁有了一切你應該看到CSRF形式的HTML標記。您可以設置任何您喜歡的其他選項,但它幾乎可以滿足您的需求。