Skip to content

Commit 412ac5e

Browse files
committed
Have the panel handle all of the authorization for both public key and password based attempts
1 parent e856dae commit 412ac5e

File tree

2 files changed

+4
-8
lines changed

2 files changed

+4
-8
lines changed

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ public function __construct(GetUserPermissionsService $permissions)
2828

2929
/**
3030
* Authenticate a set of credentials and return the associated server details
31-
* for a SFTP connection on the daemon.
31+
* for a SFTP connection on the daemon. This supports both public key and password
32+
* based credentials.
3233
*/
3334
public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
3435
{
@@ -44,9 +45,7 @@ public function __invoke(SftpAuthenticationFormRequest $request): JsonResponse
4445
$this->reject($request);
4546
}
4647
} else {
47-
// Start blocking requests when the user has no public keys in the first place —
48-
// don't let the user spam this endpoint.
49-
if ($user->sshKeys->isEmpty()) {
48+
if (!$user->sshKeys()->where('public_key', $request->input('password'))->exists()) {
5049
$this->reject($request);
5150
}
5251
}

app/Http/Requests/Api/Remote/SftpAuthenticationFormRequest.php

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
namespace Pterodactyl\Http\Requests\Api\Remote;
44

5-
use Illuminate\Validation\Rule;
65
use Illuminate\Foundation\Http\FormRequest;
76

87
class SftpAuthenticationFormRequest extends FormRequest
@@ -27,9 +26,7 @@ public function rules()
2726
return [
2827
'type' => ['nullable', 'in:password,public_key'],
2928
'username' => ['required', 'string'],
30-
'password' => [
31-
Rule::when(fn () => $this->input('type') !== 'public_key', ['required', 'string'], ['nullable']),
32-
],
29+
'password' => ['required', 'string'],
3330
];
3431
}
3532

0 commit comments

Comments
 (0)