【问题标题】:Disable Security in function禁用安全功能
【发布时间】:2014-03-21 16:07:51
【问题描述】:

我在 POST 中得到一张图片,我的想法是禁用此功能内的安全性。

有可能吗?有什么想法吗?

public function admin_addImage($id = null){
    $this->Hotel->id = $id;
    if (!$this->Hotel->exists())
        throw new NotFoundException(__('Invalid Hotel'));
    $image = $_FILES['uploadImage'];
    ClassRegistry::init('HotelImage')->create();
    if ($image['name']) {
        $imageName = md5(Security::generateAuthKey());
        $result = $this->uploadFiles('files/hotels/images', array($image), $imageName, null, 'I',array('width' => 300, 'height' => 300));
        if (!empty($result['errors'][0])) {
            $this->Session->setError(__('Invalid file format'));
            $this->redirect($this->referer());
            }
        if($result['urls'][0]){
            ClassRegistry::init('HotelImage')->save(array('hotel_id'=>$id));
            ClassRegistry::init('HotelImage')->saveField('image', md5($imageName).'.'.basicsLix::getExtension($image['name']));
        }
    } 
$this->redirect($this->referer());
}

解决方案:

if(isset($this->Security) && $this->RequestHandler->isPost() && $this->action == 'admin_addImage'){
            $this->Security->validatePost = false;
            $this->Security->enabled = false;
            $this->Security->csrfCheck = false;
    }

【问题讨论】:

  • 禁用什么安全性?
  • 这个安全性:public $components = array('Security','Acl', 'RequestHandler')
  • 你为什么需要/想要完全禁用它?
  • 因为使用 POST 方法给我发送错误“黑洞”,反正我已经解决了,把代码留在这里。

标签: security cakephp


【解决方案1】:

这在书中有具体回答:

http://book.cakephp.org/2.0/en/core-libraries/components/security-component.html#disabling-security-component-for-specific-actions

在某些情况下,您可能希望禁用所有安全检查 一个动作(例如 AJAX 请求)。您可以通过以下方式“解锁”这些操作 将它们列在 beforeFilter 中的 $this->Security->unlockedActions 中。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-01-10
    • 2018-12-10
    • 1970-01-01
    • 2021-02-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多