diff options
author | Git'Fellow <12234510+solracsf@users.noreply.github.com> | 2024-11-28 08:41:50 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-28 08:41:50 +0100 |
commit | 4875f3281ac8f64b4d819ba00bc7056b63f8ec5e (patch) | |
tree | 878fca2d3b5287d4d68b12b9fff59e7c713771f2 | |
parent | ee753f08cabbf5dc935916107e186cc3e8f43b1f (diff) | |
parent | 72a891d26003fb87d6e4dcf16193dd80860a3435 (diff) | |
download | nextcloud-server-4875f3281ac8f64b4d819ba00bc7056b63f8ec5e.tar.gz nextcloud-server-4875f3281ac8f64b4d819ba00bc7056b63f8ec5e.zip |
Merge pull request #49279 from nextcloud/backport/48675/stable28
[stable28] DNS: do not query CNAME if A succeeded already
-rw-r--r-- | lib/private/Http/Client/DnsPinMiddleware.php | 7 | ||||
-rw-r--r-- | tests/lib/Http/Client/DnsPinMiddlewareTest.php | 5 |
2 files changed, 8 insertions, 4 deletions
diff --git a/lib/private/Http/Client/DnsPinMiddleware.php b/lib/private/Http/Client/DnsPinMiddleware.php index aecccc6ce97..5ad12089884 100644 --- a/lib/private/Http/Client/DnsPinMiddleware.php +++ b/lib/private/Http/Client/DnsPinMiddleware.php @@ -74,15 +74,19 @@ class DnsPinMiddleware { $soaDnsEntry = $this->soaRecord($target); $dnsNegativeTtl = $soaDnsEntry['minimum-ttl'] ?? null; + $canHaveCnameRecord = true; $dnsTypes = [DNS_A, DNS_AAAA, 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'])) { @@ -93,7 +97,6 @@ class DnsPinMiddleware { $canHaveCnameRecord = false; } elseif (isset($dnsResponse['target']) && $canHaveCnameRecord) { $targetIps = array_merge($targetIps, $this->dnsResolve($dnsResponse['target'], $recursionCount)); - $canHaveCnameRecord = true; } } } elseif ($dnsNegativeTtl !== null) { diff --git a/tests/lib/Http/Client/DnsPinMiddlewareTest.php b/tests/lib/Http/Client/DnsPinMiddlewareTest.php index 2fa868e6963..1414d58bd97 100644 --- a/tests/lib/Http/Client/DnsPinMiddlewareTest.php +++ b/tests/lib/Http/Client/DnsPinMiddlewareTest.php @@ -554,10 +554,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); } } |