Skip to content

Commit

Permalink
Fix authentication lockout when doing multiple SFTP uploads; closes #…
Browse files Browse the repository at this point in the history
  • Loading branch information
DaneEveritt committed Sep 13, 2020
1 parent 7b57d65 commit 79f616f
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions app/Http/Controllers/Api/Remote/SftpAuthenticationController.php
Expand Up @@ -14,6 +14,7 @@
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Symfony\Component\HttpKernel\Exception\BadRequestHttpException;
use Pterodactyl\Http\Requests\Api\Remote\SftpAuthenticationFormRequest;
use Symfony\Component\HttpKernel\Exception\TooManyRequestsHttpException;

class SftpAuthenticationController extends Controller
{
Expand Down Expand Up @@ -71,11 +72,12 @@ public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
'server' => strrev(array_get($parts, 0)),
];

$this->incrementLoginAttempts($request);
if ($this->hasTooManyLoginAttempts($request)) {
return JsonResponse::create([
'error' => 'Too many logins attempted too quickly.',
], JsonResponse::HTTP_TOO_MANY_REQUESTS);
$seconds = $this->limiter()->availableIn($this->throttleKey($request));

throw new TooManyRequestsHttpException(
$seconds, "Too many login attempts for this account, please try again in {$seconds} seconds."
);
}

/** @var \Pterodactyl\Models\Node $node */
Expand All @@ -91,6 +93,8 @@ public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse

$server = $this->serverRepository->getByUuid($connection['server'] ?? '');
if (! password_verify($request->input('password'), $user->password) || $server->node_id !== $node->id) {
$this->incrementLoginAttempts($request);

throw new HttpForbiddenException(
'Authorization credentials were not correct, please try again.'
);
Expand Down

0 comments on commit 79f616f

Please sign in to comment.