🔒 Replace serialize/unserialize with JSON for route cache#33
Open
dimitriBouteille wants to merge 3 commits intodevelopfrom
Open
🔒 Replace serialize/unserialize with JSON for route cache#33dimitriBouteille wants to merge 3 commits intodevelopfrom
dimitriBouteille wants to merge 3 commits intodevelopfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Replace
serialize()/unserialize()with JSON for the PSR-6 route cache, and fix the unreachabletry/catchblock that leftRouteLoader::getRoutes()returningfalsewhen the cache payload was corrupted.Why
RouteLoader::getRoutes()deserialized the cached route list withunserialize():Two problems:
strings (class names, paths, HTTP methods) — there is no need to allow arbitrary class deserialization.
What changed
RouteLoader::getRoutes()now persists routes as JSON and validates the shape on read. Any anomaly (invalid JSON, missing/wrong-typed fields, unsupported callback) triggers a transparent fallback to findRoutes() and overwrites the cache.New hydrateRoutes(string): ?Route[]rebuilds Route / RouteAction instances and returns null whenever the payload deviates from the expected shape — letting the caller rebuild instead of returning a half-broken list.New dehydrateRoutes(Route[]): ?stringflattens routes into plain arrays, uses JSON_THROW_ON_ERROR, and refuses to cache when a permissionCallback cannot be safely serialized (Closure, arbitrary object). Such routes stillregister normally; only the cache write is skipped, with an E_USER_NOTICE so it shows up in dev.
New isCacheableCallback(mixed): boolaccepts only null, strings (class-string / function name) and [class-string, method-string] arrays.