diff --git a/app/Livewire/Settings/LoginProtection.php b/app/Livewire/Settings/LoginProtection.php index e8639dc..cad3550 100644 --- a/app/Livewire/Settings/LoginProtection.php +++ b/app/Livewire/Settings/LoginProtection.php @@ -60,8 +60,8 @@ class LoginProtection extends Component Setting::put('bruteforce_bantime', (string) $this->bantime); Setting::put('bruteforce_whitelist', implode("\n", $lines)); - // Widening the whitelist immediately clears any now-exempt bans. - foreach (BannedIp::all() as $ban) { + // Widening the whitelist immediately clears any now-exempt active bans. + foreach (BannedIp::active()->get() as $ban) { if ($guard->isExempt($ban->ip)) { $guard->unban($ban->ip); } @@ -154,10 +154,12 @@ class LoginProtection extends Component public function render(BruteforceGuard $guard) { + $ip = (string) request()->ip(); + return view('livewire.settings.login-protection', [ 'bans' => BannedIp::query()->where('banned_until', '>', now())->orderByDesc('banned_until')->get(), - 'currentIp' => (string) request()->ip(), - 'currentIpExempt' => $guard->isExempt((string) request()->ip()), + 'currentIp' => $ip, + 'currentIpExempt' => $guard->isExempt($ip), ]); } } diff --git a/resources/views/livewire/settings/index.blade.php b/resources/views/livewire/settings/index.blade.php index af7c21d..4db2973 100644 --- a/resources/views/livewire/settings/index.blade.php +++ b/resources/views/livewire/settings/index.blade.php @@ -58,6 +58,7 @@ @elseif ($tab === 'users') @elseif ($tab === 'sessions') @elseif ($tab === 'email') + {{-- Unknown ?tab= falls back to profile instead of rendering nothing. --}} @else @endif diff --git a/tests/Feature/Settings/LoginProtectionTabTest.php b/tests/Feature/Settings/LoginProtectionTabTest.php index 863fd45..49dc15a 100644 --- a/tests/Feature/Settings/LoginProtectionTabTest.php +++ b/tests/Feature/Settings/LoginProtectionTabTest.php @@ -61,6 +61,21 @@ class LoginProtectionTabTest extends TestCase $this->assertDatabaseHas('audit_events', ['action' => 'auth.ip_unbanned', 'target' => '203.0.113.5']); } + public function test_unban_all_clears_every_ban(): void + { + $user = User::factory()->create(); + BannedIp::create(['ip' => '203.0.113.5', 'banned_until' => now()->addHour(), 'attempts' => 10]); + BannedIp::create(['ip' => '203.0.113.6', 'banned_until' => now()->addHour(), 'attempts' => 10]); + + $this->actingAs($user); + $token = ConfirmToken::issue('bansClearedAll'); + ConfirmToken::confirm($token); + Livewire::actingAs($user)->test(LoginProtection::class)->call('unbanAll', $token); + + $this->assertDatabaseCount('banned_ips', 0); + $this->assertDatabaseHas('audit_events', ['action' => 'auth.ip_unbanned', 'target' => 'all']); + } + public function test_widening_whitelist_clears_now_exempt_bans(): void { $user = User::factory()->create();