Skip to content

Commit 12c651a

Browse files
committed
Ensure email domain has valid MX record
Signed-off-by: Tamal Saha <[email protected]>
1 parent 26d0a41 commit 12c651a

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

pkg/server/types.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222

2323
"github.com/avct/uasurfer"
2424
"github.com/google/uuid"
25+
"golang.org/x/net/publicsuffix"
2526
. "gomodules.xyz/email-providers"
2627
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2728
)
@@ -73,6 +74,13 @@ func (form LicenseForm) Validate() error {
7374
if agree, _ := strconv.ParseBool(form.Tos); !agree {
7475
return fmt.Errorf("user must agree to terms and services")
7576
}
77+
if apex, err := publicsuffix.EffectiveTLDPlusOne(Domain(form.Email)); err != nil {
78+
return err
79+
} else {
80+
if err := DomainWithMXRecord(apex); err != nil {
81+
return err
82+
}
83+
}
7684
return nil
7785
}
7886

pkg/server/utils.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ limitations under the License.
1717
package server
1818

1919
import (
20+
"errors"
2021
"fmt"
2122
"net"
2223
"net/http"
@@ -29,6 +30,17 @@ import (
2930
"k8s.io/klog/v2"
3031
)
3132

33+
func DomainWithMXRecord(domain string) error {
34+
records, err := net.LookupMX(domain)
35+
if err != nil {
36+
return err
37+
}
38+
if len(records) == 0 {
39+
return errors.New("no MX records")
40+
}
41+
return nil
42+
}
43+
3244
func IsEnterpriseProduct(product string) bool {
3345
return strings.HasSuffix(strings.ToLower(product), "-enterprise")
3446
}

0 commit comments

Comments
 (0)