Skip to content

Commit e0fab3b

Browse files
committed
fix: 🐛 Leave null cache.serializable_classes untouched under Laravel 13
Laravel 13's cache.serializable_classes is tri-state: null disables deserialization enforcement entirely, false blocks all objects, and an array is an allow-list. The auto-registration introduced in 13.2.0 coerced null into an array, silently switching the whole application into strict allow-list mode and breaking cache reads for any class outside this package. Return early when the value is null so apps that run with enforcement disabled are left as they were. The false-to-array path is preserved so hardened Laravel 13 apps still get working geocoder caching. Seed the Laravel 13 default (false) in the test environment so the discovery tests exercise the real hardened starting point instead of the implicit null Testbench leaves in place. Fixes #210
1 parent 119bf84 commit e0fab3b

3 files changed

Lines changed: 26 additions & 1 deletion

File tree

src/Providers/GeocoderService.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,21 @@ protected function registerSerializableClasses(): void
5656
return;
5757
}
5858

59+
$existing = config("cache.serializable_classes");
60+
61+
// Laravel 13 treats a `null` `serializable_classes` as "enforcement
62+
// disabled" — any class may be unserialized from the cache. Converting
63+
// it to an array here would silently switch the entire application into
64+
// strict allow-list mode, breaking cache reads for classes outside this
65+
// package. When enforcement is off there is nothing to register. See #210.
66+
if ($existing === null) {
67+
return;
68+
}
69+
5970
if (self::$discoveredSerializableClasses === []) {
6071
self::$discoveredSerializableClasses = $this->discoverSerializableClasses();
6172
}
6273

63-
$existing = config("cache.serializable_classes");
6474
$existing = is_array($existing)
6575
? $existing
6676
: [];

tests/CreatesApplication.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,9 @@ protected function getEnvironmentSetUp($app)
2323
'serialize' => false,
2424
]);
2525
$app['config']->set('geocoder.cache.store', 'geocode');
26+
// Mirror the Laravel 13 default so discovery tests exercise the real
27+
// hardened starting point (`false`) rather than the implicit null
28+
// Testbench would otherwise leave in place.
29+
$app['config']->set('cache.serializable_classes', false);
2630
}
2731
}

tests/Feature/Providers/GeocoderServiceTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,17 @@
431431
expect($registered)->toContain(Collection::class);
432432
});
433433

434+
it('leaves a null cache.serializable_classes untouched (Laravel 13 enforcement disabled)', function () {
435+
config(['cache.serializable_classes' => null]);
436+
437+
$provider = new GeocoderService(app());
438+
$method = new \ReflectionMethod($provider, 'registerSerializableClasses');
439+
$method->setAccessible(true);
440+
$method->invoke($provider);
441+
442+
expect(config('cache.serializable_classes'))->toBeNull();
443+
});
444+
434445
it('skips auto-registration when geocoder.cache.auto_register_serializable_classes is false', function () {
435446
config([
436447
'geocoder.cache.auto_register_serializable_classes' => false,

0 commit comments

Comments
 (0)