-
Notifications
You must be signed in to change notification settings - Fork 0
fix(dns): prevent resolution loop when querying internal nameserver hostnames #146
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughAdds Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant DNSResolver
participant InternalNS as Internal Nameserver(s)
participant UpstreamNS as Upstream Nameserver(s)
Client->>DNSResolver: request resolve(target)
DNSResolver->>DNSResolver: isInternalNameserver(target)?
alt target is internal
DNSResolver-->>UpstreamNS: select Upstream Nameservers (avoid loop)
DNSResolver-->>Client: return Upstream Nameservers
else target not internal
DNSResolver-->>InternalNS: apply normal internal-vs-upstream logic
DNSResolver-->>Client: return chosen Nameservers
end
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
Comment |
a9d38ab to
bc1e5be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
dns/server.go
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
- GitHub Check: build
- GitHub Check: Analyze (go)
🔇 Additional comments (1)
dns/server.go (1)
633-639: LGTM! Correct placement and logic for loop prevention.The pre-check correctly intercepts queries for internal nameserver hostnames before the managed domain check. This ensures that even if an internal nameserver's hostname is within a managed domain, the resolver uses upstream nameservers to break the resolution loop.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (1)
dns/server_test.go (1)
106-113: Strengthen validation to check all returned nameservers.The current validation at line 108 only checks the first nameserver, which could miss cases where the implementation returns multiple nameservers or orders them differently. Consider adopting the more robust approach used in
TestDNSResolver_selectNameservers_ManagedDomainCheck(lines 662-690), which verifies that all returned nameservers belong to the expected list.🔎 More robust validation approach
for _, test := range tests { ns := resolver.selectNameservers(test.target) - isUpstream := len(ns) > 0 && ns[0] == "127.0.0.11:53" - if isUpstream != test.expectUpstream { - t.Errorf("selectNameservers(%q): %s - got upstream=%v, want upstream=%v", - test.target, test.description, isUpstream, test.expectUpstream) + + // Verify all returned nameservers are from the expected source + for _, nameserver := range ns { + isUpstream := nameserver == "127.0.0.11:53" + isInternal := nameserver == "aether:53" + + if test.expectUpstream && !isUpstream { + t.Errorf("selectNameservers(%q): %s - expected upstream nameserver, got %s", + test.target, test.description, nameserver) + } + if !test.expectUpstream && !isInternal { + t.Errorf("selectNameservers(%q): %s - expected internal nameserver, got %s", + test.target, test.description, nameserver) + } } }
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
dns/server.godns/server_test.go
🚧 Files skipped from review as they are similar to previous changes (1)
- dns/server.go
🧰 Additional context used
🧬 Code graph analysis (1)
dns/server_test.go (3)
logger/test.go (1)
NewTestLogger(123-127)dns/config.go (1)
DNSConfig(11-30)dns/server.go (1)
New(55-103)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
- GitHub Check: build
🔇 Additional comments (1)
dns/server_test.go (1)
46-80: Excellent test coverage for internal nameserver detection.The test cases comprehensively cover the expected behavior including exact matches, trailing dots, case insensitivity, subdomain exclusion, IP address exclusion, and empty strings. The table-driven approach is clean and makes it easy to verify all edge cases.
When resolving a domain that matches an internal nameserver's hostname (e.g., querying for
ns1.internal.example.comwhen that's configured inInternalNameservers), the resolver would attempt to resolve the nameserver using itself, creating an infinite loop.This fix adds
isInternalNameserver()to check if the query target matches any internal nameserver hostname. If so,selectNameservers()returns upstream nameservers instead, breaking the potential loop.Summary by CodeRabbit
Bug Fixes
Tests
✏️ Tip: You can customize this high-level summary in your review settings.