首页 > 解决方案 > cakephp 4 为特定操作禁用 csrf

问题描述

我在 cakephp4 项目上工作,
希望允许一个动作从没有 csrf 的任何客户端获取发布请求。
根据文档,我编写了以下代码,但它在发布请求时显示 BAD REQUEST。

class MylogsController extends AppController
{

  public function initialize(): void
  {
      parent::initialize(); 
      $this->loadComponent('Security');
  }

  public function beforeFilter(EventInterface $event)
  {
      parent::beforeFilter($event);
      $this->Security->setConfig('unlockedActions', ['add']);
  }

  public function add()
  {
    debug($this->request->getData());exit;
  }
}

标签: ajaxhttp-postcsrfcakephp-4.x

解决方案


推荐阅读