Skip to content

PHPLARA-262 Support serializable classes allowlist in MongoStore cache - #3573

Open
paulinevos wants to merge 1 commit into
mongodb:5.xfrom
paulinevos:phplara-262
Open

PHPLARA-262 Support serializable classes allowlist in MongoStore cache#3573
paulinevos wants to merge 1 commit into
mongodb:5.xfrom
paulinevos:phplara-262

Conversation

@paulinevos

@paulinevos paulinevos commented Aug 28, 2026

Copy link
Copy Markdown
Contributor

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

  • Add tests and ensure they pass

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.
@paulinevos
paulinevos requested a review from a team as a code owner August 28, 2026 11:09
@paulinevos
paulinevos requested review from GromNaN and a lite review from Copilot August 28, 2026 11:09

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_classes from the service provider into MongoStore.
  • Apply PHP’s unserialize(..., ['allowed_classes' => ...]) option in MongoStore when 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 GromNaN left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe set to false, to be secure by default when using this feature.

Suggested change
'serializable_classes' => null,
'serializable_classes' => false,

return $repository;
}

private function getStoreAllowing(array|bool|null $serializableClasses): Repository

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null is not used.

Suggested change
private function getStoreAllowing(array|bool|null $serializableClasses): Repository
private function getStoreAllowing(array|bool $serializableClasses): Repository

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants