Skip to content

Commit 88c31d7

Browse files
jasonvargaclaude
andcommitted
Serialize nocache regions before storing in cache
Wrap Region objects in serialize() before putting them in the cache store so the cache layer only sees a string. This avoids issues with Laravel 13's serializable_classes allowlist, since Region context can contain arbitrary objects. We control the unserialize() call ourselves with allowed_classes => true. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 1b3c29d commit 88c31d7

2 files changed

Lines changed: 3 additions & 3 deletions

File tree

src/StaticCaching/NoCache/DatabaseSession.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public function region(string $key): Region
3030
throw new RegionNotFound($key);
3131
}
3232

33-
return unserialize($region->region);
33+
return unserialize($region->region, ['allowed_classes' => true]);
3434
}
3535

3636
protected function cacheRegion(Region $region)

src/StaticCaching/NoCache/Session.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function regions(): Collection
5151
public function region(string $key): Region
5252
{
5353
if ($this->regions->contains($key) && ($region = StaticCache::cacheStore()->get('nocache::region.'.$key))) {
54-
return $region;
54+
return $region instanceof Region ? $region : unserialize($region, ['allowed_classes' => true]);
5555
}
5656

5757
throw new RegionNotFound($key);
@@ -150,6 +150,6 @@ protected function resolvePageAndPathForPagination(): void
150150

151151
protected function cacheRegion(Region $region)
152152
{
153-
StaticCache::cacheStore()->forever('nocache::region.'.$region->key(), $region);
153+
StaticCache::cacheStore()->forever('nocache::region.'.$region->key(), serialize($region));
154154
}
155155
}

0 commit comments

Comments
 (0)