Files
pterodactyl-panel/app/Http/Requests/Api/Application/Users/StoreUserRequest.php
T
subway 8e07ac97ab Fix a few API authorization gaps (#7273)
## Fixes
- An application key with only `users` write could create a root admin
or change an admin's password. Touching root admins now needs a key with
write on everything.
- An admin's account key could read node config (including the Wings
token) and create deploy tokens. Those admin endpoints now need a panel
session, and the application config endpoint no longer accepts account
keys. `wings configure` with an application key still works.

The email enumeration issue I originally had here is already covered by
#7259, so I dropped it.

Added tests for each. Full test suite, phpstan and pint pass. Checked
the node config page and auto-deploy in the admin UI still work.
2026-10-12 05:42:35 -04:00

88 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace Pterodactyl\Http\Requests\Api\Application\Users;
use Illuminate\Database\Eloquent\Model;
use Pterodactyl\Actions\Users\CreateUser;
use Pterodactyl\Http\Requests\Api\Application\ApplicationApiRequest;
use Pterodactyl\Http\Requests\Concerns\ValidatesExtensionFields;
use Pterodactyl\Models\User;
use Pterodactyl\Services\Acl\Api\AdminAcl;
class StoreUserRequest extends ApplicationApiRequest
{
use ValidatesExtensionFields {
actionInput as private inputWithExtensions;
}
protected ?string $resource = AdminAcl::RESOURCE_USERS;
protected int $permission = AdminAcl::WRITE;
public function authorize(): bool
{
return parent::authorize() && (! $this->boolean('root_admin') || $this->canManageAdministrators());
}
/**
* Return the validation rules for this request.
*
* @param NormalizedValidationRules|null $rules
* @return ValidationRules
*/
public function rules(?array $rules = null): array
{
$rules ??= CreateUser::rules();
return [
'external_id' => $rules['external_id'],
'email' => $rules['email'],
'username' => $rules['username'],
'password' => $rules['password'],
'language' => $rules['language'],
'root_admin' => $rules['root_admin'],
'first_name' => $rules['name_first'],
'last_name' => $rules['name_last'],
];
}
/**
* The validated input under the action's field names: first_name and last_name are
* its name_first and name_last.
*
* @return array<string, mixed>
*/
public function actionInput(): array
{
$input = $this->inputWithExtensions();
$input['name_first'] = $input['first_name'] ?? null;
$input['name_last'] = $input['last_name'] ?? null;
unset($input['first_name'], $input['last_name']);
return $input;
}
/**
* Rename some fields to be more user friendly.
*/
public function attributes(): array
{
return [
'external_id' => 'Third Party Identifier',
'name_first' => 'First Name',
'name_last' => 'Last Name',
'root_admin' => 'Root Administrator Status',
];
}
/**
* {@inheritdoc}
*/
protected function extensionFieldsModel(): Model|string
{
return User::class;
}
}