fix(netxlite): ensure we only accept DNS responses (#735)
Previously, the DNS decoder did not check whether it was parsing
a DNS query or a DNS response, which was wrong.
As a side note, it seems I am using "reply" in the codebase instead
of "response". The latter seems correct DNS terminology.
This diff has been extracted from 9249d14f80
See https://github.com/ooni/probe/issues/2096.
This commit is contained in:
parent
ce052b665e
commit
7c45f7b88c
3 changed files with 66 additions and 7 deletions
|
|
@ -24,6 +24,19 @@ func TestDNSDecoder(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("with bytes containing a query", func(t *testing.T) {
|
||||
d := &DNSDecoderMiekg{}
|
||||
queryID := dns.Id()
|
||||
rawQuery := dnsGenQuery(dns.TypeA, queryID)
|
||||
addrs, err := d.DecodeLookupHost(dns.TypeA, rawQuery, queryID)
|
||||
if !errors.Is(err, ErrDNSIsQuery) {
|
||||
t.Fatal("unexpected err", err)
|
||||
}
|
||||
if len(addrs) > 0 {
|
||||
t.Fatal("expected no addrs")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("wrong query ID", func(t *testing.T) {
|
||||
d := &DNSDecoderMiekg{}
|
||||
const (
|
||||
|
|
@ -157,15 +170,16 @@ func TestDNSDecoder(t *testing.T) {
|
|||
})
|
||||
})
|
||||
|
||||
t.Run("parseReply", func(t *testing.T) {
|
||||
t.Run("decodeSuccessfulReply", func(t *testing.T) {
|
||||
d := &DNSDecoderMiekg{}
|
||||
msg := &dns.Msg{}
|
||||
msg.Rcode = dns.RcodeFormatError // an rcode we don't handle
|
||||
msg.Response = true
|
||||
data, err := msg.Pack()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reply, err := d.parseReply(data, 0)
|
||||
reply, err := d.decodeSuccessfulReply(data, 0)
|
||||
if !errors.Is(err, ErrOODNSMisbehaving) { // catch all error
|
||||
t.Fatal("not the error we expected", err)
|
||||
}
|
||||
|
|
@ -186,6 +200,19 @@ func TestDNSDecoder(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("with bytes containing a query", func(t *testing.T) {
|
||||
d := &DNSDecoderMiekg{}
|
||||
queryID := dns.Id()
|
||||
rawQuery := dnsGenQuery(dns.TypeHTTPS, queryID)
|
||||
https, err := d.DecodeHTTPS(rawQuery, queryID)
|
||||
if !errors.Is(err, ErrDNSIsQuery) {
|
||||
t.Fatal("unexpected err", err)
|
||||
}
|
||||
if https != nil {
|
||||
t.Fatal("expected nil https")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("wrong query ID", func(t *testing.T) {
|
||||
d := &DNSDecoderMiekg{}
|
||||
const (
|
||||
|
|
@ -252,6 +279,19 @@ func TestDNSDecoder(t *testing.T) {
|
|||
}
|
||||
})
|
||||
|
||||
t.Run("with bytes containing a query", func(t *testing.T) {
|
||||
d := &DNSDecoderMiekg{}
|
||||
queryID := dns.Id()
|
||||
rawQuery := dnsGenQuery(dns.TypeNS, queryID)
|
||||
ns, err := d.DecodeNS(rawQuery, queryID)
|
||||
if !errors.Is(err, ErrDNSIsQuery) {
|
||||
t.Fatal("unexpected err", err)
|
||||
}
|
||||
if len(ns) > 0 {
|
||||
t.Fatal("expected no result")
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("wrong query ID", func(t *testing.T) {
|
||||
d := &DNSDecoderMiekg{}
|
||||
const (
|
||||
|
|
|
|||
Loading…
Reference in a new issue