Skip to content

Commit 086cd68

Browse files
committed
Check via zlint if a domain's TLD is valid
If there's discrepencies between the PSL and Zlint TLD list, this will take the most conservative option of rejecting if either list doesn't have a TLD.
1 parent 7209bc2 commit 086cd68

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

iana/iana.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,14 @@ import (
44
"fmt"
55

66
"github.com/weppos/publicsuffix-go/publicsuffix"
7+
zlintutil "github.com/zmap/zlint/v3/util"
78
)
89

910
// ExtractSuffix returns the public suffix of the domain using only the "ICANN"
1011
// section of the Public Suffix List database.
1112
// If the domain does not end in a suffix that belongs to an IANA-assigned
1213
// domain, ExtractSuffix returns an error.
14+
// It confirms with zlint's TLD list.
1315
func ExtractSuffix(name string) (string, error) {
1416
if name == "" {
1517
return "", fmt.Errorf("Blank name argument passed to ExtractSuffix")
@@ -22,6 +24,10 @@ func ExtractSuffix(name string) (string, error) {
2224

2325
suffix := rule.Decompose(name)[1]
2426

27+
if !zlintutil.IsInTLDMap(suffix) {
28+
return "", fmt.Errorf("Domain %s has an invalid TLD %s", name, suffix)
29+
}
30+
2531
// If the TLD is empty, it means name is actually a suffix.
2632
// In fact, decompose returns an array of empty strings in this case.
2733
if suffix == "" {

0 commit comments

Comments
 (0)