]> BookStack Code Mirror - bookstack/commitdiff
Added throttling to password reset requests
authorDan Brown <redacted>
Fri, 8 Oct 2021 22:19:37 +0000 (23:19 +0100)
committerDan Brown <redacted>
Fri, 8 Oct 2021 22:19:37 +0000 (23:19 +0100)
app/Config/auth.php
app/Http/Controllers/Auth/ForgotPasswordController.php
tests/Auth/AuthTest.php

index 404b5352dcc2b45537d4407a634171cee7a6c69e..23b9039b97028d5372a217d92e2635446a46d672 100644 (file)
@@ -70,6 +70,7 @@ return [
             'email'    => 'emails.password',
             'table'    => 'password_resets',
             'expire'   => 60,
+            'throttle' => 60,
         ],
     ],
 
index 3df0608f87ffad7f09754ce2f24e6d82694b716b..8eaee08a2b49985dbcfc299681f7be0577d48b7a 100644 (file)
@@ -56,7 +56,7 @@ class ForgotPasswordController extends Controller
             $this->logActivity(ActivityType::AUTH_PASSWORD_RESET, $request->get('email'));
         }
 
-        if ($response === Password::RESET_LINK_SENT || $response === Password::INVALID_USER) {
+        if (in_array($response, [Password::RESET_LINK_SENT, Password::INVALID_USER, Password::RESET_THROTTLED])) {
             $message = trans('auth.reset_password_sent', ['email' => $request->get('email')]);
             $this->showSuccessNotification($message);
 
index d037b57011fada64a1c1755ab9418b9ea03af828..f19011c46abe5d2e2a93eec83e58d7dd40678ce7 100644 (file)
@@ -282,6 +282,22 @@ class AuthTest extends TestCase
             ->assertElementContains('a', 'Sign up');
     }
 
+    public function test_reset_password_request_is_throttled()
+    {
+        $editor = $this->getEditor();
+        Notification::fake();
+        $this->get('/password/email');
+        $this->followingRedirects()->post('/password/email', [
+            'email' => $editor->email,
+        ]);
+
+        $resp = $this->followingRedirects()->post('/password/email', [
+            'email' => $editor->email,
+        ]);
+        Notification::assertTimesSent(1, ResetPassword::class);
+        $resp->assertSee('A password reset link will be sent to ' . $editor->email . ' if that email address is found in the system.');
+    }
+
     public function test_login_redirects_to_initially_requested_url_correctly()
     {
         config()->set('app.url', 'http://localhost');