fix: use sld match instead of string suffix match
This commit is contained in:
parent
5f42911d12
commit
3be40025e0
13
hosts.go
13
hosts.go
@ -104,16 +104,25 @@ type RedisHosts struct {
|
|||||||
func (r *RedisHosts) Get(domain string) ([]string, bool) {
|
func (r *RedisHosts) Get(domain string) ([]string, bool) {
|
||||||
r.mu.RLock()
|
r.mu.RLock()
|
||||||
defer r.mu.RUnlock()
|
defer r.mu.RUnlock()
|
||||||
|
|
||||||
domain = strings.ToLower(domain)
|
domain = strings.ToLower(domain)
|
||||||
ip, ok := r.hosts[domain]
|
ip, ok := r.hosts[domain]
|
||||||
if ok {
|
if ok {
|
||||||
return strings.Split(ip, ","), true
|
return strings.Split(ip, ","), true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sld, err := publicsuffix.EffectiveTLDPlusOne(domain)
|
||||||
|
if err != nil {
|
||||||
|
return nil, false
|
||||||
|
}
|
||||||
|
|
||||||
for host, ip := range r.hosts {
|
for host, ip := range r.hosts {
|
||||||
if strings.HasPrefix(host, "*.") {
|
if strings.HasPrefix(host, "*.") {
|
||||||
upperLevelDomain := strings.Split(host, "*.")[1]
|
old, err := publicsuffix.EffectiveTLDPlusOne(host)
|
||||||
if strings.HasSuffix(domain, upperLevelDomain) {
|
if err != nil {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
if sld == old {
|
||||||
return strings.Split(ip, ","), true
|
return strings.Split(ip, ","), true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user