PHPLARA-262 Support serializable classes allowlist in MongoStore cache - #3573
PHPLARA-262 Support serializable classes allowlist in MongoStore cache#3573paulinevos wants to merge 1 commit into
Conversation
Laravel added an opt-in allowlist of classes that cache stores may instantiate while unserializing, configured with cache.serializable_classes. MongoStore was the last store not honouring it, so applications hardening their cache had a gap they could not close. The default stays unrestricted, so existing behaviour is unchanged.
There was a problem hiding this comment.
Pull request overview
Adds support for Laravel’s cache.serializable_classes configuration to the MongoDB cache store so applications can restrict which classes may be instantiated during cache unserialization (default remains unrestricted for backwards compatibility).
Changes:
- Pass
cache.serializable_classesfrom the service provider intoMongoStore. - Apply PHP’s
unserialize(..., ['allowed_classes' => ...])option inMongoStorewhen configured. - Add test coverage for default/unrestricted behavior, deny-all behavior, and allowlist behavior; update the cache configuration reference docs.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/Cache/MongoCacheStoreTest.php | Adds tests validating default behavior and the new allowlist/denylist unserialization behavior. |
| src/MongoDBServiceProvider.php | Wires cache.serializable_classes config into the MongoStore constructor. |
| src/Cache/MongoStore.php | Stores the allowlist setting and uses it when unserializing cached values. |
| resources/boost/skills/laravel-mongodb/references/cache-sessions.md | Documents the serializable_classes cache configuration option. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
GromNaN
left a comment
There was a problem hiding this comment.
The PR will have to target the current minor (5.9)
|
|
||
| // Optional: restrict which classes may be unserialized from the cache. | ||
| // null (default) allows all, false allows none, or list allowed classes. | ||
| 'serializable_classes' => null, |
There was a problem hiding this comment.
Maybe set to false, to be secure by default when using this feature.
| 'serializable_classes' => null, | |
| 'serializable_classes' => false, |
| return $repository; | ||
| } | ||
|
|
||
| private function getStoreAllowing(array|bool|null $serializableClasses): Repository |
There was a problem hiding this comment.
null is not used.
| private function getStoreAllowing(array|bool|null $serializableClasses): Repository | |
| private function getStoreAllowing(array|bool $serializableClasses): Repository |
Laravel added an opt-in allowlist of classes that cache stores may instantiate while unserializing, configured with cache.serializable_classes. MongoStore was the last store not honouring it, so applications hardening their cache had a gap they could not close.
The default stays unrestricted, so existing behaviour is unchanged.
Checklist