由于通过API进行普通密码登录,我们最近将应用程序从http转移到了https。
然而,由于这样做,我们与Blackholes有真正的问题。尽管
,但是我们的控制器中的API函数似乎是黑洞的任何'POST'$this->Security->validatePost = false;
在AppController.php中设置
我们正在使用CakePHP版本2.1.3
代码示例如下:
AppController.php:
function beforeFilter()
{
$this->Security->validatePost = false;
$this->Security->requireSecure();
}
SaleOrderController.php:
function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow('addApi'); // Allow access to the API without logging in.
}
发布到此URL会返回以下消息: “请求已经黑了”
一旦我们能够正常工作(没有被黑洞),我们将调整它,以便只使用validatePost = false执行某些操作。但是,现在我们只想让系统正常工作。
注意:'GET'对行动的请求工作正常(不会被黑洞)。
我在这里错过了一些简单的配置,还是在工作中有一些更深层次的问题?安全模块似乎在文档上有点不足,而且从我的谷歌搜索看起来大多数人都通过执行相同的步骤避免了黑名单。
答案 0 :(得分:8)
原来,以下内容对CakePHP 2.X无效:
$ this-> Security-> enabled = false;
要停用您需要遵循此文档的组件: http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html
我的问题与CSRF保护有关,我认为它可能是CakePHP 2.X中的新功能? 无论如何,我需要做的就是在我的SaleOrderController beforeFilter函数中添加以下行:
$ this-> Security-> csrfCheck = false;
我的整个BeforeFilter功能现在是:
function beforeFilter()
{
parent::beforeFilter();
$this->Auth->allow('addApi'); // Allow access to the API without logging in.
if (isset($this->Security) && $this->action == 'addApi') {
$this->Security->csrfCheck = false;
$this->Security->validatePost = false;
}
}
答案 1 :(得分:1)
见以下网址
CakePHP: Disable Security Component site wide
Disabling input elements in a CakePHP form that uses Security component and jQuery
http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html
http://api.cakephp.org/class/security-component
或尝试一下: -
即使您在app_controller中禁用它,您的个人控制器也可能启用了该安全性。正如我猜测的那样,这就是您想要做的事情。如果没有让我了解更多信息
function beforeFilter(){
parent::beforeFilter();
if(isset($this->Security) && $this->RequestHandler->isAjax() && $this->action = 'add'){
$this->Security->enabled = false;
}
}