From c39a7be8f55a4537a4eaa4a134be6a3b975b14ec Mon Sep 17 00:00:00 2001 From: robert dennis <31261583+robertdrakedennis@users.noreply.github.com> Date: Sun, 28 Jun 2026 17:52:34 -0400 Subject: [PATCH] Improve email handling --- .../Servers/Subusers/StoreSubuserRequest.php | 3 +- app/Models/User.php | 2 + app/Rules/UserEmail.php | 33 +++++ composer.lock | 140 +++++++++--------- .../Application/Users/UserControllerTest.php | 28 ++++ .../Api/Client/AccountControllerTest.php | 8 + .../Subuser/CreateServerSubuserTest.php | 15 ++ 7 files changed, 162 insertions(+), 67 deletions(-) create mode 100644 app/Rules/UserEmail.php diff --git a/app/Http/Requests/Api/Client/Servers/Subusers/StoreSubuserRequest.php b/app/Http/Requests/Api/Client/Servers/Subusers/StoreSubuserRequest.php index 28accf20d..923c72001 100644 --- a/app/Http/Requests/Api/Client/Servers/Subusers/StoreSubuserRequest.php +++ b/app/Http/Requests/Api/Client/Servers/Subusers/StoreSubuserRequest.php @@ -2,6 +2,7 @@ namespace Pterodactyl\Http\Requests\Api\Client\Servers\Subusers; +use Pterodactyl\Rules\UserEmail; use Pterodactyl\Models\Permission; class StoreSubuserRequest extends SubuserRequest @@ -14,7 +15,7 @@ class StoreSubuserRequest extends SubuserRequest public function rules(): array { return [ - 'email' => 'required|email:strict|between:1,191', + 'email' => ['required', 'email:strict', 'between:1,191', new UserEmail()], 'permissions' => 'required|array', 'permissions.*' => 'string', ]; diff --git a/app/Models/User.php b/app/Models/User.php index e0de1d425..c2dad8855 100644 --- a/app/Models/User.php +++ b/app/Models/User.php @@ -3,6 +3,7 @@ namespace Pterodactyl\Models; use Pterodactyl\Rules\Username; +use Pterodactyl\Rules\UserEmail; use Pterodactyl\Facades\Activity; use Illuminate\Support\Collection; use Illuminate\Validation\Rules\In; @@ -189,6 +190,7 @@ class User extends Model implements $rules['language'][] = new In(array_keys((new self())->getAvailableLanguages())); $rules['username'][] = new Username(); + $rules['email'][] = new UserEmail(); return $rules; } diff --git a/app/Rules/UserEmail.php b/app/Rules/UserEmail.php new file mode 100644 index 000000000..8fcd29d67 --- /dev/null +++ b/app/Rules/UserEmail.php @@ -0,0 +1,33 @@ +=7", + "phpdocumentor/type-resolver": "<1.5.1", "symfony/mailer": "<6.4", "symfony/serializer": "<6.4.3|>7.0,<7.0.3" }, "require-dev": { "egulias/email-validator": "^2.1.10|^3.1|^4", "league/html-to-markdown": "^5.0", - "phpdocumentor/reflection-docblock": "^3.0|^4.0|^5.0", + "phpdocumentor/reflection-docblock": "^5.2|^6.0", "symfony/dependency-injection": "^6.4|^7.0|^8.0", "symfony/process": "^6.4|^7.0|^8.0", "symfony/property-access": "^6.4|^7.0|^8.0", @@ -6274,7 +6282,7 @@ "mime-type" ], "support": { - "source": "https://github.com/symfony/mime/tree/v7.4.0" + "source": "https://github.com/symfony/mime/tree/v7.4.13" }, "funding": [ { @@ -6294,7 +6302,7 @@ "type": "tidelift" } ], - "time": "2025-11-16T10:14:42+00:00" + "time": "2026-05-23T16:22:37+00:00" }, { "name": "symfony/polyfill-ctype", @@ -6463,16 +6471,16 @@ }, { "name": "symfony/polyfill-intl-idn", - "version": "v1.33.0", + "version": "v1.38.1", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-idn.git", - "reference": "9614ac4d8061dc257ecc64cba1b140873dce8ad3" + "reference": "dc21118016c039a66235cf93d96b435ffb282412" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/9614ac4d8061dc257ecc64cba1b140873dce8ad3", - "reference": "9614ac4d8061dc257ecc64cba1b140873dce8ad3", + "url": "https://api.github.com/repos/symfony/polyfill-intl-idn/zipball/dc21118016c039a66235cf93d96b435ffb282412", + "reference": "dc21118016c039a66235cf93d96b435ffb282412", "shasum": "" }, "require": { @@ -6526,7 +6534,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.33.0" + "source": "https://github.com/symfony/polyfill-intl-idn/tree/v1.38.1" }, "funding": [ { @@ -6546,20 +6554,20 @@ "type": "tidelift" } ], - "time": "2024-09-10T14:38:51+00:00" + "time": "2026-05-25T15:22:23+00:00" }, { "name": "symfony/polyfill-intl-normalizer", - "version": "v1.33.0", + "version": "v1.38.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-intl-normalizer.git", - "reference": "3833d7255cc303546435cb650316bff708a1c75c" + "reference": "2d446c214bdbe5b71bde5011b060a05fece3ae6b" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/3833d7255cc303546435cb650316bff708a1c75c", - "reference": "3833d7255cc303546435cb650316bff708a1c75c", + "url": "https://api.github.com/repos/symfony/polyfill-intl-normalizer/zipball/2d446c214bdbe5b71bde5011b060a05fece3ae6b", + "reference": "2d446c214bdbe5b71bde5011b060a05fece3ae6b", "shasum": "" }, "require": { @@ -6611,7 +6619,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.33.0" + "source": "https://github.com/symfony/polyfill-intl-normalizer/tree/v1.38.0" }, "funding": [ { @@ -6631,20 +6639,20 @@ "type": "tidelift" } ], - "time": "2024-09-09T11:45:10+00:00" + "time": "2026-05-25T13:48:31+00:00" }, { "name": "symfony/polyfill-mbstring", - "version": "v1.33.0", + "version": "v1.38.2", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-mbstring.git", - "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493" + "reference": "d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/6d857f4d76bd4b343eac26d6b539585d2bc56493", - "reference": "6d857f4d76bd4b343eac26d6b539585d2bc56493", + "url": "https://api.github.com/repos/symfony/polyfill-mbstring/zipball/d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6", + "reference": "d3d318bad5e7a1bfbd026009c8bfb8d8f99ae6b6", "shasum": "" }, "require": { @@ -6696,7 +6704,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.33.0" + "source": "https://github.com/symfony/polyfill-mbstring/tree/v1.38.2" }, "funding": [ { @@ -6716,20 +6724,20 @@ "type": "tidelift" } ], - "time": "2024-12-23T08:48:59+00:00" + "time": "2026-05-27T06:59:30+00:00" }, { "name": "symfony/polyfill-php80", - "version": "v1.33.0", + "version": "v1.37.0", "source": { "type": "git", "url": "https://github.com/symfony/polyfill-php80.git", - "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608" + "reference": "dfb55726c3a76ea3b6459fcfda1ec2d80a682411" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/0cc9dd0f17f61d8131e7df6b84bd344899fe2608", - "reference": "0cc9dd0f17f61d8131e7df6b84bd344899fe2608", + "url": "https://api.github.com/repos/symfony/polyfill-php80/zipball/dfb55726c3a76ea3b6459fcfda1ec2d80a682411", + "reference": "dfb55726c3a76ea3b6459fcfda1ec2d80a682411", "shasum": "" }, "require": { @@ -6780,7 +6788,7 @@ "shim" ], "support": { - "source": "https://github.com/symfony/polyfill-php80/tree/v1.33.0" + "source": "https://github.com/symfony/polyfill-php80/tree/v1.37.0" }, "funding": [ { @@ -6800,7 +6808,7 @@ "type": "tidelift" } ], - "time": "2025-01-02T08:10:11+00:00" + "time": "2026-04-10T16:19:22+00:00" }, { "name": "symfony/polyfill-php83", @@ -7271,16 +7279,16 @@ }, { "name": "symfony/service-contracts", - "version": "v3.6.1", + "version": "v3.7.1", "source": { "type": "git", "url": "https://github.com/symfony/service-contracts.git", - "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43" + "reference": "c0a284bab1ed8aa0417e3d69250ab437739563a0" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/symfony/service-contracts/zipball/45112560a3ba2d715666a509a0bc9521d10b6c43", - "reference": "45112560a3ba2d715666a509a0bc9521d10b6c43", + "url": "https://api.github.com/repos/symfony/service-contracts/zipball/c0a284bab1ed8aa0417e3d69250ab437739563a0", + "reference": "c0a284bab1ed8aa0417e3d69250ab437739563a0", "shasum": "" }, "require": { @@ -7298,7 +7306,7 @@ "name": "symfony/contracts" }, "branch-alias": { - "dev-main": "3.6-dev" + "dev-main": "3.7-dev" } }, "autoload": { @@ -7334,7 +7342,7 @@ "standards" ], "support": { - "source": "https://github.com/symfony/service-contracts/tree/v3.6.1" + "source": "https://github.com/symfony/service-contracts/tree/v3.7.1" }, "funding": [ { @@ -7354,7 +7362,7 @@ "type": "tidelift" } ], - "time": "2025-07-15T11:30:57+00:00" + "time": "2026-06-16T09:55:08+00:00" }, { "name": "symfony/string", diff --git a/tests/Integration/Api/Application/Users/UserControllerTest.php b/tests/Integration/Api/Application/Users/UserControllerTest.php index 7c70bb10b..c819076ba 100644 --- a/tests/Integration/Api/Application/Users/UserControllerTest.php +++ b/tests/Integration/Api/Application/Users/UserControllerTest.php @@ -235,6 +235,19 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase $this->assertActivityFor('user:user.create', $this->getApiUser(), $user); } + public function testCreateUserRejectsDashPrefixedEmail() + { + $response = $this->postJson('/api/application/users', [ + 'username' => 'dashuser', + 'email' => '-x@example.com', + 'first_name' => 'Test', + 'last_name' => 'User', + ]); + + $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); + $this->assertDatabaseMissing('users', ['email' => '-x@example.com']); + } + /** * Test that a user can be updated. */ @@ -264,6 +277,21 @@ class UserControllerTest extends ApplicationApiIntegrationTestCase ]); } + public function testUpdateUserRejectsDashPrefixedEmail() + { + $user = User::factory()->create(); + + $response = $this->patchJson('/api/application/users/' . $user->id, [ + 'username' => $user->username, + 'email' => '-x@example.com', + 'first_name' => $user->name_first, + 'last_name' => $user->name_last, + ]); + + $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); + $this->assertDatabaseMissing('users', ['id' => $user->id, 'email' => '-x@example.com']); + } + /** * Test that a user can be deleted from the database. */ diff --git a/tests/Integration/Api/Client/AccountControllerTest.php b/tests/Integration/Api/Client/AccountControllerTest.php index b941c92a9..b2e6204ed 100644 --- a/tests/Integration/Api/Client/AccountControllerTest.php +++ b/tests/Integration/Api/Client/AccountControllerTest.php @@ -150,6 +150,14 @@ class AccountControllerTest extends ClientApiIntegrationTestCase $response->assertJsonPath('errors.0.detail', 'The email must be a valid email address.'); $response->assertJsonPath('errors.0.meta.source_field', 'email'); + $response = $this->actingAs($user)->putJson('/api/client/account/email', [ + 'email' => '-x@example.com', + 'password' => 'password', + ]); + + $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); + $response->assertJsonPath('errors.0.meta.source_field', 'email'); + $this->assertDatabaseMissing('users', ['id' => $user->id, 'email' => '-x@example.com']); } /** diff --git a/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php b/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php index 547f8b864..a249f2327 100644 --- a/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php +++ b/tests/Integration/Api/Client/Server/Subuser/CreateServerSubuserTest.php @@ -149,6 +149,21 @@ class CreateServerSubuserTest extends ClientApiIntegrationTestCase $response->assertJsonPath('errors.0.meta.source_field', 'email'); } + public function testSubuserWithDashPrefixedEmailCannotBeCreated() + { + [$user, $server] = $this->generateTestAccount(); + + $response = $this->actingAs($user)->postJson($this->link($server) . '/users', [ + 'email' => '-x@example.com', + 'permissions' => [ + Permission::ACTION_USER_CREATE, + ], + ]); + + $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); + $this->assertDatabaseMissing('users', ['email' => '-x@example.com']); + } + /** * Test that creating a subuser when there is already an account with that email runs * as expected and does not create a new account.