An open-source, self-hostable PaaS alternative to Vercel, Heroku & Netlify that lets you easily deploy static sites, databases, full-stack applications and 360+ one-click services on your own servers.
PHP coolifydatabasesdeploymentdockerdocker-composeinertiajslaravelmariadbmysqlnextjsnodejsphppostgresredisself-hostedself-hostingserverstatic-sitesveltesvelte5
refactor: consolidate file path validation patterns and support scoped packages
Andras Bacsai01031fc5f3d2
diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.phpindex c80d31ab3e..b51d04fca5 100644--- a/app/Jobs/ApplicationDeploymentJob.php+++ b/app/Jobs/ApplicationDeploymentJob.php@@ -3929,7 +3929,7 @@ COPY ./nginx.conf /etc/nginx/conf.d/default.conf");private function validatePathField(string $value, string $fieldName): string{- if (! preg_match('/^\/[a-zA-Z0-9._\-\/]+$/', $value)) {+ if (! preg_match(\App\Support\ValidationPatterns::FILE_PATH_PATTERN, $value)) {throw new \RuntimeException("Invalid {$fieldName}: contains forbidden characters.");}if (str_contains($value, '..')) {diff --git a/app/Livewire/Project/Application/General.php b/app/Livewire/Project/Application/General.phpindex 747536bcf9..b3fe998064 100644--- a/app/Livewire/Project/Application/General.php+++ b/app/Livewire/Project/Application/General.php@@ -73,7 +73,7 @@ class General extends Component#[Validate(['string', 'nullable'])]public ?string $dockerfile = null;- #[Validate(['string', 'nullable', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'])]+ #[Validate(['string', 'nullable', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/~@+]+$/'])]public ?string $dockerfileLocation = null;#[Validate(['string', 'nullable'])]@@ -85,7 +85,7 @@ class General extends Component#[Validate(['string', 'nullable'])]public ?string $dockerRegistryImageTag = null;- #[Validate(['string', 'nullable', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'])]+ #[Validate(['string', 'nullable', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/~@+]+$/'])]public ?string $dockerComposeLocation = null;#[Validate(['string', 'nullable'])]@@ -198,8 +198,8 @@ class General extends Component'dockerfile' => 'nullable','dockerRegistryImageName' => 'nullable','dockerRegistryImageTag' => 'nullable',- 'dockerfileLocation' => ['nullable', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],- 'dockerComposeLocation' => ['nullable', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],+ 'dockerfileLocation' => ['nullable', 'regex:'.ValidationPatterns::FILE_PATH_PATTERN],+ 'dockerComposeLocation' => ['nullable', 'regex:'.ValidationPatterns::FILE_PATH_PATTERN],'dockerCompose' => 'nullable','dockerComposeRaw' => 'nullable','dockerfileTargetBuild' => 'nullable',@@ -231,8 +231,8 @@ class General extends Componentreturn array_merge(ValidationPatterns::combinedMessages(),[- 'dockerfileLocation.regex' => 'The Dockerfile location must be a valid path starting with / and containing only alphanumeric characters, dots, hyphens, and slashes.',- 'dockerComposeLocation.regex' => 'The Docker Compose location must be a valid path starting with / and containing only alphanumeric characters, dots, hyphens, and slashes.',+ ...ValidationPatterns::filePathMessages('dockerfileLocation', 'Dockerfile'),+ ...ValidationPatterns::filePathMessages('dockerComposeLocation', 'Docker Compose'),'name.required' => 'The Name field is required.','gitRepository.required' => 'The Git Repository field is required.','gitBranch.required' => 'The Git Branch field is required.',diff --git a/app/Livewire/Project/New/GithubPrivateRepository.php b/app/Livewire/Project/New/GithubPrivateRepository.phpindex 1bb276b89c..61ae0e1511 100644--- a/app/Livewire/Project/New/GithubPrivateRepository.php+++ b/app/Livewire/Project/New/GithubPrivateRepository.php@@ -168,7 +168,7 @@ class GithubPrivateRepository extends Component'selected_repository_owner' => 'required|string|regex:/^[a-zA-Z0-9\-_]+$/','selected_repository_repo' => 'required|string|regex:/^[a-zA-Z0-9\-_\.]+$/','selected_branch_name' => ['required', 'string', new ValidGitBranch],- 'docker_compose_location' => ['nullable', 'string', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],+ 'docker_compose_location' => \App\Support\ValidationPatterns::filePathRules(),]);if ($validator->fails()) {diff --git a/app/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php b/app/Livewire/Project/New/GithubPrivateRepositoryDeployKey.phpindex f52c01e916..b9af20c760 100644--- a/app/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php+++ b/app/Livewire/Project/New/GithubPrivateRepositoryDeployKey.php@@ -64,7 +64,7 @@ class GithubPrivateRepositoryDeployKey extends Component'is_static' => 'required|boolean','publish_directory' => 'nullable|string','build_pack' => 'required|string',- 'docker_compose_location' => ['nullable', 'string', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],+ 'docker_compose_location' => \App\Support\ValidationPatterns::filePathRules(),];protected function rules()@@ -76,7 +76,7 @@ class GithubPrivateRepositoryDeployKey extends Component'is_static' => 'required|boolean','publish_directory' => 'nullable|string','build_pack' => 'required|string',- 'docker_compose_location' => ['nullable', 'string', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],+ 'docker_compose_location' => \App\Support\ValidationPatterns::filePathRules(),];}diff --git a/app/Livewire/Project/New/PublicGitRepository.php b/app/Livewire/Project/New/PublicGitRepository.phpindex a08c448dd5..cc2510a666 100644--- a/app/Livewire/Project/New/PublicGitRepository.php+++ b/app/Livewire/Project/New/PublicGitRepository.php@@ -70,7 +70,7 @@ class PublicGitRepository extends Component'publish_directory' => 'nullable|string','build_pack' => 'required|string','base_directory' => 'nullable|string',- 'docker_compose_location' => ['nullable', 'string', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],+ 'docker_compose_location' => \App\Support\ValidationPatterns::filePathRules(),];protected function rules()@@ -82,7 +82,7 @@ class PublicGitRepository extends Component'publish_directory' => 'nullable|string','build_pack' => 'required|string','base_directory' => 'nullable|string',- 'docker_compose_location' => ['nullable', 'string', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],+ 'docker_compose_location' => \App\Support\ValidationPatterns::filePathRules(),'git_branch' => ['required', 'string', new ValidGitBranch],];}diff --git a/app/Support/ValidationPatterns.php b/app/Support/ValidationPatterns.phpindex a2da0fc464..2ae1536da8 100644--- a/app/Support/ValidationPatterns.php+++ b/app/Support/ValidationPatterns.php@@ -17,6 +17,12 @@ class ValidationPatterns*/public const DESCRIPTION_PATTERN = '/^[\p{L}\p{M}\p{N}\s\-_.,!?()\'\"+=*@\/&]+$/u';+ /**+ * Pattern for file paths (dockerfile location, docker compose location, etc.)+ * Allows alphanumeric, dots, hyphens, underscores, slashes, @, ~, and ++ */+ public const FILE_PATH_PATTERN = '/^\/[a-zA-Z0-9._\-\/~@+]+$/';+/*** Get validation rules for name fields*/@@ -81,7 +87,25 @@ class ValidationPatterns];}- /**+ /**+ * Get validation rules for file path fields (dockerfile location, docker compose location)+ */+ public static function filePathRules(int $maxLength = 255): array+ {+ return ['nullable', 'string', 'max:'.$maxLength, 'regex:'.self::FILE_PATH_PATTERN];+ }++ /**+ * Get validation messages for file path fields+ */+ public static function filePathMessages(string $field = 'dockerfileLocation', string $label = 'Dockerfile'): array+ {+ return [+ "{$field}.regex" => "The {$label} location must be a valid path starting with / and containing only alphanumeric characters, dots, hyphens, underscores, slashes, @, ~, and +.",+ ];+ }++ /*** Get combined validation messages for both name and description fields*/public static function combinedMessages(): arraydiff --git a/bootstrap/helpers/api.php b/bootstrap/helpers/api.phpindex 1b03a4d374..43c074cd15 100644--- a/bootstrap/helpers/api.php+++ b/bootstrap/helpers/api.php@@ -134,8 +134,8 @@ function sharedDataApplications()'manual_webhook_secret_gitlab' => 'string|nullable','manual_webhook_secret_bitbucket' => 'string|nullable','manual_webhook_secret_gitea' => 'string|nullable',- 'dockerfile_location' => ['string', 'nullable', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],- 'docker_compose_location' => ['string', 'nullable', 'max:255', 'regex:/^\/[a-zA-Z0-9._\-\/]+$/'],+ 'dockerfile_location' => ['string', 'nullable', 'max:255', 'regex:'.\App\Support\ValidationPatterns::FILE_PATH_PATTERN],+ 'docker_compose_location' => ['string', 'nullable', 'max:255', 'regex:'.\App\Support\ValidationPatterns::FILE_PATH_PATTERN],'docker_compose' => 'string|nullable','docker_compose_domains' => 'array|nullable','docker_compose_custom_start_command' => 'string|nullable',diff --git a/tests/Feature/CommandInjectionSecurityTest.php b/tests/Feature/CommandInjectionSecurityTest.phpindex 47e9f3b357..7047e4bc6d 100644--- a/tests/Feature/CommandInjectionSecurityTest.php+++ b/tests/Feature/CommandInjectionSecurityTest.php@@ -91,6 +91,28 @@ describe('deployment job path field validation', function () {->toBe('/docker/Dockerfile.prod');});+ test('allows path with @ symbol for scoped packages', function () {+ $job = new ReflectionClass(ApplicationDeploymentJob::class);+ $method = $job->getMethod('validatePathField');+ $method->setAccessible(true);++ $instance = $job->newInstanceWithoutConstructor();++ expect($method->invoke($instance, '/packages/@intlayer/mcp/Dockerfile', 'dockerfile_location'))+ ->toBe('/packages/@intlayer/mcp/Dockerfile');+ });++ test('allows path with tilde and plus characters', function () {+ $job = new ReflectionClass(ApplicationDeploymentJob::class);+ $method = $job->getMethod('validatePathField');+ $method->setAccessible(true);++ $instance = $job->newInstanceWithoutConstructor();++ expect($method->invoke($instance, '/build~v1/c++/Dockerfile', 'dockerfile_location'))+ ->toBe('/build~v1/c++/Dockerfile');+ });+test('allows valid compose file path', function () {$job = new ReflectionClass(ApplicationDeploymentJob::class);$method = $job->getMethod('validatePathField');@@ -149,6 +171,18 @@ describe('API validation rules for path fields', function () {});});+ test('dockerfile_location validation allows paths with @ for scoped packages', function () {+ $rules = sharedDataApplications();++ $validator = validator(+ ['dockerfile_location' => '/packages/@intlayer/mcp/Dockerfile'],+ ['dockerfile_location' => $rules['dockerfile_location']]+ );++ expect($validator->fails())->toBeFalse();+ });+});+describe('sharedDataApplications rules survive array_merge in controller', function () {test('docker_compose_location safe regex is not overridden by local rules', function () {$sharedRules = sharedDataApplications();@@ -164,7 +198,7 @@ describe('sharedDataApplications rules survive array_merge in controller', funct// The merged rules for docker_compose_location should be the safe regex, not just 'string'expect($merged['docker_compose_location'])->toBeArray();- expect($merged['docker_compose_location'])->toContain('regex:/^\/[a-zA-Z0-9._\-\/]+$/');+ expect($merged['docker_compose_location'])->toContain('regex:'.\App\Support\ValidationPatterns::FILE_PATH_PATTERN);});});