Fix authentication lockout when doing multiple SFTP uploads; closes #2221

This commit is contained in:
Dane Everitt 2020-09-13 13:54:41 -07:00
parent 7b57d65edf
commit 79f616f791
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53

View file

@ -14,6 +14,7 @@ use Pterodactyl\Services\Servers\GetUserPermissionsService;
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
{
@ -71,11 +72,12 @@ class SftpAuthenticationController extends Controller
'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 */
@ -91,6 +93,8 @@ class SftpAuthenticationController extends Controller
$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.'
);