Fix 2 SFTP Lockout Ratelimit Bugs (#7257)

Fixes two SFTP lockout bugs:

- `ad374661f` moved the server lookup after the password check, so fake
server identifiers bypassed the rate limit.
- `24f340c9a` keyed the lockout on server + Wings IP, so anyone could
lock every user out of a server.

Unknown servers are now rejected before any credential check, and the
lockout is keyed on the normalised username + resolved server UUID.
This commit is contained in:
Joshua Piper
2026-10-06 22:46:46 -04:00
committed by GitHub
parent 4a6377c675
commit 66ce0f2a16
2 changed files with 123 additions and 15 deletions
@@ -9,6 +9,7 @@ use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Str;
use phpseclib3\Crypt\PublicKeyLoader;
use phpseclib3\Exception\NoKeyLoadedException;
use Pterodactyl\Enum\Permissions;
@@ -31,6 +32,9 @@ class SftpAuthenticationController extends Controller
{
use ThrottlesLogins;
/** The server resolved for the current request, used to key the lockout. */
private ?Server $throttleServer = null;
/**
* Authenticate a set of credentials and return the associated server details
* for a SFTP connection on the daemon. This supports both public key and password
@@ -41,6 +45,8 @@ class SftpAuthenticationController extends Controller
$connection = $this->parseUsername(JsonValueGuard::string($request->validated('username')));
throw_if(empty($connection['server']), BadRequestHttpException::class, 'No valid server identifier was included in the request.');
$server = $this->getServer($request, $connection['server']);
if ($this->hasTooManyLoginAttempts($request)) {
$seconds = RateLimiter::availableIn($this->throttleKey($request));
@@ -84,8 +90,6 @@ class SftpAuthenticationController extends Controller
}
}
$server = $this->getServer($request, $connection['server']);
$this->validateSftpAccess($user, $server, $permissions);
return new JsonResponse([
@@ -106,7 +110,13 @@ class SftpAuthenticationController extends Controller
->where('node_id', RemoteRequestNode::get($request)->id)
->first();
return $server ?? $this->reject($request);
if ($server === null) {
$this->reject($request, false);
}
$this->throttleServer = $server;
return $server;
}
/**
@@ -127,7 +137,7 @@ class SftpAuthenticationController extends Controller
}
/**
* Rejects the request and increments the login attempts.
* Rejects the request, optionally incrementing the login attempts.
*/
protected function reject(Request $request, bool $increment = true): never
{
@@ -157,13 +167,13 @@ class SftpAuthenticationController extends Controller
}
/**
* Get the throttle key for the given request.
* Get the throttle key for the given request: normalised requested username plus server UUID
*/
protected function throttleKey(Request $request): string
{
$raw = JsonValueGuard::nullableString($request->input('username', '')) ?? '';
$username = explode('.', strrev($raw));
$username = Str::transliterate(mb_strtolower(mb_rtrim($this->parseUsername($raw)['username'], ' ')));
return mb_strtolower(strrev($username[0] ?? '').'|'.$request->ip()); // @phpstan-ignore nullCoalesce.offset
return $username.'|'.($this->throttleServer->uuid ?? '');
}
}