mirror of
https://github.com/HolgerHatGarKeineNode/einundzwanzig-app.git
synced 2026-06-05 01:15:36 +00:00
🛡️ **Add robust Livewire payload validation and throttling**
- ✅ Implemented handling for `CorruptComponentPayloadException` to prevent logging noise and improve exception management. - 🛠️ Added IP-based throttling (120 requests/min) for the `/livewire/update` endpoint with middleware integration for better traffic control. - ✅ Introduced unit tests to validate throttle settings and middleware application. - 🧪 Enhanced tests for ensuring silent handling of corrupt payload scenarios and reduced log noise.
This commit is contained in:
@@ -4,6 +4,7 @@ use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Livewire\Exceptions\MethodNotFoundException;
|
||||
use Livewire\Features\SupportLifecycleHooks\DirectlyCallingLifecycleHooksNotAllowedException;
|
||||
use Livewire\Mechanisms\HandleComponents\CorruptComponentPayloadException;
|
||||
|
||||
it('returns 400 for lifecycle-hook probing instead of 500', function () {
|
||||
Route::get('/_test/livewire-lifecycle-probe', function () {
|
||||
@@ -42,3 +43,17 @@ it('still surfaces genuine method-not-found bugs', function () {
|
||||
|
||||
expect($this->get('/_test/livewire-real-method-not-found')->status())->not->toBe(400);
|
||||
});
|
||||
|
||||
it('does not report corrupt Livewire snapshot payloads', function () {
|
||||
Log::spy();
|
||||
|
||||
Route::get('/_test/livewire-corrupt-payload', function () {
|
||||
throw new CorruptComponentPayloadException;
|
||||
});
|
||||
|
||||
$this->get('/_test/livewire-corrupt-payload');
|
||||
|
||||
Log::shouldNotHaveReceived('error');
|
||||
Log::shouldNotHaveReceived('critical');
|
||||
Log::shouldNotHaveReceived('emergency');
|
||||
});
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
it('registers a generous Livewire update throttle keyed by IP', function () {
|
||||
$limiter = RateLimiter::limiter('livewire');
|
||||
|
||||
expect($limiter)->not->toBeNull();
|
||||
|
||||
$request = Request::create('/livewire/update', 'POST');
|
||||
$request->server->set('REMOTE_ADDR', '203.0.113.10');
|
||||
|
||||
$limit = $limiter($request);
|
||||
|
||||
expect($limit->maxAttempts)->toBe(120)
|
||||
->and($limit->decaySeconds)->toBe(60)
|
||||
->and($limit->key)->toBe('203.0.113.10');
|
||||
});
|
||||
|
||||
it('applies the livewire throttle middleware to the update route', function () {
|
||||
$route = Route::getRoutes()->getByName('livewire.update');
|
||||
|
||||
expect($route)->not->toBeNull()
|
||||
->and($route->gatherMiddleware())->toContain('throttle:livewire');
|
||||
});
|
||||
Reference in New Issue
Block a user