2013-08-23 55 views
0

我認爲用了jQuery POST數據發送到我的控制器,但它的失敗,我得到以下錯誤,當安全問題工作是通過一起去除該控制器中的安全性。發送POST請求王氏CakePHP的

這裏的控制器有問題的前過濾器

public function beforeFilter() { 
    parent::beforeFilter(); 
    $this->Auth->allow('help','submit_bank_info'); 
    $this->Auth->authorize = 'Controller'; 
} 

如果看到這個蛋糕上的文檔

When using the Security Component you must use the FormHelper to create your forms. In addition, you must not override any of the fields’ 「name」 attributes. The Security Component looks for certain indicators that are created and managed by the FormHelper (especially those created in create() and end()). Dynamically altering the fields that are submitted in a POST request (e.g. disabling, deleting or creating new fields via JavaScript) is likely to trigger a black-holing of the request. See the $validatePost or $disabledFields configuration parameters.

我使用的版本2.3.8。有什麼方法可以禁用該操作,以便我可以爲其他操作保留安全組件?

+0

確實/設置/幫助或確實/幫助工作? – Adder

+0

是的,但那些不是基於javascript/jquery的表單。他們是用表單助手構建的。出於幾個原因,我不得不使用javascript/jquery作爲「submit_bank_info」。我正在使用平衡付款卡處理。 – user1406951

回答

1

嘗試停止jQuery併發布表單並使用firebug跟蹤CakePHP使用表單發送的隱藏數據,因爲它們的文檔發送隱藏數據以防止CSRF攻擊。

The csrfExpires property can be any value that is compatible with strtotime(). By default the FormHelper will add a data[_Token][key] containing the CSRF token to every form when the component is enabled.

嘗試捕獲隱藏字段並將其與您的jquery請求一起發送。

UPDATE

也可以嘗試使用CakePHP它會產生數據,以產生形式爲[_Token] [字段]和數據[_Token] [解鎖]隱藏字段與它們的鍵:

<?php 
    echo $this->Form->create('formA',array('id'=>'formA')); 
    echo $this->Form->input('inputA'); 
    echo $this->Form->submit(); 
    echo $this->Form->end(); 
?> 

這將產生

<input type="hidden" name="_method" value="POST"/> 
    <input type="hidden" name="data[_Token][key]" value="randomValue"/> 
    <input type="hidden" name="data[_Token][fields]" value="randomValue"/> 
    <input type="hidden" name="data[_Token][unlocked]" value=""/> 

在烏爾JQuery的AJAX請求serialize()形式併發送。