mirror of https://github.com/v2ray/v2ray-core
allow dns modification only from trusted tags
parent
dd81fc6f6a
commit
a540d7dc99
|
@ -68,6 +68,11 @@ func (this *DnsCache) cleanup() {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (this *DnsCache) Add(context app.Context, domain string, ip net.IP) {
|
func (this *DnsCache) Add(context app.Context, domain string, ip net.IP) {
|
||||||
|
callerTag := context.CallerTag()
|
||||||
|
if !this.config.IsTrustedSource(callerTag) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
this.RLock()
|
this.RLock()
|
||||||
entry, found := this.cache[domain]
|
entry, found := this.cache[domain]
|
||||||
this.RUnlock()
|
this.RUnlock()
|
||||||
|
|
|
@ -5,6 +5,7 @@ import (
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/v2ray/v2ray-core/app/dns"
|
"github.com/v2ray/v2ray-core/app/dns"
|
||||||
|
dnstesting "github.com/v2ray/v2ray-core/app/dns/testing"
|
||||||
apptesting "github.com/v2ray/v2ray-core/app/testing"
|
apptesting "github.com/v2ray/v2ray-core/app/testing"
|
||||||
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
|
netassert "github.com/v2ray/v2ray-core/common/net/testing/assert"
|
||||||
v2testing "github.com/v2ray/v2ray-core/testing"
|
v2testing "github.com/v2ray/v2ray-core/testing"
|
||||||
|
@ -14,11 +15,19 @@ func TestDnsAdd(t *testing.T) {
|
||||||
v2testing.Current(t)
|
v2testing.Current(t)
|
||||||
|
|
||||||
domain := "v2ray.com"
|
domain := "v2ray.com"
|
||||||
cache := dns.NewCache(nil)
|
cache := dns.NewCache(&dnstesting.CacheConfig{
|
||||||
|
TrustedTags: map[string]bool{
|
||||||
|
"testtag": true,
|
||||||
|
},
|
||||||
|
})
|
||||||
ip := cache.Get(&apptesting.Context{}, domain)
|
ip := cache.Get(&apptesting.Context{}, domain)
|
||||||
netassert.IP(ip).IsNil()
|
netassert.IP(ip).IsNil()
|
||||||
|
|
||||||
cache.Add(&apptesting.Context{}, domain, []byte{1, 2, 3, 4})
|
cache.Add(&apptesting.Context{CallerTagValue: "notvalidtag"}, domain, []byte{1, 2, 3, 4})
|
||||||
|
ip = cache.Get(&apptesting.Context{}, domain)
|
||||||
|
netassert.IP(ip).IsNil()
|
||||||
|
|
||||||
|
cache.Add(&apptesting.Context{CallerTagValue: "testtag"}, domain, []byte{1, 2, 3, 4})
|
||||||
ip = cache.Get(&apptesting.Context{}, domain)
|
ip = cache.Get(&apptesting.Context{}, domain)
|
||||||
netassert.IP(ip).Equals(net.IP([]byte{1, 2, 3, 4}))
|
netassert.IP(ip).Equals(net.IP([]byte{1, 2, 3, 4}))
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
package testing
|
||||||
|
|
||||||
|
type CacheConfig struct {
|
||||||
|
TrustedTags map[string]bool
|
||||||
|
}
|
||||||
|
|
||||||
|
func (this *CacheConfig) IsTrustedSource(tag string) bool {
|
||||||
|
_, found := this.TrustedTags[tag]
|
||||||
|
return found
|
||||||
|
}
|
Loading…
Reference in New Issue