Skip to content

fix: prevent service domain FQDN corruption when ports are present#8980

Open
pannous wants to merge 1 commit intocoollabsio:nextfrom
pannous:fix/service-domain-url-corruption-v2
Open

fix: prevent service domain FQDN corruption when ports are present#8980
pannous wants to merge 1 commit intocoollabsio:nextfrom
pannous:fix/service-domain-url-corruption-v2

Conversation

@pannous
Copy link

@pannous pannous commented Mar 14, 2026

Changes

When a one-click service has a predefined port (e.g., GitLab with port 80), saving the domain FQDN corrupts the URL from http://git.example.com:80 into //:80git.example.com.

Three places in parsers.php use fragile string manipulation (str()->after('://')->before(':')) to strip ports. This breaks when the URL structure is unexpected. The existing getFqdnWithoutPort() helper in shared.php already handles this correctly using Spatie\Url, so this PR replaces the inline code with calls to that helper.

Also fixes a strict type comparison (int !== string) in the old parser's port matching that caused unnecessary FQDN rewrites on every parse cycle.

Issues

Category

  • Bug fix
  • Improvement
  • New feature
  • Adding new one click service
  • Fixing or updating existing one click service

Preview

N/A — backend-only fix, no UI changes.

AI Assistance

  • AI was used (please describe below)

If AI was used:

  • Tools used: Claude Code
  • How extensively: Investigation and code search. Fix was human-reviewed and validated against existing getFqdnWithoutPort() implementation.

Testing

  • Verified that getFqdnWithoutPort('http://git.example.com:80') returns http://git.example.com (uses Spatie\Url internally)
  • Verified that getFqdnWithoutPort('git.example.com') falls back gracefully (returns input unchanged)
  • Verified (int) $env_port !== (int) $predefinedPort correctly compares 80 and "80" as equal

Contributor Agreement

Important

  • I have read and understood the contributor guidelines. If I have failed to follow any guideline, I understand that this PR may be closed without review.
  • I have searched existing issues and pull requests (including closed ones) to ensure this isn't a duplicate.
  • I have tested all the changes thoroughly with a local development instance of Coolify and I am confident that they will work as expected when a maintainer tests them.

Replace fragile string manipulation with existing getFqdnWithoutPort()
helper. Fix strict type comparison in port matching.

Fixes coollabsio#8798
Copilot AI review requested due to automatic review settings March 14, 2026 18:30
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR standardizes “FQDN without port” handling by reusing the existing getFqdnWithoutPort() helper in Docker Compose parsers, and prevents unnecessary port rewrites by comparing ports numerically.

Changes:

  • Use getFqdnWithoutPort() when deriving COOLIFY_URL / service URLs (instead of inline string slicing).
  • In service parsing, reuse the computed FQDN-without-port for $url to avoid duplicate transformations.
  • Compare URL ports as integers when enforcing predefined ports (to avoid string/int strict-compare mismatches).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
bootstrap/helpers/shared.php Casts ports to int before comparing to avoid spurious port updates/saves.
bootstrap/helpers/parsers.php Refactors URL-without-port generation to use getFqdnWithoutPort() across application/service parsing.

You can also share your feedback on Copilot code review. Take the survey.

@@ -2539,7 +2539,7 @@ function serviceParser(Service $resource): Collection
});
$coolifyEnvironments->put('COOLIFY_FQDN', $fqdnsWithoutPort->implode(','));
$urls = $fqdns->map(function ($fqdn): Stringable {
} elseif ($isServiceApplication) {
$fqdn = str($savedService->fqdn)->after('://')->before(':')->prepend(str($savedService->fqdn)->before('://')->append('://'))->value();
$url = str($savedService->fqdn)->after('://')->before(':')->prepend(str($savedService->fqdn)->before('://')->append('://'))->value();
$fqdn = getFqdnWithoutPort($savedService->fqdn);
@ShadowArcanist
Copy link
Member

When a one-click service has a predefined port (e.g., GitLab with port 80), saving the domain FQDN corrupts the URL from http://git.example.com:80 into //:80git.example.com.

Which version of Coolify has this issue?

@ShadowArcanist ShadowArcanist added the 💤 Waiting for feedback Issues awaiting a response from the author. label Mar 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

quality/verified 💤 Waiting for feedback Issues awaiting a response from the author.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants