[9.x] Change session serialization defaults #5787
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
In previous releases of Laravel, the PHP
serialize
andunserialize
functions were used to serialize the session data for storage. In general, this is fine since all Laravel session cookies are encrypted and signed using message authentication; therefore, they can't be tampered with by the client and raw user, controlled input can not make it into theunserialize
function.However, if the application encryption key (
APP_KEY
) is compromised, user controlled input could be passed to theunserialize
function by crafting an encrypted cookie using the stolen encryption key. This could lead to remote code execution.This changes the default behavior of new Laravel 9 applications to use JSON encoding to serialize session data. Applications upgrading from Laravel 8 may continue using PHP serialization without issue - though I will note this in the upgrade guide because I know many people start with a blank Laravel 9 skeleton and move their existing Laravel 8 code into it in order to "upgrade" their application (note that I don't recommend doing this). And, changing this value on an existing application will invalidate existing sessions and logout currently authentication users.
In summary - this does not address any known security vulnerability. A security vulnerability only surfaces if the application encryption key
APP_KEY
is stolen. And, if that happens, your application is still compromised regardless of this change because the attacker can craft valid session cookies to login as other users. This only addresses the possible remote code execution vulnerability if theAPP_KEY
leaks.