Upgraded your self-hosted Dify? Your .env may still have the SECRET_KEY everyone else has
Описание и применение
После обновления Dify файл .env может содержать публичный SECRET_KEY, позволяющий злоумышленникам подписывать токены. Замените его на уникальный ключ, чтобы защитить сессии, JWT и OAuth‑учётные данные.
Задача
After upgrading Dify, the .env file may still contain a public SECRET_KEY that was shipped with older releases, allowing attackers to sign tokens and compromise the instance.
Результат
Replacing the public SECRET_KEY secures the Dify instance against token forgery and credential compromise, while also prompting necessary user notifications and re-authorizations.
Рабочий процесс
- 1. Verify if the old key is present: grep -c '^SECRET_KEY=sk-9f73s3lj' dify/docker/.env
- 2. If count is 1, replace the key: cd dify/docker && cp .env .env.bak && sed -i "s|^SECRET_KEY=.*|SECRET_KEY=$(openssl rand -base64 42)|" .env && docker compose up -d
- 3. Inform users that changing the key will log them out and invalidate file URLs and OAuth integrations.
- 4. Optionally adjust other .env settings: expose ports, set CONSOLE_CORS_ALLOW_ORIGINS, set INIT_PASSWORD, and change default Postgres/Redis passwords.
Доказательства
Up to Dify 1.14.x, docker/.env.example shipped a fixed SECRET_KEY, a long string starting sk-9f73s3lj
What the key does, from Dify's environment variable docs: it's used for "session cookie signing, JWT authentication tokens, file URL signatures (HMAC-SHA256), and encrypting third-party OAuth credentials"
Changing the key "will immediately log out all users, invalidate all file URLs", and OAuth-based plugin integrations must be authorized again because "their encrypted credentials become unrecoverable"
- Дата записи: 2026-10-12T19:56:20.570Z