paulc / dnslib

A Python library to encode/decode DNS wire-format packets
https://github.com/paulc/dnslib
BSD 2-Clause "Simplified" License
295 stars 84 forks source link

DNSLabels matchSuffix are not case-insensitive (From #22) #36

Closed NiKiZe closed 1 year ago

NiKiZe commented 2 years ago

In #22 case-insensitive hashing was mentioned and resolved.

matchSuffix should (at least most of the time) be case insensitive https://datatracker.ietf.org/doc/html/rfc4343

>>> from dnslib.dns import DNSLabel
>>> l = DNSLabel("test.example.Com")
>>> l
<DNSLabel: 'test.example.Com.'>
>>> l.matchSuffix("example.Com")
True
>>> l.matchSuffix("example.com")
False
>>>

The last command is False, expected True

It is seen in the wild that requests are coming in especially as .ip6.arpa. and .IP6.ARPA.

Originally posted by @NiKiZe in https://github.com/paulc/dnslib/issues/22#issuecomment-1030912336

Possible Fix:

@@ -113,14 +115,14 @@ class DNSLabel(object):
             Return True if label suffix matches
         """
         suffix = DNSLabel(suffix)
-        return self.label[-len(suffix.label):] == suffix.label
+        return DNSLabel(self.label[-len(suffix.label):]) == suffix