1. Red
  2. Learn
  3. Frameworks and runtimes

Leaked Laravel APP_KEY: why it's RCE and how to rotate it

Leaked Laravel APP_KEY: what a holder can forge, how to rotate it without stranding stored data, and why APP_PREVIOUS_KEYS can keep a leaked key working.

By Timothy Lindblom, FounderPublished 4 November 20268 min readHow we check facts
On this page
  1. Why does a leaked APP_KEY become remote code execution?
  2. Is every leaked key an RCE?
  3. How did the key leak, and where else is it?
  4. How do I rotate the key without a mess?
  5. Should I use APP_PREVIOUS_KEYS for a leaked key?
  6. Am I affected? A three-state self-test
  7. Was the key already used, and what should I look for?
  8. Which Laravel versions are still supported?
  9. What can an outside scan tell me about this?

If your Laravel APP_KEY has leaked, treat it as compromised today. Anyone holding it can forge cookies and other encrypted values your app trusts, and in some code paths that reaches remote code execution. Generate a new key, deploy it to every server and worker, and keep the old key out of APP_PREVIOUS_KEYS unless you need it briefly to re-encrypt stored data. Deleting the file from GitHub changes nothing.

FactDetailSource
What the key doesEncrypts and signs every cookie, including the session cookieLaravel docs
Why a leak mattersdecrypt() unserializes by default, so a forged encrypted value can become code executionSynacktiv, 10 July 2025
Scale267,952 keys in public sources; about 260,000 on GitHub; 400 validated as functionalSynacktiv, GitGuardian, 10 July 2025
Oldest CVECVE-2018-15133, CVSS v3.1 8.1, Laravel up to 5.5.40 and 5.6.0 to 5.6.29NVD
Known exploitedCVE-2018-15133 added to CISA KEV on 16 January 2024CISA
Graceful rotationAPP_PREVIOUS_KEYS, introduced in Laravel 11Laravel 11 notes
Checked4 November 2026this page
267,952keys found in public sources (Synacktiv)
400validated as functional (GitGuardian)
4confirmed code execution cases in production (GitGuardian)

The first number is Synacktiv's count of keys it collected, and the other two are GitGuardian's counts from its own research, both published 10 July 2025. They describe a research dataset, not every Laravel site.

Why does a leaked APP_KEY become remote code execution?

Laravel encrypts every cookie, including the session cookie, with the key and signs the result with a message authentication code. The signature is what stops a visitor from editing a cookie. Whoever holds the key can produce a valid one.

That alone is a forgery problem. It turns into code execution when the app decrypts the forged value and then unserializes it. Synacktiv's analysis explains that decrypt() defaults to unserialization, which lets PHP object deserialization run. We do not reproduce the technique here.

The older example is CVE-2018-15133. NVD describes an unserialize call on an X-XSRF-TOKEN value and says the attacker needs the application key. CISA lists it as known exploited, with the same condition.

Is every leaked key an RCE?

No, and the honest answer is "it depends on the code path". Current Laravel does not unserialize cookies by default. The 12.x source for EncryptCookies has a static serialization flag that defaults to false.

Applications still create their own paths. Synacktiv's three application CVEs involved a route that accepts encrypted input, a cookie deserialization enabled by a Passport setting, and SESSION_DRIVER=cookie, which stores the session payload in the cookie itself. The Laravel session docs list that driver.

GitGuardian found 400 functional keys and 4 confirmed code execution cases. Those four are the cases it confirmed, so read them as a floor. The decision is the same either way. You cannot prove from outside which path your app exposes, so rotate. A separate Laravel-family risk is an outdated Livewire, and checking your Livewire v3 version takes a minute.

How did the key leak, and where else is it?

The usual routes are a committed .env, a .env served by the web server, and a default key shipped inside a purchased or open-source application. Synacktiv found a vendor default key that appeared on 1,650 public instances.

The Laravel configuration docs say the .env file should not be committed, and that an intruder reaching the repository would see every credential in it. The deployment docs say the web root must be public/, because serving from the project root exposes sensitive files, and their sample Nginx config denies dotfiles.

A key that was ever public is not made private again by removing it. GitGuardian reports 50 keys that were deleted from repositories and still worked in production. Search your history for it: git log --all --oneline -- .env lists every commit that touched the file.

The 30-second check for .env and .git requests shows how to see whether your server answers for those paths. If the file already reached a remote, what to do when .env was pushed to GitHub covers the first hour, and a push-protection and pre-commit scanner stops the next one. The key is rarely the only secret in that file, so the same incident usually needs the steps in this guide to rotating every other credential.

How do I rotate the key without a mess?

The order matters more than the commands. The aim is a new key everywhere, the old key accepted nowhere, and your stored data still readable.

Rotation flow: new key generated, deployed to every server, workers reloaded, stored data re-encrypted, old key removed 1. New key generate 2. Deploy every server 3. Reload cache and workers 4. Re-encrypt stored data 5. Drop old key confirm
The order of a rotation. Step 4 is needed only if your app stores values encrypted with the key.

What are the steps?

  • Find where the key lives: .env on each server, container environment, CI variables, a secrets manager, and any staging copy that shares it.
  • Generate a new key with php artisan key:generate, which writes it to your environment file. In a hosted pipeline, put the new value into the platform's secret store instead.
  • Deploy the same new key to every server and container. A mixed fleet logs users out at random and fails decryption on some requests.
  • Rebuild cached configuration. The Laravel configuration docs say that once config:cache has run, .env is no longer loaded, so run php artisan config:cache again.
  • Reload long-running processes. The deployment docs say queue workers, Reverb and Octane need a reload to use new code, with php artisan reload. Otherwise restart them through your process monitor.
  • Decide what to do about encrypted stored data (next section), then remove any old key from APP_PREVIOUS_KEYS.
  • Rotate the other secrets that sat beside the key in the same file.

Expect every user to be logged out. The encryption docs say a key change signs out all authenticated sessions, so warn your users, or your clients, before you do it.

Should I use APP_PREVIOUS_KEYS for a leaked key?

This is the trap the documentation does not spell out. Laravel 11 added APP_PREVIOUS_KEYS so that a routine rotation does not log everyone out. When decrypting, Laravel tries the current key, then each previous key in turn until one works.

For a routine rotation that is the feature you want. For a leaked key it means the leaked key keeps decrypting whatever it is sent. It follows from the documented behaviour, so a leaked key left in that list is still a working key.

OptionUsersStored encrypted dataLeaked key still acceptedUse when
New key only, nothing in APP_PREVIOUS_KEYSAll logged outUnreadable until restoredNoYou store nothing encrypted, or you can restore it from backup
New key plus the old key in APP_PREVIOUS_KEYS for a short windowNot logged out for stale sessionsReadableYes, until you remove itYou must re-encrypt data first. Keep the window short
Routine rotation of a key that never leakedNot logged outReadableNot applicableScheduled hygiene

If you need the second row, re-encrypt in one planned job: read each encrypted column with the old key still listed, write it back so it is encrypted with the new key, then remove the old key and reload. Run it on a copy first. Check your models for encrypted casts and your code for Crypt::encryptString calls, because those are the values a rotation strands.

Am I affected? A three-state self-test

Am I affected? Where you stand right now

A check from outside can see an exposed environment file or a source map. It cannot see your repository history, your servers' environment, or whether anyone used the key.

  1. Detected Your key appears in a repository or history, or your domain serves .env or .git to anyone. Treat the key as public. Rotate it today and start the incident steps below.
  2. Unknown Nothing visible from outside, but you cannot say where the key has been. This is the common case. Search repository history and CI logs, check old backups and shared staging servers, and rotate if you cannot rule it out.
  3. Confirmed by owner evidence You hold a deploy record of the new key on every server, a reload after it, and a settings dump showing the old key is not in APP_PREVIOUS_KEYS. The rotation is complete. Whether the old key was used before then is a separate question.

No scan, ours included, moves you from "unknown" to "confirmed".

Was the key already used, and what should I look for?

Rotation closes the door going forward. It does not remove anything planted while the key was public. If the key was exposed for a long period, assume the question is open until you have looked.

Look inside the server for files you did not deploy, especially under storage/, public/ and bootstrap/cache/. Check scheduled tasks and queue jobs you did not create, new administrator accounts, changed .env values, and unexpected outbound connections from the PHP process. Compare logs for the period the key was public against requests that carried unusually long cookie values.

If you find anything, follow a step-by-step incident response plan and rotate every credential the server could read, not only this key. After the fix, this checklist for confirming the fix held explains what evidence counts.

Which Laravel versions are still supported?

Rotation is easier on a supported release, and older ones have no graceful option at all. This table is from the Laravel support policy, read on 4 November 2026.

VersionReleasedSecurity fixes untilStatus on 4 November 2026
1014 February 20234 February 2025Past end of security fixes
1112 March 202412 March 2026Past end of security fixes
1224 February 202524 February 2027Security fixes only
1317 March 202617 March 2028Supported

APP_PREVIOUS_KEYS arrived in 11, so on 10 and earlier a rotation always signs users out and strands encrypted data. Plan the upgrade as part of the same job.

What can an outside scan tell me about this?

The free scan reads the stack your site serves and matches each version to known vulnerabilities. It also checks for .git, .env, backups and open directory listings, and for API keys and tokens in shipped bundles. It is a lookup. It can say a file is readable. It cannot say the key sat in a private repository for two years or that your workers reloaded.

For a closer look at what an outside view cannot settle, read the limits of an outside-only scan. If you run Laravel next to other PHP CMSs, how PHP2Shell affects Drupal, Joomla, MediaWiki and Laravel is the related read, and the other framework guides cover the rest. The wider context is in the October 2026 tracker.

Questions people ask

I committed my .env to GitHub and deleted it. Am I fine?

No. The key is still in the commit history, in forks and in any clone made while it was public, and your running app still uses it. GitGuardian found 50 keys that had been deleted from repositories but still worked in production. Rotate the key, then treat deletion as housekeeping.

If I change APP_KEY, will every user be logged out?

Yes. Laravel's documentation says changing the key logs out all authenticated sessions, because every cookie, including the session cookie, is encrypted. It also says data encrypted with the previous key can no longer be decrypted, unless you list that key in APP_PREVIOUS_KEYS.

Does a leaked APP_KEY always mean someone can run code on my server?

No, and you should still rotate. Whether a forged value reaches code execution depends on your Laravel version, your settings and your own code. Synacktiv documented cases in the cookie, session and route layers, and GitGuardian confirmed 4 production cases among 400 functional keys.

Should I put the leaked key in APP_PREVIOUS_KEYS?

Only briefly, and only if you must re-encrypt stored data. Laravel tries every previous key when decrypting, so a leaked key listed there still decrypts what an attacker sends. Re-encrypt your data, then remove it. If you have no encrypted columns, leave APP_PREVIOUS_KEYS empty.

How do I know whether someone already used the key?

From the outside you cannot tell. Look inside the server for files you did not deploy, new scheduled tasks, unfamiliar admin users and odd outbound connections, and check logs for the period the key was public. If you find any, follow an incident process rather than only rotating.

Which Laravel versions support APP_PREVIOUS_KEYS?

Laravel 11 introduced it, and the 12.x and 13.x documentation describe it. Laravel 11 and older are past their security fix dates at our check on 4 November 2026, so on those versions plan an upgrade as well as a rotation.

Sources

  1. GitGuardian: Exploiting public APP_KEY leaks (10 July 2025)About 260,000 APP_KEYs on GitHub, 400 validated as functional, 4 confirmed code execution cases, and 50 keys deleted from repositories that stayed valid in production. Checked 24 October 2026.
  2. Synacktiv: Laravel APP_KEY leakage analysis (10 July 2025)267,952 keys from public sources, why decrypt() defaulting to unserialization matters, the three application CVEs, 3.56% of public instances. Checked 24 October 2026.
  3. Laravel 12.x documentation: EncryptionWhat APP_KEY drives, graceful rotation with APP_PREVIOUS_KEYS, the decryption order. Checked 24 October 2026.
  4. Laravel 13.x documentation: EncryptionSame rotation section on the newest release. Checked 24 October 2026.
  5. Laravel 11.x release notes: graceful encryption key rotationWhere APP_PREVIOUS_KEYS was introduced. Also the support policy table. Checked 24 October 2026.
  6. Laravel 13.x release notes: support policyBug fix and security fix end dates per major version, including the 17 March 2026 release of 13. Checked 4 November 2026.
  7. Laravel 12.x documentation: ConfigurationKeep .env out of source control, config caching and the env() function, debug mode.
  8. Laravel 12.x documentation: DeploymentWeb root must be public/, dotfile rule in the sample Nginx config, php artisan reload for long-running workers.
  9. Laravel 12.x documentation: HTTP SessionSession drivers, including the cookie driver.
  10. NVD: CVE-2018-15133Unserialize on a token value, needs the application key. CVSS v3.1 8.1. Affects up to 5.5.40 and 5.6.0 to 5.6.29. Checked 24 October 2026.
  11. CISA Known Exploited Vulnerabilities catalog: CVE-2018-15133Listed as Laravel Deserialization of Untrusted Data Vulnerability, added 16 January 2024.
  12. laravel/framework: EncryptCookies middleware (12.x source)Cookie serialization flag and its default.

Facts on this page are dated and point at the primary source next to them. If a vendor status changes after the date shown, the vendor's page wins; tell us at support@run.cloud and we will update it.