mirror of
https://github.com/golang/net.git
synced 2026-03-31 10:27:08 +09:00
publicsuffix: don't treat ip addresses as domain names
While IP addresses are not domain names and probably shouldn't be passed to these functions at all, it seems wrong to have it handle IPv4 and IPv6 differently. Fixes golang/go#32979 Change-Id: Id321a08b552c11d990c3966636b64793f762143f Reviewed-on: https://go-review.googlesource.com/c/net/+/715100 Reviewed-by: Michael Pratt <mpratt@google.com> LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com> Reviewed-by: Damien Neil <dneil@google.com>
This commit is contained in:
@@ -51,6 +51,7 @@ package publicsuffix // import "golang.org/x/net/publicsuffix"
|
||||
import (
|
||||
"fmt"
|
||||
"net/http/cookiejar"
|
||||
"net/netip"
|
||||
"strings"
|
||||
)
|
||||
|
||||
@@ -84,6 +85,10 @@ func (list) String() string {
|
||||
// domains like "foo.appspot.com" can be found at
|
||||
// https://wiki.mozilla.org/Public_Suffix_List/Use_Cases
|
||||
func PublicSuffix(domain string) (publicSuffix string, icann bool) {
|
||||
if _, err := netip.ParseAddr(domain); err == nil {
|
||||
return domain, false
|
||||
}
|
||||
|
||||
lo, hi := uint32(0), uint32(numTLD)
|
||||
s, suffix, icannNode, wildcard := domain, len(domain), false, false
|
||||
loop:
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
package publicsuffix
|
||||
|
||||
import (
|
||||
"net/netip"
|
||||
"sort"
|
||||
"strings"
|
||||
"testing"
|
||||
@@ -85,6 +86,11 @@ var publicSuffixTestCases = []struct {
|
||||
// Empty string.
|
||||
{"", "", false},
|
||||
|
||||
// IP addresses don't have a domain hierarchy
|
||||
{"192.0.2.0", "192.0.2.0", false},
|
||||
{"::ffff:192.0.2.0", "::ffff:192.0.2.0", false},
|
||||
{"2001:db8::", "2001:db8::", false},
|
||||
|
||||
// The .ao rules are:
|
||||
// ao
|
||||
// ed.ao
|
||||
@@ -332,6 +338,10 @@ type slowPublicSuffixRule struct {
|
||||
// This function returns the public suffix, not the registrable domain, and so
|
||||
// it stops after step 6.
|
||||
func slowPublicSuffix(domain string) (string, bool) {
|
||||
if _, err := netip.ParseAddr(domain); err == nil {
|
||||
return domain, false
|
||||
}
|
||||
|
||||
match := func(rulePart, domainPart string) bool {
|
||||
switch rulePart[0] {
|
||||
case '*':
|
||||
|
||||
Reference in New Issue
Block a user