diff --git a/config/fortify.php b/config/fortify.php index e53bbb2..0681407 100644 --- a/config/fortify.php +++ b/config/fortify.php @@ -101,7 +101,10 @@ return [ | */ - 'middleware' => ['web'], + // Throttle all Fortify endpoints (registration has no built-in limiter) to + // blunt signup spam / CPU-exhaustion via repeated password hashing. Login + // keeps its own stricter 'login' limiter on top. + 'middleware' => ['web', 'throttle:20,1'], /* |-------------------------------------------------------------------------- diff --git a/tests/Feature/Auth/RegisterTest.php b/tests/Feature/Auth/RegisterTest.php index 567edf4..97afdfc 100644 --- a/tests/Feature/Auth/RegisterTest.php +++ b/tests/Feature/Auth/RegisterTest.php @@ -39,6 +39,21 @@ it('refuses to register with an existing customer email (account-claim guard)', expect(User::query()->where('email', 'claim@signup.test')->exists())->toBeFalse(); }); +it('throttles repeated registration attempts', function () { + $hit429 = false; + for ($i = 0; $i < 24; $i++) { + $res = $this->post(route('register.store'), [ + 'name' => 'S', 'email' => "spam{$i}@signup.test", + 'password' => 'password1234', 'password_confirmation' => 'password1234', + ]); + if ($res->status() === 429) { + $hit429 = true; + break; + } + } + expect($hit429)->toBeTrue(); +}); + it('rejects a mismatched password confirmation', function () { $this->post(route('register.store'), [ 'name' => 'X',