cakephp3.6にてCSRF対策をするために、AppController.phpでCSRFコンポーネントを有効にしました。
PHP
1class AppController extends Controller 2{ 3 public function initialize() 4 { 5 $this->loadComponent('Csrf'); 6 } 7}
FormHelperを使用してフォームも作っているのですが、submitした後、「CSRF token mismatch」のエラーが吐かれ、404ページに移動してしまいます。
エラーログ
Error: [Cake\Http\Exception\InvalidCsrfTokenException] CSRF token mismatch. .. .. /hoge/vendor/cakephp/cakephp/src/Controller/Component/CsrfComponent.php(103): Cake\Controller\Component\CsrfComponent->_validateToken(Object(Cake\Http\ServerRequest))
原因がわからず、困っております。
ご教示のほど、よろしくお願いいたします。
以下、追記です。
/src/Application.php
PHP
1 public function middleware($middlewareQueue) 2 { 3 $middlewareQueue 4 // Catch any exceptions in the lower layers, 5 // and make an error page/response 6 ->add(ErrorHandlerMiddleware::class) 7 8 // Handle plugin/theme assets like CakePHP normally does. 9 ->add(AssetMiddleware::class) 10 11 // Add routing middleware. 12 // Routes collection cache enabled by default, to disable route caching 13 // pass null as cacheConfig, example: `new RoutingMiddleware($this)` 14 // you might want to disable this cache in case your routing is extremely simple 15 ->add(new RoutingMiddleware($this, '_cake_routes_')) 16 17 // Add csrf middleware. 18 ->add(new CsrfProtectionMiddleware([ 19 'httpOnly' => false 20 ])); 21 22 return $middlewareQueue; 23 }
回答1件
あなたの回答
tips
プレビュー