Skip to content

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.

fix(git): harden ssh URL normalization

Iisyourdadd2ada90a4714
diff --git a/bootstrap/helpers/shared.php b/bootstrap/helpers/shared.php
index 88ac018192..011c149c93 100644
--- a/bootstrap/helpers/shared.php
+++ b/bootstrap/helpers/shared.php
@@ -3660,14 +3660,16 @@ function convertGitUrl(string $gitRepository, string $deploymentType, GithubApp|
}
}
- if (str($gitRepository)->contains('://')) {
- $parsedRepository = parse_url($gitRepository);
+ $normalizedRepository = $repository;
+
+ if (str($normalizedRepository)->contains('://')) {
+ $parsedRepository = parse_url($normalizedRepository);
if ($parsedRepository !== false && array_key_exists('port', $parsedRepository)) {
$providerInfo['port'] = (string) $parsedRepository['port'];
}
} else {
- preg_match('/^(?<host>[^:]+):(?<port>\d+)\/(?<path>.+)$/', $gitRepository, $matches);
+ preg_match('/^(?<host>[^:]+):(?<port>\d+)\/(?<path>.+)$/', $normalizedRepository, $matches);
if (! empty($matches['port'])) {
$providerInfo['port'] = $matches['port'];
diff --git a/tests/Feature/ConvertingGitUrlsTest.php b/tests/Feature/ConvertingGitUrlsTest.php
index 5ff1c83650..96b19fcc96 100644
--- a/tests/Feature/ConvertingGitUrlsTest.php
+++ b/tests/Feature/ConvertingGitUrlsTest.php
@@ -68,3 +68,39 @@ test('convertGitUrlsForSourceAndSshUrlSchemeWithCustomPort', function () {
'port' => '22222',
]);
});
+
+test('convertGitUrlsForSourceAndSshUrlSchemeWithCustomPortAndIpv6Host', function () {
+ $result = convertGitUrl('ssh://git@[2001:db8::10]:22222/group/project.git', 'source', null);
+ expect($result)->toBe([
+ 'repository' => 'ssh://git@[2001:db8::10]:22222/group/project.git',
+ 'port' => '22222',
+ ]);
+});
+
+test('convertGitUrlsForDeployKeyAndGithubAppWithCustomPort', function () {
+ $githubApp = new GithubApp([
+ 'html_url' => 'https://github.example.com',
+ 'custom_user' => 'git',
+ 'custom_port' => 22222,
+ ]);
+
+ $result = convertGitUrl('andrasbacsai/coolify-examples.git', 'deploy_key', $githubApp);
+ expect($result)->toBe([
+ 'repository' => 'ssh://[email protected]:22222/andrasbacsai/coolify-examples.git',
+ 'port' => '22222',
+ ]);
+});
+
+test('convertGitUrlsForDeployKeyAndGithubAppWithCustomPortAndIpv6Host', function () {
+ $githubApp = new GithubApp([
+ 'html_url' => 'https://[2001:db8::10]',
+ 'custom_user' => 'git',
+ 'custom_port' => 22222,
+ ]);
+
+ $result = convertGitUrl('andrasbacsai/coolify-examples.git', 'deploy_key', $githubApp);
+ expect($result)->toBe([
+ 'repository' => 'ssh://git@[2001:db8::10]:22222/andrasbacsai/coolify-examples.git',
+ 'port' => '22222',
+ ]);
+});