diff --git a/app/Support/DomainFavicon.php b/app/Support/DomainFavicon.php new file mode 100644 index 0000000000..e872a14ac7 --- /dev/null +++ b/app/Support/DomainFavicon.php @@ -0,0 +1,63 @@ + */ + private const LOCAL_SUFFIXES = ['.localhost', '.local', '.lan', '.internal', '.home.arpa', '.test']; + + public static function url(string $publicUrl, ?string $dnsStatus = null, ?string $expectedIp = null): ?string + { + $parts = parse_url($publicUrl); + if (! is_array($parts) || ! isset($parts['scheme'], $parts['host'])) { + return null; + } + + if (self::isPrivateHost($parts['host'])) { + return null; + } + + if ($dnsStatus === 'ok' && filled($expectedIp) && ! DnsRecordHints::isPublicAddress($expectedIp)) { + return null; + } + + $port = isset($parts['port']) ? ':'.$parts['port'] : ''; + + return $parts['scheme'].'://'.$parts['host'].$port.'/favicon.ico'; + } + + private static function isPrivateHost(string $host): bool + { + $host = strtolower(trim($host, '[]')); + + if (filter_var($host, FILTER_VALIDATE_IP) !== false) { + return ! DnsRecordHints::isPublicAddress($host); + } + + if ($host === 'localhost') { + return true; + } + + foreach (self::LOCAL_SUFFIXES as $suffix) { + if (str_ends_with($host, $suffix)) { + return true; + } + } + + if (preg_match('/(?:^|\.)(\d{1,3}(?:[.-]\d{1,3}){3})\.(?:sslip|nip)\.io$/', $host, $matches) === 1) { + $embeddedIp = str_replace('-', '.', $matches[1]); + + return filter_var($embeddedIp, FILTER_VALIDATE_IP) === false + || ! DnsRecordHints::isPublicAddress($embeddedIp); + } + + return false; + } +} diff --git a/resources/views/livewire/project/application/partials/domain-row.blade.php b/resources/views/livewire/project/application/partials/domain-row.blade.php index 018beefebd..60f0eb38f8 100644 --- a/resources/views/livewire/project/application/partials/domain-row.blade.php +++ b/resources/views/livewire/project/application/partials/domain-row.blade.php @@ -16,10 +16,7 @@ }; $gridClass = 'service-domains-overview-grid'; $publicUrl = getFqdnWithoutPort($row['url']); - $domainParts = $isSuggested ? null : parse_url($publicUrl); - $faviconUrl = is_array($domainParts) && isset($domainParts['scheme'], $domainParts['host']) - ? $domainParts['scheme'].'://'.$domainParts['host'].'/favicon.ico' - : null; + $faviconUrl = $isSuggested ? null : \App\Support\DomainFavicon::url($publicUrl, $row['dns_status'] ?? null, $row['expected_ip'] ?? null); $rowDirection = $isCompose ? ($serviceRedirects[$this->serviceRedirectWireKey($row['service'])] ?? 'both') : $redirect; diff --git a/resources/views/livewire/project/service/partials/domain-table.blade.php b/resources/views/livewire/project/service/partials/domain-table.blade.php index 7038756440..af5d672525 100644 --- a/resources/views/livewire/project/service/partials/domain-table.blade.php +++ b/resources/views/livewire/project/service/partials/domain-table.blade.php @@ -45,7 +45,6 @@ ? \Illuminate\Support\Str::headline($row['service_name']) : '-'; $publicUrl = getFqdnWithoutPort($row['url']); - $domainParts = $isSuggested ? null : parse_url($publicUrl); $isNoindexed = $service->applications->firstWhere('id', $row['service_application_id'])?->isDomainNoindexed($row['url']); $rowDirection = $serviceRedirects[$row['service_application_id']] ?? 'both'; $directionLabel = match ($rowDirection) { @@ -53,9 +52,7 @@ 'non-www' => 'Redirect to non-www', default => 'Both www and non-www', }; - $faviconUrl = is_array($domainParts) && isset($domainParts['scheme'], $domainParts['host']) - ? $domainParts['scheme'].'://'.$domainParts['host'].(isset($domainParts['port']) ? ':'.$domainParts['port'] : '').'/favicon.ico' - : null; + $faviconUrl = $isSuggested ? null : \App\Support\DomainFavicon::url($publicUrl, $row['dns_status'] ?? null, $row['expected_ip'] ?? null); $domainKey = hash('sha256', $row['url'].'|'.($row['service_application_id'] ?? '')); $editingParts = \App\Support\DomainUrlParts::split($row['url']); if ($row['has_port_override'] ?? false) { diff --git a/resources/views/livewire/traffic/_geo.blade.php b/resources/views/livewire/traffic/_geo.blade.php index f47e0506bf..06f24bfee6 100644 --- a/resources/views/livewire/traffic/_geo.blade.php +++ b/resources/views/livewire/traffic/_geo.blade.php @@ -50,10 +50,35 @@ @else