由于通过API的纯密码登录,我们最近将我们的应用程序从http转换为https。
然而,由于这样做,我们在黑洞方面遇到了真正的问题。Cake似乎对我们控制器中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的POSTing返回以下消息:“该请求已被黑洞”
一旦我们可以让它工作(不会被黑洞),我们将对它进行调整,以便只有在validatePost = false的情况下才能执行某些操作。但是,现在我们只想让系统正常工作。
注意:对action的'GET‘请求工作正常(没有黑洞)。
我是不是遗漏了一些简单的配置,还是工作中有一些更深层次的问题?安全模块似乎缺乏文档,从我的谷歌搜索看,大多数人通过执行与我相同的步骤来避免黑洞。
发布于 2012-09-06 02:40:12
事实证明,以下内容在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;
}
}发布于 2012-09-05 14:39:58
请参阅下面的URL
CakePHP: Disable Security Component site wide
Disabling input elements in a CakePHP form that uses Security component and jQuery
http://life.mysiteonline.org/archives/175-Disable-the-Security-Component-in-CakePHP-only-for-Certain-Actions.html
http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html
http://api.cakephp.org/class/security-component
或尝试:-
即使你在你app_controller中禁用了它,你的个人控制器可能有安全enabled.As,我猜测这就是你想要的do.If,不要让我知道更多
function beforeFilter(){
parent::beforeFilter();
if(isset($this->Security) && $this->RequestHandler->isAjax() && $this->action = 'add'){
$this->Security->enabled = false;
}
}https://stackoverflow.com/questions/12275666
复制相似问题