@@ -171,6 +171,55 @@ func TestTrace(t *testing.T) {
171171 require .Nil (t , err , "could not resolve dns" )
172172}
173173
174+ func TestParseFromMsgIgnoresExtraAndNsSections (t * testing.T ) {
175+ msg := new (dns.Msg )
176+ msg .SetQuestion ("example.com." , dns .TypeA )
177+
178+ msg .Answer = []dns.RR {
179+ & dns.A {
180+ Hdr : dns.RR_Header {Name : "example.com." , Rrtype : dns .TypeA , Class : dns .ClassINET , Ttl : 300 },
181+ A : []byte {93 , 184 , 216 , 34 },
182+ },
183+ }
184+
185+ msg .Ns = []dns.RR {
186+ & dns.NS {
187+ Hdr : dns.RR_Header {Name : "example.com." , Rrtype : dns .TypeNS , Class : dns .ClassINET , Ttl : 3600 },
188+ Ns : "ns1.example.com." ,
189+ },
190+ & dns.SOA {
191+ Hdr : dns.RR_Header {Name : "example.com." , Rrtype : dns .TypeSOA , Class : dns .ClassINET , Ttl : 3600 },
192+ Ns : "ns1.example.com." ,
193+ Mbox : "admin.example.com." ,
194+ Serial : 2024010101 ,
195+ Refresh : 7200 ,
196+ Retry : 3600 ,
197+ Expire : 1209600 ,
198+ Minttl : 300 ,
199+ },
200+ }
201+
202+ msg .Extra = []dns.RR {
203+ & dns.A {
204+ Hdr : dns.RR_Header {Name : "ns1.example.com." , Rrtype : dns .TypeA , Class : dns .ClassINET , Ttl : 3600 },
205+ A : []byte {198 , 51 , 100 , 1 },
206+ },
207+ & dns.AAAA {
208+ Hdr : dns.RR_Header {Name : "ns1.example.com." , Rrtype : dns .TypeAAAA , Class : dns .ClassINET , Ttl : 3600 },
209+ AAAA : []byte {0x20 , 0x01 , 0x0d , 0xb8 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0x01 },
210+ },
211+ }
212+
213+ d := & DNSData {}
214+ err := d .ParseFromMsg (msg )
215+ require .NoError (t , err )
216+
217+ assert .Equal (t , []string {"93.184.216.34" }, d .A , "only Answer A records should be parsed" )
218+ assert .Empty (t , d .AAAA , "Additional AAAA glue records should not leak" )
219+ assert .Empty (t , d .NS , "Authority NS records should not leak" )
220+ assert .Empty (t , d .SOA , "Authority SOA records should not leak" )
221+ }
222+
174223func TestInternalIPDetectionWithHostsFile (t * testing.T ) {
175224 CheckInternalIPs = true
176225 defer func () { CheckInternalIPs = false }()
0 commit comments