]> source.dussan.org Git - nextcloud-server.git/commitdiff
fix: do not query CNAME if A succeeded already
authorgeorglauterbach <44545919+georglauterbach@users.noreply.github.com>
Sun, 13 Oct 2024 08:21:03 +0000 (08:21 +0000)
committerbackportbot[bot] <backportbot[bot]@users.noreply.github.com>
Thu, 14 Nov 2024 10:45:23 +0000 (10:45 +0000)
Signed-off-by: georglauterbach <44545919+georglauterbach@users.noreply.github.com>
lib/private/Http/Client/DnsPinMiddleware.php
tests/lib/Http/Client/DnsPinMiddlewareTest.php

index fcf0818ebb953e42e14b0b8a9402bc1d15655950..50e07f8c34de65762baa121fd00f6f77b4bd8632 100644 (file)
@@ -57,17 +57,21 @@ class DnsPinMiddleware {
 
                $soaDnsEntry = $this->soaRecord($target);
                $dnsNegativeTtl = $soaDnsEntry['minimum-ttl'] ?? null;
+               $canHaveCnameRecord = true;
 
                $dnsTypes = \defined('AF_INET6') || @inet_pton('::1')
                        ? [DNS_A, DNS_AAAA, DNS_CNAME]
                        : [DNS_A, DNS_CNAME];
                foreach ($dnsTypes as $dnsType) {
+                       if ($canHaveCnameRecord === false && $dnsType === DNS_CNAME) {
+                               continue;
+                       }
+
                        if ($this->negativeDnsCache->isNegativeCached($target, $dnsType)) {
                                continue;
                        }
 
                        $dnsResponses = $this->dnsGetRecord($target, $dnsType);
-                       $canHaveCnameRecord = true;
                        if ($dnsResponses !== false && count($dnsResponses) > 0) {
                                foreach ($dnsResponses as $dnsResponse) {
                                        if (isset($dnsResponse['ip'])) {
index d265ce3e71c187ae6effbc30668c61a1e3d5a61d..7ece5423b897a9c948d59d27f64e8fe82b95a24b 100644 (file)
@@ -537,10 +537,11 @@ class DnsPinMiddlewareTest extends TestCase {
                        ['nextcloud' => ['allow_local_address' => false]]
                );
 
-               $this->assertCount(4, $dnsQueries);
+               $this->assertCount(3, $dnsQueries);
                $this->assertContains('example.com' . DNS_SOA, $dnsQueries);
                $this->assertContains('subsubdomain.subdomain.example.com' . DNS_A, $dnsQueries);
                $this->assertContains('subsubdomain.subdomain.example.com' . DNS_AAAA, $dnsQueries);
-               $this->assertContains('subsubdomain.subdomain.example.com' . DNS_CNAME, $dnsQueries);
+               // CNAME should not be queried if A or AAAA succeeded already
+               $this->assertNotContains('subsubdomain.subdomain.example.com' . DNS_CNAME, $dnsQueries);
        }
 }