A Filament Upgrade Broke Our Livewire Security Test and Found a 500
Filament renamed an internal locked property, and our tamper test failed. The quick fix kept it green but tested something else. The red production case showed a real gap: forged Livewire updates returned 500.
The test that guards locked Livewire state
DeployWatchers has a Filament admin panel built on Livewire. Livewire keeps component state in the browser and sends it back with every request, so a public property can be changed by anyone who can edit that request. The #[Locked] attribute (opens in a new tab) is the guard: Livewire refuses to update a locked property from the client.
We had a test that tampers with locked state on purpose. It renders an admin page, takes the component snapshot and posts an update for one of Filament's internal locked properties:
it('rejects changes to Filament locked state and only reports them in debug mode', function (bool $debug) {
config(['app.debug' => $debug]);
$sentry = fakeSentry();
$this->actingAs(User::factory()->admin()->create());
$component = Livewire::test(LegalSettings::class);
$response = $this->withHeader('X-Livewire', 'true')->postJson(app('livewire')->getUpdateUri(), [
'components' => [[
'snapshot' => json_encode($component->snapshot, JSON_THROW_ON_ERROR),
'updates' => ['loadedDeferredSchemas' => ['form' => true]],
'calls' => [],
]],
]);
if ($debug) {
$response->assertStatus(500);
expect($sentry->errors()[0]->getExceptions()[0]->getType())
->toBe(CannotUpdateLockedPropertyException::class);
} else {
$response->assertStatus(419)->assertContent('');
expect($sentry->errors())->toBe([]);
}
})->with([false, true]);
The production branch matters most. With APP_DEBUG=false, Livewire answers a locked-property update with an empty 419 and does not report it. A forged request is an attacker or a scanner, not a bug, so it should not reach our error tracker.
A routine upgrade broke it
While testing PHP 8.6 (our write-up), we updated Filament from 5.11 to 5.12 on PHP 8.5. The whole suite passed except both cases of this test:
debug=true:
Failed asserting that two strings are identical.
-'Livewire\Features\SupportLockedProperties\CannotUpdateLockedPropertyException'
+'Livewire\Exceptions\PublicPropertyNotFoundException'
debug=false:
Expected response status code [419] but received 500.
The exception message explained the cause:
Unable to set component data. Public property [$loadedDeferredSchemas] not found on component: [App\Filament\Pages\LegalSettings]
Filament had renamed the property to loadedLazySchemas as part of a lazy-loading refactor (filamentphp/filament#21015 (opens in a new tab)). It is an internal property of a trait, so there was no upgrade note, and there did not need to be one. Our test had reached into Filament's internals, and the internals changed.
Our first fix made the test pass and stop testing
The first repair looked reasonable. Instead of a hard-coded name, the test used reflection to pick any public property with #[Locked] that was present in the snapshot:
$locked = collect((new ReflectionClass(LegalSettings::class))->getProperties(ReflectionProperty::IS_PUBLIC))
->first(fn (ReflectionProperty $property): bool => $property->getAttributes(Locked::class) !== []
&& array_key_exists($property->getName(), $component->snapshot['data']));
The test passed again. When we came back to it a week later, we checked which property it actually used. It was defaultAction, from Filament's actions trait, not the lazy-schema property the test had been written for. The test still exercised Livewire's locked guard, so it was not useless. But it no longer tested what its name and history said, and the next Filament release could quietly change its target again.
The final version names the property and fails loudly if it disappears or loses the attribute:
$property = new ReflectionProperty(LegalSettings::class, 'loadedLazySchemas');
expect($property->getAttributes(Locked::class))->not->toBeEmpty()
->and($component->snapshot['data'])->toHaveKey('loadedLazySchemas');
If Filament renames it again, the failure will say exactly that, instead of producing an unrelated exception from Livewire.
The red test was describing production
The more useful lesson was in the debug=false failure. We had read it as "wrong exception, test is stale". It was also a statement about production: an update for a property that does not exist returned 500, not 419.
We reproduced it with the old test and the status assertion removed. In production mode, the forged update returned 500 and created one error event of type PublicPropertyNotFoundException.
Livewire 4.4 handles several kinds of forged update quietly in production:
| Forged update | Production response | Reported |
|---|---|---|
Changes a #[Locked] property |
Empty 419 |
No |
| Sends a value of the wrong type to a typed property | 419 (abort(419)) |
No |
| Calls a method that does not exist | Empty 419 |
No |
| Corrupted snapshot (checksum mismatch) | Empty 419 |
No |
| Sets a property that does not exist | 500 |
Yes |
Uses a dot path deeper than max_nesting_depth (default 10) |
500 |
Yes |
The source makes the intent clear. For wrong-type values, HandleComponents aborts with 419 so a scanner's request "never reaches the top-level catch (which would report it as a real bug)". PublicPropertyNotFoundException and MaxNestingDepthExceededException have no such handling, so Laravel renders them as ordinary server errors. We checked Livewire 4.4.10 and 4.4.11.
The next question was who can send such a request. A valid snapshot is signed by the server, so an attacker needs one from a real page. Filament's login page is a public Livewire component. A temporary test against Filament\Auth\Pages\Login with APP_DEBUG=false showed:
updates {doesNotExist: 'x'} -> status 500, error events 1
updates {'data.nope': 'x'} -> status 200, error events 0
So any visitor could produce a 500 and an error report per request, without logging in. Nothing leaks: the response is a generic server error, and the property is never set. But for us it still matters. Error-rate alerts, the Sentry quota and the "unexpected crash" signal all treat these requests as real failures. For a product that monitors other people's deployments, false 500s in our own metrics are not acceptable.
The fix: one handler in bootstrap/app.php
We answer these two exceptions the same way Livewire answers a locked-property update, and only in production:
use Livewire\Exceptions\MaxNestingDepthExceededException;
use Livewire\Exceptions\PublicPropertyNotFoundException;
->withExceptions(function (Exceptions $exceptions): void {
// ...
$forgedLivewireUpdate = static fn (Throwable $e): bool => ! config('app.debug')
&& ($e instanceof PublicPropertyNotFoundException || $e instanceof MaxNestingDepthExceededException);
$exceptions->dontReportWhen($forgedLivewireUpdate);
$exceptions->render(static fn (Throwable $e) => $forgedLivewireUpdate($e) ? response('', 419) : null);
})
With APP_DEBUG=true nothing changes. A developer who mistypes a wire:model name still gets the full error page.
The regression test posts both forged updates to the anonymous login component, in both modes:
it('answers forged Livewire updates of unknown or over-deep properties like locked ones', function (bool $debug, array $updates, string $exception) {
config(['app.debug' => $debug]);
$sentry = fakeSentry();
$component = Livewire::test(Login::class);
$response = $this->withHeader('X-Livewire', 'true')->postJson(app('livewire')->getUpdateUri(), [
'components' => [[
'snapshot' => json_encode($component->snapshot, JSON_THROW_ON_ERROR),
'updates' => $updates,
'calls' => [],
]],
]);
if ($debug) {
$response->assertStatus(500);
expect($sentry->errors()[0]->getExceptions()[0]->getType())->toBe($exception);
} else {
$response->assertStatus(419)->assertContent('');
expect($sentry->errors())->toBe([]);
}
})->with([false, true])->with([
'unknown property' => [['doesNotExist' => 'x'], PublicPropertyNotFoundException::class],
'over-deep path' => [['data'.str_repeat('.a', 11) => 'x'], MaxNestingDepthExceededException::class],
]);
Without the handler, both production cases fail with Expected response status code [419] but received 500, and both debug cases pass. With it, all four pass, along with the rest of the suite.
Checking it in production
Before the deploy, composer audit blocked us for an unrelated reason: a batch of Filament security advisories had been published for versions below 5.12.1. We updated to 5.12.4 and shipped both changes together.
After the deploy, we ran a short check from the browser console on an authenticated admin page. It takes the snapshot of a Livewire widget and sends the two forged updates:
const lw = document.querySelector('script[data-update-uri]');
const snapshot = document.querySelector('[wire\\:snapshot]').getAttribute('wire:snapshot');
const send = async (updates) => {
const r = await fetch(lw.dataset.updateUri, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Livewire': '1' },
body: JSON.stringify({ _token: lw.dataset.csrf, components: [{ snapshot, updates, calls: [] }] }),
});
return `${r.status}, body length ${(await r.text()).length}`;
};
console.log('unknown property:', await send({ doesNotExist: 'x' }));
console.log('over-deep path: ', await send({ ['data' + '.a'.repeat(11)]: 'x' }));
Both returned 419 with an empty body. The anonymous login path goes through the same exception handler and is covered by the test above; we did not sign out of production to repeat it there.
What we changed in how we test framework internals
- A test that names a framework's internal property should assert that the property exists. Otherwise a rename turns a security test into a test of something else, and the failure points the wrong way.
- Do not make such tests self-healing. Picking "any locked property" kept the test green and hid the fact that its target had changed. A loud failure after an upgrade is cheaper.
- Read both branches of a failing debug/production test. The debug failure told us the test was stale. The production failure told us how real users would see the same request.
- Check how your app answers forged Livewire updates. Run the console snippet above on a page of your own app with
APP_DEBUG=false. If an unknown property returns500, every scanner that finds a public Livewire page can raise your error rate.
Catch problems after your next deployment
Monitor availability, browser JavaScript errors and visual changes with DeployWatchers.