From b81baff4b178b8264a9ae4ab704f7902c841fa1b Mon Sep 17 00:00:00 2001 From: Andras Bacsai <5845193+andrasbacsai@users.noreply.github.com> Date: Tue, 14 Oct 2025 20:44:19 +0200 Subject: [PATCH] fix: improve logging and add shell escaping for git ls-remote Two improvements to Git deployment handling: 1. **ApplicationDeploymentJob.php**: - Fixed log message to show actual resolved commit SHA (`$this->commit`) - Previously showed `$this->application->git_commit_sha` which could be "HEAD" - Now displays the actual 40-character commit SHA that will be deployed 2. **Application.php (generateGitLsRemoteCommands)**: - Added `escapeshellarg()` for repository URL in 'other' deployment type - Prevents shell injection in git ls-remote commands - Complements existing shell escaping in `generateGitImportCommands` - Ensures consistent security across all Git operations **Security Impact:** - All Git commands now use properly escaped repository URLs - Prevents command injection through malicious repository URLs - Consistent escaping in both ls-remote and clone operations **User Experience:** - Deployment logs now show exact commit SHA being deployed - More accurate debugging information for deployment issues Co-Authored-By: Claude --- app/Jobs/ApplicationDeploymentJob.php | 2 +- app/Models/Application.php | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/Jobs/ApplicationDeploymentJob.php b/app/Jobs/ApplicationDeploymentJob.php index 4a849fccb..5b4f71ac9 100644 --- a/app/Jobs/ApplicationDeploymentJob.php +++ b/app/Jobs/ApplicationDeploymentJob.php @@ -1927,7 +1927,7 @@ private function clone_repository() { $importCommands = $this->generate_git_import_commands(); $this->application_deployment_queue->addLogEntry("\n----------------------------------------"); - $this->application_deployment_queue->addLogEntry("Importing {$this->customRepository}:{$this->application->git_branch} (commit sha {$this->application->git_commit_sha}) to {$this->basedir}."); + $this->application_deployment_queue->addLogEntry("Importing {$this->customRepository}:{$this->application->git_branch} (commit sha {$this->commit}) to {$this->basedir}."); if ($this->pull_request_id !== 0) { $this->application_deployment_queue->addLogEntry("Checking out tag pull/{$this->pull_request_id}/head."); } diff --git a/app/Models/Application.php b/app/Models/Application.php index 82e3e596c..33c1b7fc4 100644 --- a/app/Models/Application.php +++ b/app/Models/Application.php @@ -1131,7 +1131,8 @@ public function generateGitLsRemoteCommands(string $deployment_uuid, bool $exec_ if ($this->deploymentType() === 'other') { $fullRepoUrl = $customRepository; - $base_command = "{$base_command} {$customRepository}"; + $escapedCustomRepository = escapeshellarg($customRepository); + $base_command = "{$base_command} {$escapedCustomRepository}"; if ($exec_in_docker) { $commands->push(executeInDocker($deployment_uuid, $base_command));