diff options
author | georglauterbach <44545919+georglauterbach@users.noreply.github.com> | 2024-10-13 08:21:03 +0000 |
---|---|---|
committer | backportbot[bot] <backportbot[bot]@users.noreply.github.com> | 2024-11-14 10:45:23 +0000 |
commit | c97cb962eeca14e8f031b8727342539a74267c3a (patch) | |
tree | 86ba02037c9707e8f06372bedb4526c96986d8e0 | |
parent | e75ed32cacc9516071a883d6dbcf88c6bd19ee1b (diff) | |
download | nextcloud-server-c97cb962eeca14e8f031b8727342539a74267c3a.tar.gz nextcloud-server-c97cb962eeca14e8f031b8727342539a74267c3a.zip |
fix: do not query CNAME if A succeeded already
Signed-off-by: georglauterbach <44545919+georglauterbach@users.noreply.github.com>
-rw-r--r-- | lib/private/Http/Client/DnsPinMiddleware.php | 6 | ||||
-rw-r--r-- | tests/lib/Http/Client/DnsPinMiddlewareTest.php | 5 |
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/private/Http/Client/DnsPinMiddleware.php b/lib/private/Http/Client/DnsPinMiddleware.php index fcf0818ebb9..50e07f8c34d 100644 --- a/lib/private/Http/Client/DnsPinMiddleware.php +++ b/lib/private/Http/Client/DnsPinMiddleware.php @@ -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'])) { diff --git a/tests/lib/Http/Client/DnsPinMiddlewareTest.php b/tests/lib/Http/Client/DnsPinMiddlewareTest.php index d265ce3e71c..7ece5423b89 100644 --- a/tests/lib/Http/Client/DnsPinMiddlewareTest.php +++ b/tests/lib/Http/Client/DnsPinMiddlewareTest.php @@ -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); } } |