CraftCMS cookieValidationKey должен быть настроен с использованием секретного ключа.

Я использую CraftCMS, и я получаю эту ошибку:

Invalid Configuration – yii\base\InvalidConfigException
craft\web\Request::cookieValidationKey must be configured with a secret key.

Более длинная ошибка:

1. in /code/vendor/yiisoft/yii2/web/Request.phpat line 1678
1669167016711672167316741675167616771678167916801681168216831684168516861687     * Converts `$_COOKIE` into an array of [[Cookie]].
     * @return array the cookies obtained from request
     * @throws InvalidConfigException if [[cookieValidationKey]] is not set when [[enableCookieValidation]] is true
     */
    protected function loadCookies()
    {
        $cookies = [];
        if ($this->enableCookieValidation) {
            if ($this->cookieValidationKey == '') {
                throw new InvalidConfigException(get_class($this) . '::cookieValidationKey must be configured with a secret key.');
            }
            foreach ($_COOKIE as $name => $value) {
                if (!is_string($value)) {
                    continue;
                }
                $data = Yii::$app->getSecurity()->validateData($value, $this->cookieValidationKey);
                if ($data === false) {
                    continue;
                }

Мой файл .env такой:

# The environment Craft is currently running in ("dev", "staging", "production", etc.)
ENVIRONMENT="dev"

# The application ID used to to uniquely store session and cache data, mutex locks, and more
APP_ID="CraftCMS"

# The secure key Craft will use for hashing and encrypting data
SECURITY_KEY="xxxxxxxx"

# The database driver that will be used ("mysql" or "pgsql")
DB_DRIVER="mysql"

# The database server name or IP address
DB_SERVER="mariadb"

# The port to connect to the database with
DB_PORT="3306"

# The name of the database to select
DB_DATABASE="dev_craftcms"

# The database username to connect with
DB_USER="root"

# The database password to connect with
DB_PASSWORD="abc123"

# The database schema that will be used (PostgreSQL only)
DB_SCHEMA=""

# The prefix that should be added to generated table names (only necessary if multiple things are sharing the same database)
DB_TABLE_PREFIX=""

DEFAULT_SITE_URL="http://www.amira.local/"

Я что-то упустил?


person Devin Dixon    schedule 23.11.2020    source источник


Ответы (2)


Ваш файл env предназначен только для хранения этих секретов, поэтому они не передаются в систему управления версиями, Craft не извлекает автоматически значения оттуда напрямую. При этом ключ безопасности устанавливается в общем файле конфигурации Craft config/general.php и должен быть установлен как:

    // The secure key Craft will use for hashing and encrypting data
    'securityKey' => getenv('SECURITY_KEY'),

Подозреваю, что в общем кофиге это не задано, поэтому выдает ошибку. Кроме того, xxxxxxxxx не очень безопасен, я бы рекомендовал использовать там надежный пароль.

person Seth Warburton    schedule 20.01.2021

Вы можете установить свой Craft Key, введя это в свой путь к терминалу:

php craft setup/security-key
person Alexis Dalai Waldo Jiménez    schedule 04.03.2021