mirror of
https://github.com/mjl-/mox.git
synced 2025-04-21 21:40:01 +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
2 changed files with 15 additions and 1 deletions
|
@ -20,6 +20,7 @@ var (
|
|||
errTrailingDot = errors.New("dns name has trailing dot")
|
||||
errUnderscore = errors.New("domain name with underscore")
|
||||
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
|
||||
|
@ -96,6 +97,12 @@ func ParseDomain(s string) (Domain, error) {
|
|||
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)
|
||||
if err != nil {
|
||||
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) {
|
||||
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)
|
||||
ts.smtpErr(err, &smtpclient.Error{Permanent: true, Code: smtp.C550MailboxUnavail, Secode: smtp.SeAddr1UnknownDestMailbox1})
|
||||
})
|
||||
|
|
Loading…
Reference in a new issue