Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Check locked out status before validation, not after.
James Cole7945066fde2d
diff --git a/app/Exceptions/Handler.php b/app/Exceptions/Handler.phpindex 33d11738aa..b09fbca8dd 100644--- a/app/Exceptions/Handler.php+++ b/app/Exceptions/Handler.php@@ -199,6 +199,13 @@ class Handler extends ExceptionHandlerreturn response()->view('errors.DatabaseException', ['exception' => $e, 'debug' => $isDebug], 500);}+ if ($e instanceof LockedOutException) {+ Log::debug('Return Firefly III error view.');+ $isDebug = config('app.debug');++ return response()->view('errors.FireflyException', ['exception' => $e, 'debug' => $isDebug], 429);+ }+if ($e instanceof FireflyException || $e instanceof ErrorException || $e instanceof OAuthServerException) {Log::debug('Return Firefly III error view.');@@ -207,6 +214,7 @@ class Handler extends ExceptionHandlerreturn response()->view('errors.FireflyException', ['exception' => $e, 'debug' => $isDebug], 500);}+Log::debug(sprintf('Error "%s" has no Firefly III treatment, parent will handle.', $e::class));Log::error($e->getMessage());diff --git a/app/Exceptions/LockedOutException.php b/app/Exceptions/LockedOutException.phpnew file mode 100644index 0000000000..dd932956a6--- /dev/null+++ b/app/Exceptions/LockedOutException.php@@ -0,0 +1,27 @@+<?php+/*+ * LockedOutException.php+ * Copyright (c) 2026 [email protected]+ *+ * This file is part of Firefly III (https://github.com/firefly-iii).+ *+ * This program is free software: you can redistribute it and/or modify+ * it under the terms of the GNU Affero General Public License as+ * published by the Free Software Foundation, either version 3 of the+ * License, or (at your option) any later version.+ *+ * This program is distributed in the hope that it will be useful,+ * but WITHOUT ANY WARRANTY; without even the implied warranty of+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the+ * GNU Affero General Public License for more details.+ *+ * You should have received a copy of the GNU Affero General Public License+ * along with this program. If not, see <https://www.gnu.org/licenses/>.+ */++namespace FireflyIII\Exceptions;++class LockedOutException extends FireflyException+{++}diff --git a/app/Http/Controllers/Auth/LoginController.php b/app/Http/Controllers/Auth/LoginController.phpindex 7aed9c32fd..c982bff0e1 100644--- a/app/Http/Controllers/Auth/LoginController.php+++ b/app/Http/Controllers/Auth/LoginController.php@@ -27,6 +27,8 @@ use Carbon\Carbon;use FireflyIII\Events\Security\System\UnknownUserTriedLogin;use FireflyIII\Events\Security\User\UserFailedLoginAttempt;use FireflyIII\Events\Security\User\UserSuccessfullyLoggedIn;+use FireflyIII\Exceptions\FireflyException;+use FireflyIII\Exceptions\LockedOutException;use FireflyIII\Http\Controllers\Controller;use FireflyIII\Providers\RouteServiceProvider;use FireflyIII\Repositories\User\UserRepositoryInterface;@@ -85,19 +87,11 @@ final class LoginController extends Controller*/public function login(Request $request): JsonResponse|RedirectResponse{- $username = $request->get($this->username());- Log::channel('audit')->info(sprintf('User is trying to login using "%s"', $username));+ Log::channel('audit')->info(sprintf('User is trying to login using "%s"', $request->input($this->username())));Log::debug('User is trying to login.');- try {- $this->validateLogin($request);- } catch (ValidationException) {- // basic validation exception.- // report the failed login to the user if the count is 2 or 5.- // TODO here be warning.- return redirect(route('login'))->withErrors([$this->username => trans('auth.failed')])->onlyInput($this->username);- }- Log::debug('Login data is present.');+ // first, check for too many login attempts:+ $this->incrementLoginAttempts($request);// Copied directly from AuthenticatesUsers, but with logging added:// If the class is using the ThrottlesLogins trait, we can automatically throttle@@ -107,8 +101,23 @@ final class LoginController extends ControllerLog::channel('audit')->warning(sprintf('Login for user "%s" was locked out.', $request->get($this->username())));Log::error(sprintf('Login for user "%s" was locked out.', $request->get($this->username())));$this->fireLockoutEvent($request);- $this->sendLockoutResponse($request);+ $seconds = $this->limiter()->availableIn($this->throttleKey($request));+ $message = (string) trans('auth.throttle', ['seconds' => $seconds, 'minutes' => ceil($seconds / 60),]);+ Log::error(sprintf('Will SLEEP for %d second(s).', $seconds));+ sleep($seconds);+ throw new LockedOutException($message);}++ try {+ $this->validateLogin($request);+ } catch (ValidationException) {+ // basic validation exception.+ // report the failed login to the user if the count is 2 or 5.+ // TODO here be warning.+ return redirect(route('login'))->withErrors([$this->username => trans('auth.failed')])->onlyInput($this->username);+ }+ Log::debug('Login data is present.');+// Copied directly from AuthenticatesUsers, but with logging added:if ($this->attemptLogin($request)) {Log::channel('audit')->info(sprintf('User "%s" has been logged in.', $request->get($this->username())));