mileusna / spf

Go package for SPF record check
MIT License
13 stars 8 forks source link

Another case of panic of CNAME #6

Open devl00p opened 1 year ago

devl00p commented 1 year ago

Hello,

I bumped into a case similar to issue #5 but not caugth in v0.9.5.

It would be nice to have the same warning.

Traceback:

panic: interface conversion: dns.RR is *dns.CNAME, not *dns.MX

goroutine 1 [running]:
github.com/mileusna/spf.lookupMX({0xc00003777a?, 0x47fb89?})
        /home/nico/go/pkg/mod/github.com/mileusna/spf@v0.9.5/resolver.go:112 +0x145
github.com/mileusna/spf.(*check).checkMX(0x868138?, {0xc0003eb380, 0x10, 0x10}, {0xc00003777a?, 0x4bdc26?}, {0x0, 0x0}, {0x0, 0x0})
        /home/nico/go/pkg/mod/github.com/mileusna/spf@v0.9.5/spf.go:207 +0x66
github.com/mileusna/spf.(*check).checkHost(0xc00052fcc8, {0xc0003eb380, 0x10, 0x10}, {0xc0000bbe6b, 0xb}, {0xc0000bbf80, 0x11})
        /home/nico/go/pkg/mod/github.com/mileusna/spf@v0.9.5/spf.go:85 +0x47b
github.com/mileusna/spf.CheckHost({0xc0003eb380?, 0x8?, 0xc00052fd90?}, {0xc0000bbe6b?, 0x1?}, {0xc0000bbf80?, 0x7b47c0?}, {0x0?, 0xc00039fda8?})
        /home/nico/go/pkg/mod/github.com/mileusna/spf@v0.9.5/spf.go:60 +0xb0
main.main()
        /home/nico/dev/checkspf/main.go:124 +0x435
exit status 2

Code:

package main

import (
    "net"
    "fmt"

    "github.com/mileusna/spf"
)

func main() {
    ip := net.ParseIP("123.123.123.123")
    r := spf.CheckHost(ip, "annonces.fr", "name@annonces.fr", "")
    fmt.Printf("status: %s\n", r)
}

SPF is the following:

v=spf1 mx:www.annonces.fr mx:smtp.triplemind.com mx:mx.fluxgrid.net ?all

Thank you for your help

Regards

devl00p commented 1 year ago

And another case, not in mx (domain lherbergement.fr):

v=spf1 include:spf.protection.outlook.com include:_spf.google.com include:_spf.afi-sa.net include:spf.ecollectivites.fr ip4:77.159.229.30 ip4:77.159.229.23 ip4:135.125.126.160/27 -all
mileusna commented 1 year ago

Yes, it have that same assumption that the record is not CNAME on other places as well. I will take a look.