Merge: * SB/PC: limit the number of hashes in request to 4
Close #1697 * commit '0ee3505e1f0cc3df78651f2f9cb393c5ff3df26e': * SB/PC: limit the number of hashes in request to 4
This commit is contained in:
commit
7a77dadab0
|
@ -146,6 +146,12 @@ func TestEtcHostsMatching(t *testing.T) {
|
|||
|
||||
// SAFE BROWSING
|
||||
|
||||
func TestSafeBrowsingHash(t *testing.T) {
|
||||
q, hashes := hostnameToHashParam("1.2.3.4.5.6")
|
||||
assert.Equal(t, "0132d0fa.b5413b4e.5fa067c1.e7f6c011.", q)
|
||||
assert.Equal(t, 4, len(hashes))
|
||||
}
|
||||
|
||||
func TestSafeBrowsing(t *testing.T) {
|
||||
d := NewForTest(&Config{SafeBrowsingEnabled: true}, nil)
|
||||
defer d.Close()
|
||||
|
|
|
@ -157,6 +157,7 @@ func (d *Dnsfilter) checkSafeSearch(host string) (Result, error) {
|
|||
}
|
||||
|
||||
// for each dot, hash it and add it to string
|
||||
// The maximum is 4 components: "a.b.c.d"
|
||||
func hostnameToHashParam(host string) (string, map[string]bool) {
|
||||
var hashparam bytes.Buffer
|
||||
hashes := map[string]bool{}
|
||||
|
@ -166,6 +167,18 @@ func hostnameToHashParam(host string) (string, map[string]bool) {
|
|||
tld = ""
|
||||
}
|
||||
curhost := host
|
||||
|
||||
nDots := 0
|
||||
for i := len(curhost) - 1; i >= 0; i-- {
|
||||
if curhost[i] == '.' {
|
||||
nDots++
|
||||
if nDots == 4 {
|
||||
curhost = curhost[i+1:] // "xxx.a.b.c.d" -> "a.b.c.d"
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for {
|
||||
if curhost == "" {
|
||||
// we've reached end of string
|
||||
|
|
Loading…
Reference in New Issue