2013-08-23 46 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()形式并发送。