Url encode username in sftp connection string (#1731)

This commit is contained in:
Boy132 2025-09-22 12:58:54 +02:00 committed by GitHub
parent e5c24fe8b6
commit bb40a5273f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 6 additions and 6 deletions

View File

@ -174,13 +174,13 @@ class Settings extends ServerFormPage
->url(function (Server $server) { ->url(function (Server $server) {
$fqdn = $server->node->daemon_sftp_alias ?? $server->node->fqdn; $fqdn = $server->node->daemon_sftp_alias ?? $server->node->fqdn;
return 'sftp://' . auth()->user()->username . '.' . $server->uuid_short . '@' . $fqdn . ':' . $server->node->daemon_sftp; return 'sftp://' . rawurlencode(auth()->user()->username) . '.' . $server->uuid_short . '@' . $fqdn . ':' . $server->node->daemon_sftp;
}), }),
) )
->formatStateUsing(function (Server $server) { ->formatStateUsing(function (Server $server) {
$fqdn = $server->node->daemon_sftp_alias ?? $server->node->fqdn; $fqdn = $server->node->daemon_sftp_alias ?? $server->node->fqdn;
return 'sftp://' . auth()->user()->username . '.' . $server->uuid_short . '@' . $fqdn . ':' . $server->node->daemon_sftp; return 'sftp://' . rawurlencode(auth()->user()->username) . '.' . $server->uuid_short . '@' . $fqdn . ':' . $server->node->daemon_sftp;
}), }),
TextInput::make('username') TextInput::make('username')
->label(trans('server/setting.server_info.sftp.username')) ->label(trans('server/setting.server_info.sftp.username'))
@ -191,7 +191,7 @@ class Settings extends ServerFormPage
TextEntry::make('password') TextEntry::make('password')
->label(trans('server/setting.server_info.sftp.password')) ->label(trans('server/setting.server_info.sftp.password'))
->columnSpan(1) ->columnSpan(1)
->label(trans('server/setting.server_info.sftp.password_body')), ->state(trans('server/setting.server_info.sftp.password_body')),
]), ]),
]), ]),
Section::make(trans('server/setting.reinstall.title')) Section::make(trans('server/setting.reinstall.title'))

View File

@ -99,7 +99,7 @@ class SftpAuthenticationController extends Controller
*/ */
protected function getUser(Request $request, string $username): User protected function getUser(Request $request, string $username): User
{ {
return User::query()->where('username', $username)->firstOr(function () use ($request) { return User::where('username', str($username)->lower()->trim())->firstOr(function () use ($request) {
$this->reject($request); $this->reject($request);
}); });
} }

View File

@ -219,14 +219,14 @@ class User extends Model implements AuthenticatableContract, AuthorizableContrac
public function username(): Attribute public function username(): Attribute
{ {
return Attribute::make( return Attribute::make(
set: fn (string $value) => mb_strtolower($value), set: fn (string $value) => str($value)->lower()->trim()->toString(),
); );
} }
public function email(): Attribute public function email(): Attribute
{ {
return Attribute::make( return Attribute::make(
set: fn (string $value) => mb_strtolower($value), set: fn (string $value) => str($value)->lower()->trim()->toString(),
); );
} }