Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 22 additions & 10 deletions app/Models/InstanceSettings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,20 +49,32 @@ protected static function booted(): void
}
});
}

public function fqdn(): Attribute
{
return Attribute::make(
set: function ($value) {
if ($value) {
$url = Url::fromString($value);
$host = $url->getHost();
{
return Attribute::make(
set: function ($value) {
if ($value) {
$url = Url::fromString($value);
$host = $url->getHost();
$scheme = $url->getScheme();
$port = $url->getPort();

// keep :80 or :443 only if explicitly defined
if ($port && !in_array($port, [80, 443])) {
return "{$scheme}://{$host}:{$port}";
}

return $url->getScheme().'://'.$host;
// explicitly keep :80 if user/template provided it
if ($port === 80 && str_contains($value, ':80')) {
return "{$scheme}://{$host}:{$port}";
}

return "{$scheme}://{$host}";
}
);
}
}
);
Comment on lines +63 to +75
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Don't drop :443 for HTTP URLs.

As written, http://example.test:443 is rewritten to http://example.test, which breaks any template relying on that non-standard port. We only want to hide :443 for HTTPS defaults; for any other scheme (including HTTP) the explicit port must be kept.

-                // keep :80 or :443 only if explicitly defined
-                if ($port && !in_array($port, [80, 443])) {
-                    return "{$scheme}://{$host}:{$port}";
-                }
-
-                // explicitly keep :80 if user/template provided it
-                if ($port === 80 && str_contains($value, ':80')) {
-                    return "{$scheme}://{$host}:{$port}";
-                }
-
-                return "{$scheme}://{$host}";
+                if ($port === null) {
+                    return "{$scheme}://{$host}";
+                }
+
+                if ($scheme === 'https' && $port === 443) {
+                    return "{$scheme}://{$host}";
+                }
+
+                if ($scheme === 'http' && $port === 80 && ! str_contains($value, ':80')) {
+                    return "{$scheme}://{$host}";
+                }
+
+                return "{$scheme}://{$host}:{$port}";

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In app/Models/InstanceSettings.php around lines 63 to 75, the current logic
strips :443 for any scheme; change it to only omit default ports per scheme
(omit :80 only for http and omit :443 only for https). Update the initial
port-check so you include the port in the returned URL unless it is the scheme's
default (http+80 or https+443), and preserve explicit user/template-specified
ports (e.g., keep :80 if the original value contained ':80' and keep :443 for
http). Ensure the final return builds the URL without a port only when the port
equals the scheme's default and wasn’t explicitly present in the original
string.

}


public function updateCheckFrequency(): Attribute
{
Expand Down