mirror of
https://github.com/mjl-/mox.git
synced 2025-06-28 01:48:15 +03:00
in dns.ParseDomain, don't allow ipv4 addresses (ipv6 addresses were already rejected)
we are expecting a DNS domain name there. also highlighted a wrong test in the smtp server.
This commit is contained in:
parent
797c1cf9f0
commit
151729af08
@ -20,6 +20,7 @@ var (
|
|||||||
errTrailingDot = errors.New("dns name has trailing dot")
|
errTrailingDot = errors.New("dns name has trailing dot")
|
||||||
errUnderscore = errors.New("domain name with underscore")
|
errUnderscore = errors.New("domain name with underscore")
|
||||||
errIDNA = errors.New("idna")
|
errIDNA = errors.New("idna")
|
||||||
|
errIPNotName = errors.New("ip address while name required")
|
||||||
)
|
)
|
||||||
|
|
||||||
// Domain is a domain name, with one or more labels, with at least an ASCII
|
// Domain is a domain name, with one or more labels, with at least an ASCII
|
||||||
@ -96,6 +97,12 @@ func ParseDomain(s string) (Domain, error) {
|
|||||||
return Domain{}, errTrailingDot
|
return Domain{}, errTrailingDot
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// IPv4 addresses would be accepted by idna lookups. TLDs cannot be all numerical,
|
||||||
|
// so IP addresses are not valid DNS names.
|
||||||
|
if net.ParseIP(s) != nil {
|
||||||
|
return Domain{}, errIPNotName
|
||||||
|
}
|
||||||
|
|
||||||
ascii, err := idna.Lookup.ToASCII(s)
|
ascii, err := idna.Lookup.ToASCII(s)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Domain{}, fmt.Errorf("%w: to ascii: %v", errIDNA, err)
|
return Domain{}, fmt.Errorf("%w: to ascii: %v", errIDNA, err)
|
||||||
|
@ -530,7 +530,14 @@ func TestDelivery(t *testing.T) {
|
|||||||
|
|
||||||
ts.run(func(client *smtpclient.Client) {
|
ts.run(func(client *smtpclient.Client) {
|
||||||
mailFrom := "remote@example.org"
|
mailFrom := "remote@example.org"
|
||||||
rcptTo := "mjl@127.0.0.10"
|
rcptTo := "mjl@[127.0.0.10]"
|
||||||
|
err := client.Deliver(ctxbg, mailFrom, rcptTo, int64(len(deliverMessage)), strings.NewReader(deliverMessage), false, false, false)
|
||||||
|
ts.smtpErr(err, &smtpclient.Error{Permanent: true, Code: smtp.C550MailboxUnavail, Secode: smtp.SeAddr1UnknownDestMailbox1})
|
||||||
|
})
|
||||||
|
|
||||||
|
ts.run(func(client *smtpclient.Client) {
|
||||||
|
mailFrom := "remote@example.org"
|
||||||
|
rcptTo := "mjl@[IPv6:::1]"
|
||||||
err := client.Deliver(ctxbg, mailFrom, rcptTo, int64(len(deliverMessage)), strings.NewReader(deliverMessage), false, false, false)
|
err := client.Deliver(ctxbg, mailFrom, rcptTo, int64(len(deliverMessage)), strings.NewReader(deliverMessage), false, false, false)
|
||||||
ts.smtpErr(err, &smtpclient.Error{Permanent: true, Code: smtp.C550MailboxUnavail, Secode: smtp.SeAddr1UnknownDestMailbox1})
|
ts.smtpErr(err, &smtpclient.Error{Permanent: true, Code: smtp.C550MailboxUnavail, Secode: smtp.SeAddr1UnknownDestMailbox1})
|
||||||
})
|
})
|
||||||
|
Loading…
x
Reference in New Issue
Block a user