Improve email handling

This commit is contained in:
robert dennis
2026-06-28 17:52:34 -04:00
parent ea3b492dd5
commit c39a7be8f5
7 changed files with 162 additions and 67 deletions
@@ -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',
];
+2
View File
@@ -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;
}
+33
View File
@@ -0,0 +1,33 @@
<?php
namespace Pterodactyl\Rules;
use Illuminate\Contracts\Validation\Rule;
class UserEmail implements Rule
{
/**
* @param string $attribute
*/
public function passes($attribute, $value): bool
{
if (!is_string($value)) {
return true;
}
$local = explode('@', $value, 2)[0] ?? '';
$local = trim($local, '"');
return !str_starts_with($local, '-');
}
public function message(): string
{
return 'The :attribute must not start with a dash.';
}
public function __toString(): string
{
return 'p_user_email';
}
}
Generated
+74 -66
View File
@@ -5224,16 +5224,16 @@
},
{
"name": "symfony/deprecation-contracts",
"version": "v3.6.0",
"version": "v3.7.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/deprecation-contracts.git",
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62"
"reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/63afe740e99a13ba87ec199bb07bbdee937a5b62",
"reference": "63afe740e99a13ba87ec199bb07bbdee937a5b62",
"url": "https://api.github.com/repos/symfony/deprecation-contracts/zipball/f3202fa1b5097b0af062dc978b32ecf63404e31d",
"reference": "f3202fa1b5097b0af062dc978b32ecf63404e31d",
"shasum": ""
},
"require": {
@@ -5246,7 +5246,7 @@
"name": "symfony/contracts"
},
"branch-alias": {
"dev-main": "3.6-dev"
"dev-main": "3.7-dev"
}
},
"autoload": {
@@ -5271,7 +5271,7 @@
"description": "A generic function and convention to trigger deprecation notices",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.6.0"
"source": "https://github.com/symfony/deprecation-contracts/tree/v3.7.1"
},
"funding": [
{
@@ -5282,12 +5282,16 @@
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-09-25T14:21:43+00:00"
"time": "2026-06-05T06:23:12+00:00"
},
{
"name": "symfony/error-handler",
@@ -5373,16 +5377,16 @@
},
{
"name": "symfony/event-dispatcher",
"version": "v7.4.0",
"version": "v7.4.14",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher.git",
"reference": "9dddcddff1ef974ad87b3708e4b442dc38b2261d"
"reference": "51fe3d170227be8d1772214b82ae506e15ed78ff"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/9dddcddff1ef974ad87b3708e4b442dc38b2261d",
"reference": "9dddcddff1ef974ad87b3708e4b442dc38b2261d",
"url": "https://api.github.com/repos/symfony/event-dispatcher/zipball/51fe3d170227be8d1772214b82ae506e15ed78ff",
"reference": "51fe3d170227be8d1772214b82ae506e15ed78ff",
"shasum": ""
},
"require": {
@@ -5434,7 +5438,7 @@
"description": "Provides tools that allow your application components to communicate with each other by dispatching events and listening to them",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/event-dispatcher/tree/v7.4.0"
"source": "https://github.com/symfony/event-dispatcher/tree/v7.4.14"
},
"funding": [
{
@@ -5454,20 +5458,20 @@
"type": "tidelift"
}
],
"time": "2025-10-28T09:38:46+00:00"
"time": "2026-06-06T11:10:32+00:00"
},
{
"name": "symfony/event-dispatcher-contracts",
"version": "v3.6.0",
"version": "v3.7.1",
"source": {
"type": "git",
"url": "https://github.com/symfony/event-dispatcher-contracts.git",
"reference": "59eb412e93815df44f05f342958efa9f46b1e586"
"reference": "c7de7a00ffb67842132da02ea92988a39ccd9f4e"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/59eb412e93815df44f05f342958efa9f46b1e586",
"reference": "59eb412e93815df44f05f342958efa9f46b1e586",
"url": "https://api.github.com/repos/symfony/event-dispatcher-contracts/zipball/c7de7a00ffb67842132da02ea92988a39ccd9f4e",
"reference": "c7de7a00ffb67842132da02ea92988a39ccd9f4e",
"shasum": ""
},
"require": {
@@ -5481,7 +5485,7 @@
"name": "symfony/contracts"
},
"branch-alias": {
"dev-main": "3.6-dev"
"dev-main": "3.7-dev"
}
},
"autoload": {
@@ -5514,7 +5518,7 @@
"standards"
],
"support": {
"source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.6.0"
"source": "https://github.com/symfony/event-dispatcher-contracts/tree/v3.7.1"
},
"funding": [
{
@@ -5525,12 +5529,16 @@
"url": "https://github.com/fabpot",
"type": "github"
},
{
"url": "https://github.com/nicolas-grekas",
"type": "github"
},
{
"url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
"type": "tidelift"
}
],
"time": "2024-09-25T14:21:43+00:00"
"time": "2026-06-05T06:23:12+00:00"
},
{
"name": "symfony/filesystem",
@@ -6052,16 +6060,16 @@
},
{
"name": "symfony/mailer",
"version": "v7.4.0",
"version": "v7.4.14",
"source": {
"type": "git",
"url": "https://github.com/symfony/mailer.git",
"reference": "a3d9eea8cfa467ece41f0f54ba28185d74bd53fd"
"reference": "f88ce03ae73e3edb5c176ce1f337709996e88495"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/mailer/zipball/a3d9eea8cfa467ece41f0f54ba28185d74bd53fd",
"reference": "a3d9eea8cfa467ece41f0f54ba28185d74bd53fd",
"url": "https://api.github.com/repos/symfony/mailer/zipball/f88ce03ae73e3edb5c176ce1f337709996e88495",
"reference": "f88ce03ae73e3edb5c176ce1f337709996e88495",
"shasum": ""
},
"require": {
@@ -6112,7 +6120,7 @@
"description": "Helps sending emails",
"homepage": "https://symfony.com",
"support": {
"source": "https://github.com/symfony/mailer/tree/v7.4.0"
"source": "https://github.com/symfony/mailer/tree/v7.4.14"
},
"funding": [
{
@@ -6132,7 +6140,7 @@
"type": "tidelift"
}
],
"time": "2025-11-21T15:26:00+00:00"
"time": "2026-06-13T08:51:35+00:00"
},
{
"name": "symfony/mailgun-mailer",
@@ -6209,16 +6217,16 @@
},
{
"name": "symfony/mime",
"version": "v7.4.0",
"version": "v7.4.13",
"source": {
"type": "git",
"url": "https://github.com/symfony/mime.git",
"reference": "bdb02729471be5d047a3ac4a69068748f1a6be7a"
"reference": "a845722765c4f6b2ce88beaf4f4479975b186770"
},
"dist": {
"type": "zip",
"url": "https://api.github.com/repos/symfony/mime/zipball/bdb02729471be5d047a3ac4a69068748f1a6be7a",
"reference": "bdb02729471be5d047a3ac4a69068748f1a6be7a",
"url": "https://api.github.com/repos/symfony/mime/zipball/a845722765c4f6b2ce88beaf4f4479975b186770",
"reference": "a845722765c4f6b2ce88beaf4f4479975b186770",
"shasum": ""
},
"require": {
@@ -6229,15 +6237,15 @@
},
"conflict": {
"egulias/email-validator": "~3.0.0",
"phpdocumentor/reflection-docblock": "<3.2.2",
"phpdocumentor/type-resolver": "<1.4.0",
"phpdocumentor/reflection-docblock": "<5.2|>=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",
@@ -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.
*/
@@ -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']);
}
/**
@@ -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.