From eb710716a0a47474fdf372572a605e6a121c9307 Mon Sep 17 00:00:00 2001 From: Roland Shoemaker Date: Tue, 18 Aug 2015 14:14:26 -0700 Subject: [PATCH] Quick subdomain fix --- policy/policy-data.go | 2 +- policy/policy-data_test.go | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/policy/policy-data.go b/policy/policy-data.go index 7c66162a8..087d0f947 100644 --- a/policy/policy-data.go +++ b/policy/policy-data.go @@ -117,7 +117,7 @@ func (padb *PolicyAuthorityDatabaseImpl) CheckRules(host string, requireWhitelis for _, r := range rules { switch r.Type { case blacklisted: - if strings.HasPrefix(host, r.Host) { + if strings.HasPrefix(host, r.Host+".") || host == r.Host { bRules = append(bRules, r.Host) } case whitelisted: diff --git a/policy/policy-data_test.go b/policy/policy-data_test.go index fb51d0c8f..64cbc8709 100644 --- a/policy/policy-data_test.go +++ b/policy/policy-data_test.go @@ -56,4 +56,9 @@ func TestGet(t *testing.T) { test.AssertNotError(t, err, "Hostname should be whitelisted") err = p.CheckRules("a.a.com", true) test.AssertError(t, err, "Hostname isn't explicitly whitelisted") + + err = p.CheckRules("ab.com", false) + test.AssertNotError(t, err, "Hostname should not be blacklisted") + err = p.CheckRules(".b.com", false) + test.AssertError(t, err, "Hostname should be blacklisted") }