Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check via zlint if a domain's TLD is valid #7943

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions iana/iana.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,14 @@ import (
"fmt"

"github.com/weppos/publicsuffix-go/publicsuffix"
zlintutil "github.com/zmap/zlint/v3/util"
)

// ExtractSuffix returns the public suffix of the domain using only the "ICANN"
// section of the Public Suffix List database.
// If the domain does not end in a suffix that belongs to an IANA-assigned
// domain, ExtractSuffix returns an error.
// It confirms with zlint's TLD list.
func ExtractSuffix(name string) (string, error) {
if name == "" {
return "", fmt.Errorf("Blank name argument passed to ExtractSuffix")
Expand All @@ -28,5 +30,9 @@ func ExtractSuffix(name string) (string, error) {
suffix = name
}

if !zlintutil.IsInTLDMap(suffix) {
return "", fmt.Errorf("Domain %s has an unknown TLD %s", name, suffix)
}

return suffix, nil
}
Loading