Yii2 - 错误请求 (#400) |前端和后端 cookie

Yii2 - Bad Request (#400) | Frontend and backend cookies

仅当我在同一个 browser 中打开 frontendbackend 时才会出现此问题。

场景:

Interact with Backend -> Switched Tab -> Interact with Frontend -> Switched Tab Back -> Interact with Backend -> Bad Request (#400)

Cookie 后端

'identityCookie' => [
                'name' => '_backendIdentity',
                'path'=>'/admin',
                'httpOnly' => true,
            ],

Cookie 前端

'identityCookie' => [
                    'name' => '_frontendIdentity',
                    'path'=>'/', 
                    'httpOnly' => true,
                ],

会话后端

'session' => [
            'name' => 'session_backend'
        ],

会话前端

'session' => [
            'name' => 'session_frontend'
        ],

CSRF 的问题在 frontendbackend 上都是不同的,所以当存储同一应用程序的 session 的浏览器有 2 个不同的 CSRF 然后其中一个应用程序将获得 Bad Request (#400)

感谢@indra shastri

对于那些面临同样问题的人:

添加以下内容解决了我的问题。

后端 config/main.php

'request' => [
                'cookieValidationKey' => '[DIFFERENT UNIQUE KEY]',
                'csrfParam' => '_backendCSRF',
            ],

前端 config/main.php

'request' => [
            'cookieValidationKey' => '[RANDOM KEY HERE]',
            'csrfParam' => '_frontendCSRF',
        ],