1414use Symfony \Component \HttpKernel \Exception \NotFoundHttpException ;
1515use Symfony \Component \HttpKernel \Exception \BadRequestHttpException ;
1616use Pterodactyl \Http \Requests \Api \Remote \SftpAuthenticationFormRequest ;
17+ use Symfony \Component \HttpKernel \Exception \TooManyRequestsHttpException ;
1718
1819class SftpAuthenticationController extends Controller
1920{
@@ -71,11 +72,12 @@ public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
7172 'server ' => strrev (array_get ($ parts , 0 )),
7273 ];
7374
74- $ this ->incrementLoginAttempts ($ request );
7575 if ($ this ->hasTooManyLoginAttempts ($ request )) {
76- return JsonResponse::create ([
77- 'error ' => 'Too many logins attempted too quickly. ' ,
78- ], JsonResponse::HTTP_TOO_MANY_REQUESTS );
76+ $ seconds = $ this ->limiter ()->availableIn ($ this ->throttleKey ($ request ));
77+
78+ throw new TooManyRequestsHttpException (
79+ $ seconds , "Too many login attempts for this account, please try again in {$ seconds } seconds. "
80+ );
7981 }
8082
8183 /** @var \Pterodactyl\Models\Node $node */
@@ -91,6 +93,8 @@ public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
9193
9294 $ server = $ this ->serverRepository ->getByUuid ($ connection ['server ' ] ?? '' );
9395 if (! password_verify ($ request ->input ('password ' ), $ user ->password ) || $ server ->node_id !== $ node ->id ) {
96+ $ this ->incrementLoginAttempts ($ request );
97+
9498 throw new HttpForbiddenException (
9599 'Authorization credentials were not correct, please try again. '
96100 );
0 commit comments