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(webhook): match GitLab SSH repos with custom ports

Andras Bacsai34f15c106c00
diff --git a/app/Http/Controllers/Webhook/Concerns/MatchesManualWebhookApplications.php b/app/Http/Controllers/Webhook/Concerns/MatchesManualWebhookApplications.php
index f1fd0c40f6..0463790eb7 100644
--- a/app/Http/Controllers/Webhook/Concerns/MatchesManualWebhookApplications.php
+++ b/app/Http/Controllers/Webhook/Concerns/MatchesManualWebhookApplications.php
@@ -81,6 +81,10 @@ trait MatchesManualWebhookApplications
$path = data_get($parts, 'path');
} elseif (Str::startsWith($gitRepository, 'git@') && str_contains($gitRepository, ':')) {
$path = Str::after($gitRepository, ':');
+ // scp-style SSH URLs embed a custom port as "git@host:2222/owner/repo".
+ // Strip the leading numeric port segment so the path matches the webhook
+ // payload's owner/repo, consistent with convertGitUrl() in shared.php.
+ $path = preg_replace('#^\d+/#', '', $path) ?? $path;
} else {
$path = $gitRepository;
}
diff --git a/tests/Feature/Webhook/WebhookHmacTest.php b/tests/Feature/Webhook/WebhookHmacTest.php
index be2417462b..3f49ff43d7 100644
--- a/tests/Feature/Webhook/WebhookHmacTest.php
+++ b/tests/Feature/Webhook/WebhookHmacTest.php
@@ -509,6 +509,48 @@ describe('Manual Webhook Repository Matching', function () {
expect($response->getContent())->not->toContain('No applications found');
});
+ test('gitlab matches scp-style ssh repository URL with custom port', function () {
+ $app = createApplicationWithWebhook(overrides: [
+ 'git_repository' => '[email protected]:2222/services/xyz.git',
+ 'git_branch' => 'master',
+ ]);
+ $secret = $app->manual_webhook_secret_gitlab;
+
+ $response = $this->postJson('/webhooks/source/gitlab/events/manual', [
+ 'object_kind' => 'push',
+ 'ref' => 'refs/heads/master',
+ 'project' => ['path_with_namespace' => 'services/xyz'],
+ 'after' => 'abc123',
+ 'commits' => [],
+ ], [
+ 'X-Gitlab-Token' => $secret,
+ ]);
+
+ $response->assertOk();
+ expect($response->getContent())->not->toContain('No applications found');
+ });
+
+ test('gitlab matches scp-style ssh repository URL without port', function () {
+ $app = createApplicationWithWebhook(overrides: [
+ 'git_repository' => '[email protected]:services/xyz.git',
+ 'git_branch' => 'master',
+ ]);
+ $secret = $app->manual_webhook_secret_gitlab;
+
+ $response = $this->postJson('/webhooks/source/gitlab/events/manual', [
+ 'object_kind' => 'push',
+ 'ref' => 'refs/heads/master',
+ 'project' => ['path_with_namespace' => 'services/xyz'],
+ 'after' => 'abc123',
+ 'commits' => [],
+ ], [
+ 'X-Gitlab-Token' => $secret,
+ ]);
+
+ $response->assertOk();
+ expect($response->getContent())->not->toContain('No applications found');
+ });
+
test('github matches repository case-insensitively', function () {
$app = createApplicationWithWebhook(overrides: [
'git_repository' => 'https://github.com/Test-Org/Test-Repo.git',