CakePHP API黑洞-validatePost禁用不起作用


CakePHP API Blackhole - validatePost disable not working?

由于通过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会返回以下消息:"请求已被黑洞"

一旦我们能够使其工作(而不会被黑),我们将对其进行调整,以便在validatePost=false的情况下只执行某些操作。然而,目前我们只想让系统正常工作。

注意:对操作的"GET"请求可以正常工作(不会被拉黑)。

我是错过了一些简单的配置,还是工作中有一些更深层次的问题?安全模块在文档中似乎有点少,从我的谷歌搜索来看,大多数人都通过执行与我相同的步骤来避免黑洞。

发现以下内容在CakePHP 2.X:中没有影响

$this->Security->enabled=false;

要禁用组件,您需要遵循以下文档:http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html

我的问题与CSRF保护有关,我认为这在CakePHP2.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;
    }
}

请参阅以下URL

CakePHP:禁用安全组件站点范围的

禁用CakePHP表单中使用Security组件和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中禁用了它,您的单个控制器也可能启用了该安全性。正如我疯狂的猜测说这是你想做的。如果不让我知道更多关于

function beforeFilter(){
    parent::beforeFilter();
    if(isset($this->Security) && $this->RequestHandler->isAjax() && $this->action = 'add'){
        $this->Security->enabled = false;
    }
}