Repository navigation
Default serializable_classes = false prevents caching Eloquent models without additional configuration
#60754
Replies: 2 comments
|
This is exactly why Laravel 13 introduced the new The goal is to reduce the risk of PHP deserialization (object injection) attacks. When PHP calls Laravel now defaults to not unserializing arbitrary classes from the cache, and instead requires an explicit allow-list of classes that are safe to restore. (Laravel) This is not just a theoretical concern. PHP has a long history of deserialization vulnerabilities. For example:
|
|
debe añadir el todas las consultas la funcion toArray() si esta dentro de un Cache::remember |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Laravel Version
13.12.0
PHP Version
8.3.31
Database Driver & Version
MySQL
Cache Driver
database
Description
With a fresh Laravel 13 installation, the default cache configuration contains:
'serializable_classes' => false,When caching Eloquent models or Eloquent collections using the Database cache driver, the cached value cannot be restored correctly with the default configuration.
For example:
Instead of returning an
Illuminate\Database\Eloquent\CollectioncontainingProductmodels, the cached value contains__PHP_Incomplete_Classinstances.As a result, attempting to access model properties results in errors such as:
or inspecting the cached value shows
__PHP_Incomplete_Classobjects.The issue disappears after explicitly allowing the serialized classes, for example:
After clearing the cache and configuration, the same code works correctly.
Expected Behavior
I expected one of the following:
serializable_classes.Question
Is this the intended behavior?
If so, perhaps the default configuration or documentation could better explain that Eloquent models cannot be cached unless they are explicitly allowed.
Steps To Reproduce
Productmodel and migration.__PHP_Incomplete_Classobjects when the default configuration is:'serializable_classes' => false,The cached collection is now restored correctly as an
Illuminate\Database\Eloquent\CollectioncontainingProductmodel instances.All reactions