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: return null for invalid repository URLs

Andras Bacsai2ebbc5113ec8
diff --git a/app/Models/Application.php b/app/Models/Application.php
index 6bfbb6de75..7f7ce5ea1f 100644
--- a/app/Models/Application.php
+++ b/app/Models/Application.php
@@ -714,7 +714,7 @@ class Application extends BaseModel
);
}
- public function gitCommitLink($link): string
+ public function gitCommitLink($link): ?string
{
if (! is_null(data_get($this, 'source.html_url')) && ! is_null(data_get($this, 'git_repository')) && ! is_null(data_get($this, 'git_branch'))) {
if (str($this->source->html_url)->contains('bitbucket')) {
@@ -731,6 +731,10 @@ class Application extends BaseModel
$git_repository = 'https://'.parse_url($git_repository, PHP_URL_HOST).parse_url($git_repository, PHP_URL_PATH);
}
+ if (! filter_var($git_repository, FILTER_VALIDATE_URL)) {
+ return null;
+ }
+
$url = Url::fromString(Str::replaceEnd('.git', '', $git_repository));
$url = $url->withUserInfo('');
$commitPath = str($git_repository)->contains('bitbucket') ? 'commits' : 'commit';
diff --git a/tests/Unit/ApplicationGitCommitLinkTest.php b/tests/Unit/ApplicationGitCommitLinkTest.php
index e1a15e7149..378384fe8f 100644
--- a/tests/Unit/ApplicationGitCommitLinkTest.php
+++ b/tests/Unit/ApplicationGitCommitLinkTest.php
@@ -26,3 +26,14 @@ it('generates commit links for direct repository remotes', function (string $rep
'https://bitbucket.org/coollabsio/coolify/commits/1234567890abcdef',
],
]);
+
+it('does not generate commit links from incomplete repository URLs', function (string $repository) {
+ $application = new Application;
+ $application->setRelation('source', null);
+ $application->git_repository = $repository;
+
+ expect($application->gitCommitLink('1234567890abcdef'))->toBeNull();
+})->with([
+ 'missing host' => 'https://',
+ 'missing scheme' => 'github.com/coollabsio/coolify',
+]);