# App Key Analyzer
Category | Severity | Time To Fix |
---|---|---|
🛡️ Security | ⚠️ Critical | 1 minute |
Class: Enlightn\Enlightn\Analyzers\Security\AppKeyAnalyzer
# Introduction
This analyzer confirms that your application key and cipher are set.
Your laravel app uses the application key for symmetric encryption and one way hashes (for SHA256 hashes only). Some use cases include:
- Encryption of cookies (symmetric).
- Signed URLs (hash).
- Signing of serialized closures (hash).
- Password reset tokens (hash).
- Model data encryption (symmetric).
- Job encryption (symmetric).
- Session data encryption (symmetric).
# How To Fix
If your app key is not set, you may run the key:generate
Artisan command to generate your app key:
php artisan key:generate
# Tip: Rotate Your App Key Regularly
It is generally considered a good practice to rotate your app key on a regular basis (e.g. every six months) or in specific situations (such as when a developer with access to the key leaves your company).
Just make sure of the following while rotating your app key:
- Note that during key rotation, your users that are currently logged in will have their sessions invalidated (if cookies are encrypted).
- Make sure all encrypted jobs have completed processing.
- If you are using Eloquent's encrypted casting, make sure to decrypt (using the old app key) and then encrypt (using the new app key) your encrypted model data.
- If you are using signed URLs, you would need to re-generate these URLs and email your users.
- If you encrypt and decrypt anything in your application using either of the
Encrypter
class,Crypt
facade or theencrypt
anddecrypt
helpers, make sure to decrypt your data (using the old app key) and then encrypt (using the new app key) it back again.
You do not have to worry about password hashing, as the Laravel app key is not used for hashing passwords.