aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgeorglauterbach <44545919+georglauterbach@users.noreply.github.com>2024-10-13 08:21:03 +0000
committerGit'Fellow <12234510+solracsf@users.noreply.github.com>2024-11-28 08:05:44 +0100
commitd4ee439d3725c031a890afb99eecbae1a9f9547b (patch)
treefc2d826e3c485d90d0ea7d6e9351803f694495a2
parentee753f08cabbf5dc935916107e186cc3e8f43b1f (diff)
downloadnextcloud-server-d4ee439d3725c031a890afb99eecbae1a9f9547b.tar.gz
nextcloud-server-d4ee439d3725c031a890afb99eecbae1a9f9547b.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.php6
-rw-r--r--tests/lib/Http/Client/DnsPinMiddlewareTest.php5
2 files changed, 8 insertions, 3 deletions
diff --git a/lib/private/Http/Client/DnsPinMiddleware.php b/lib/private/Http/Client/DnsPinMiddleware.php
index aecccc6ce97..73310091a41 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'])) {
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);
}
}