Skip to content

Commit 7ebe04f

Browse files
committed
Don't allow blank passwords on the password change endpoint; closes pterodactyl#2750
1 parent 16f49f8 commit 7ebe04f

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

app/Http/Requests/Api/Client/Account/UpdatePasswordRequest.php

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

33
namespace Pterodactyl\Http\Requests\Api\Client\Account;
44

5-
use Pterodactyl\Models\User;
65
use Pterodactyl\Http\Requests\Api\Client\ClientApiRequest;
76
use Pterodactyl\Exceptions\Http\Base\InvalidPasswordProvidedException;
87

@@ -32,8 +31,8 @@ public function authorize(): bool
3231
*/
3332
public function rules(): array
3433
{
35-
$rules = User::getRulesForUpdate($this->user());
36-
37-
return ['password' => array_merge($rules['password'], ['confirmed'])];
34+
return [
35+
'password' => ['required', 'string', 'confirmed', 'min:8'],
36+
];
3837
}
3938
}

tests/Integration/Api/Client/AccountControllerTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,29 @@ public function testPasswordIsNotUpdatedIfCurrentPasswordIsInvalid()
140140
$response->assertJsonPath('errors.0.detail', 'The password provided was invalid for this account.');
141141
}
142142

143+
/**
144+
* Test that a validation error is returned to the user if no password is provided or if
145+
* the password is below the minimum password length.
146+
*/
147+
public function testErrorIsReturnedForInvalidRequestData()
148+
{
149+
$user = factory(User::class)->create();
150+
151+
$this->actingAs($user)->putJson('/api/client/account/password', [
152+
'current_password' => 'password',
153+
])
154+
->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY)
155+
->assertJsonPath('errors.0.meta.rule', 'required');
156+
157+
$this->actingAs($user)->putJson('/api/client/account/password', [
158+
'current_password' => 'password',
159+
'password' => 'pass',
160+
'password_confirmation' => 'pass',
161+
])
162+
->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY)
163+
->assertJsonPath('errors.0.meta.rule', 'min');
164+
}
165+
143166
/**
144167
* Test that a validation error is returned if the password passed in the request
145168
* does not have a confirmation, or the confirmation is not the same as the password.

0 commit comments

Comments
 (0)