← PHP / Laravel · Contents

PHP-011 / Intermediate

Hardcoding APP_KEY or exposing it in a public repository

A02:2021 Cryptographic Failures · CWE-321 Hard-coded Cryptographic Key

Why is this a problem?

APP_KEY can be used to forge or decrypt sessions, cookies and encrypted values.

How to fix it

bash
php artisan key:generate   # Store only in .env; maintain .gitignore
# On exposure: rotate the key, invalidate sessions and plan to re-encrypt encrypted data

Further reading