如何为插件禁用CSRF?

问题描述 投票:0回答:1

我开发了一个CakePHP 3插件,该插件必须处理没有CSRF令牌的POST请求。

在使用插件的应用程序中,我将中间件应用于根范围。

Router::scope('/', function (RouteBuilder $routes) {
    $routes->registerMiddleware('csrf', new CsrfProtectionMiddleware([
        'httpOnly' => true
    ]));

    $routes->applyMiddleware('csrf');
...

如何禁用插件的中间件?

我尝试了$this->addPlugin(\My\Plugin::class, ['middleware' => false]),但是没有用。

或者该插件负责禁用CSRF中间件吗?

cakephp cakephp-3.x
1个回答
0
投票

您可以尝试以下代码:

// In Application::bootstrap()
use ContactManager\Plugin as ContactManagerPlugin;

// Use the disable/enable to configure hooks.
$plugin = new ContactManagerPlugin();

$plugin->disable('middleware');
$this->addPlugin($plugin);
© www.soinside.com 2019 - 2024. All rights reserved.