Skip to content

Commit 79f616f

Browse files
committed
Fix authentication lockout when doing multiple SFTP uploads; closes pterodactyl#2221
1 parent 7b57d65 commit 79f616f

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

app/Http/Controllers/Api/Remote/SftpAuthenticationController.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
1515
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
1616
use Pterodactyl\Http\Requests\Api\Remote\SftpAuthenticationFormRequest;
17+
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;
1718

1819
class 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

Comments
 (0)