`Async::DNS::Resolver` will return `Resolv::DNS::Resource::IN::CNAME` when `Resolv::DNS::Resource::IN::SRV` is requested
I noticed that Async::DNS::Resolver will return CNAME records when querying SRV records for a domain that maps unknown sub-domains to a catch-all alias (ex: github.com). Where as Resolv::DNS will return an empty Array since the response records do not match the requested resource type.
This could be fixed by simply filtering the response records by class.
Steps To Reproduce
require 'async/dns'
require 'resolv'
async_resolver = Async::DNS::Resolver.new([[:udp, '8.8.8.8', 53]])
Async do
response = async_resolver.query('_xmpp-server._tcp.github.com', Resolv::DNS::Resource::IN::SRV)
records = response.answer.map { |answer| answer[2] }
p records
end
resolve = Resolv::DNS.new(nameserver: %w[8.8.8.8])
records = resolve.getresources('_xmpp-server._tcp.github.com', Resolv::DNS::Resource::IN::SRV)
p records
Expected Behavior
[]
[]
Actual Behavior
[#<Resolv::DNS::Resource::IN::CNAME:0x00007f4027885400 @name=#<Resolv::DNS::Name: github.github.io.>, @ttl=3499>]
[]
Additional Information
- ruby 3.1.4p223 (2023-03-30 revision 957bb7cb81) [x86_64-linux]
- async-dns (1.3.0)
If making such a query gives such a response, I'm not sure we should filter it, at least not at the resolver level. Maybe a higher level interface like "get addresses" or such should do that though.
If the user is explicitly querying a specific type of DNS record, and they get back another kind of record, this will likely cause a bug (no method target for ...) or require the developer to add their own filtering.
Also running into this when querying MX records for potato.com, which is a CNAME to cs.62.net. I noticed that Resolv::DNS#getresources will actually filter the records by the given Resolv::DNS::Resource::IN:: class.
I'll take a look and see what we can do.