From 5ce75cf50f5c4ab277762ff3c7ebb66379ea320e Mon Sep 17 00:00:00 2001 From: Sky Mulley Date: Fri, 9 Oct 2026 12:49:59 +0100 Subject: [PATCH] fix bug introduced by security hardening that blocks mounts from being allocated onto server containers --- app/Models/Mount.php | 9 +++++++ app/Rules/NotInPathHierarchy.php | 14 +++++++--- app/Validation/MountRules.php | 5 ++-- .../Api/Admin/Mounts/MountControllerTest.php | 27 +++++++++++++++++++ 4 files changed, 50 insertions(+), 5 deletions(-) diff --git a/app/Models/Mount.php b/app/Models/Mount.php index 6d003ef2a..90c60558b 100644 --- a/app/Models/Mount.php +++ b/app/Models/Mount.php @@ -56,6 +56,15 @@ class Mount extends Model implements Identifiable '/srv/daemon-data', ]; + /** + * Source paths that cannot be mounted, nor anything beneath them. + * + * @var list + */ + public static array $protectedSourcePaths = [ + '/etc/pterodactyl', + ]; + /** * Blacklisted target paths. * diff --git a/app/Rules/NotInPathHierarchy.php b/app/Rules/NotInPathHierarchy.php index f477bcd84..5047b35a6 100644 --- a/app/Rules/NotInPathHierarchy.php +++ b/app/Rules/NotInPathHierarchy.php @@ -13,7 +13,7 @@ class NotInPathHierarchy implements ValidationRule /** * @param list $invalidPaths */ - public function __construct(protected array $invalidPaths) {} + public function __construct(protected array $invalidPaths, protected bool $includeDescendants = true) {} public function validate(string $attribute, mixed $value, Closure $fail): void { @@ -24,9 +24,17 @@ class NotInPathHierarchy implements ValidationRule $path = Mount::normalizePath($value); foreach ($this->invalidPaths as $blocked) { - $blocked = rtrim($blocked, '/'); + $blocked = Mount::normalizePath($blocked); - if ($path === $blocked || str_starts_with($path, $blocked.'/')) { + if ($path === $blocked) { + $fail($this->includeDescendants + ? "The {$attribute} path cannot be or reside within [{$blocked}]." + : "The {$attribute} path cannot be [{$blocked}]."); + + return; + } + + if ($this->includeDescendants && str_starts_with($path, $blocked.'/')) { $fail("The {$attribute} path cannot be or reside within [{$blocked}]."); return; diff --git a/app/Validation/MountRules.php b/app/Validation/MountRules.php index b960d8cff..56921962c 100644 --- a/app/Validation/MountRules.php +++ b/app/Validation/MountRules.php @@ -32,14 +32,15 @@ final class MountRules 'required', 'string', 'starts_with:/', - new NotInPathHierarchy(Mount::$invalidSourcePaths), + new NotInPathHierarchy(Mount::$protectedSourcePaths), + new NotInPathHierarchy(Mount::$invalidSourcePaths, includeDescendants: false), ], 'target' => [ 'required', 'string', 'starts_with:/', - new NotInPathHierarchy(Mount::$invalidTargetPaths), + new NotInPathHierarchy(Mount::$invalidTargetPaths, includeDescendants: false), ], 'read_only' => ['sometimes', 'boolean'], diff --git a/tests/Integration/Api/Admin/Mounts/MountControllerTest.php b/tests/Integration/Api/Admin/Mounts/MountControllerTest.php index a5b3e1d7b..43e661bce 100644 --- a/tests/Integration/Api/Admin/Mounts/MountControllerTest.php +++ b/tests/Integration/Api/Admin/Mounts/MountControllerTest.php @@ -72,6 +72,33 @@ test('non admin forbidden', function (string $method, string $routeName): void { $response = $this->{$method}(route($routeName, ['mount' => $mount->id])); $this->assertAccessDeniedJson($response); })->with('mountEndpointsDataProvider'); +test('mount paths within server volumes and the container directory are allowed', function (string $source, string $target): void { + $response = $this->postJson(route('api.admin.mounts.store'), ['name' => 'Volume Mount', 'source' => $source, 'target' => $target]); + $response->assertStatus(Response::HTTP_CREATED); + $this->assertDatabaseHas('mounts', ['name' => 'Volume Mount', 'source' => $source, 'target' => $target]); +})->with([ + ['/var/lib/pterodactyl/volumes/34eddb08-887e-4a6e-b0f1-e4e249b3181c', '/mnt/shared'], + ['/var/lib/pterodactyl/volumes/34eddb08-887e-4a6e-b0f1-e4e249b3181c/plugins', '/home/container/plugins'], + ['/srv/daemon-data/34eddb08-887e-4a6e-b0f1-e4e249b3181c', '/home/container/shared'], +]); +test('protected mount paths are rejected', function (string $field, string $path): void { + $payload = ['name' => 'Protected Mount', 'source' => '/mnt/source', 'target' => '/mnt/target']; + $payload[$field] = $path; + $response = $this->postJson(route('api.admin.mounts.store'), $payload); + $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY); + expect(collect($response->json('errors'))->firstWhere('meta.source_field', $field))->not->toBeNull(); +})->with([ + ['source', '/var/lib/pterodactyl/volumes'], + ['source', '/var/lib/pterodactyl/volumes/'], + ['source', '/var/lib/pterodactyl/volumes/abc/..'], + ['source', '/srv/daemon-data'], + ['source', '/etc/pterodactyl'], + ['source', '/etc/pterodactyl/config.yml'], + ['source', '/var/lib/pterodactyl/volumes/../../../../etc/pterodactyl'], + ['target', '/home/container'], + ['target', '/home/container/'], + ['target', '/home/container/plugins/..'], +]); test('invalid payloads return validation errors', function (): void { $response = $this->postJson(route('api.admin.mounts.store'), []); $response->assertStatus(Response::HTTP_UNPROCESSABLE_ENTITY);