CakePHP 表单篡改
CakePHP form tampering
我在 CakePHP 2 中创建的表单有问题。
表单提交工作正常,但后来我更改了它,现在我也提交了一些其他内容。我还这样做了,以便用户可以选择他要提交的"Services"个数。
现在只有当有 exactley 1 时才会提交表单 "Service"。
我认为问题在于 "form-tampering" 保护。
由于我希望用户 "tamper" 使用表单,我该如何禁用此保护?
我的 beforeFilter 看起来像这样:
parent::beforeFilter();
$this->Auth->allow('register_new');
// Security component
if (isset($this->Security) &&
$this->RequestHandler->isAjax() &&
($this->action == 'statistics'))
{
// $this->Security->validatePost = false;
$this->Security->csrfCheck = false;
}
if (isset($this->Security) &&
$this->RequestHandler->isAjax() &&
($this->action == 'markPaid'))
{
$this->Security->validatePost = false;
$this->Security->csrfCheck = false;
}
有问题的 'action'(未获得任何数据的那个)是 "register_new"。
代码
$this->Auth->allow('register_new');
使 register_new
无需身份验证即可访问,但不会禁用表单篡改保护。
if($this->request->params['action'] == 'register_new')
{
$this->Security->validatePost = false;
}
或者,您也可以仅使用
禁用某些字段的 POST 验证
$this->Security->unlockedFields = array('field_1', ...);
具有保持对其他验证的优势。
我在 CakePHP 2 中创建的表单有问题。
表单提交工作正常,但后来我更改了它,现在我也提交了一些其他内容。我还这样做了,以便用户可以选择他要提交的"Services"个数。
现在只有当有 exactley 1 时才会提交表单 "Service"。 我认为问题在于 "form-tampering" 保护。 由于我希望用户 "tamper" 使用表单,我该如何禁用此保护?
我的 beforeFilter 看起来像这样:
parent::beforeFilter();
$this->Auth->allow('register_new');
// Security component
if (isset($this->Security) &&
$this->RequestHandler->isAjax() &&
($this->action == 'statistics'))
{
// $this->Security->validatePost = false;
$this->Security->csrfCheck = false;
}
if (isset($this->Security) &&
$this->RequestHandler->isAjax() &&
($this->action == 'markPaid'))
{
$this->Security->validatePost = false;
$this->Security->csrfCheck = false;
}
有问题的 'action'(未获得任何数据的那个)是 "register_new"。
代码
$this->Auth->allow('register_new');
使 register_new
无需身份验证即可访问,但不会禁用表单篡改保护。
if($this->request->params['action'] == 'register_new')
{
$this->Security->validatePost = false;
}
或者,您也可以仅使用
禁用某些字段的 POST 验证$this->Security->unlockedFields = array('field_1', ...);
具有保持对其他验证的优势。