socketry / async-dns

An asynchronous DNS resolver and server.
MIT License
96 stars 14 forks source link

`Async::DNS::Resolver` will return `Resolv::DNS::Resource::IN::CNAME` when `Resolv::DNS::Resource::IN::SRV` is requested #28

Open postmodern opened 1 year ago

postmodern commented 1 year ago

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

ioquatix commented 1 year ago

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.

postmodern commented 1 year ago

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.

postmodern commented 2 months ago

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.

ioquatix commented 2 months ago

I'll take a look and see what we can do.