From f41d5b98670c94dd6f3b3e1c5ed47f961d6b8a98 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Tue, 11 May 2021 20:33:02 +0300 Subject: [PATCH] Pull request: 3115 domain case Merge in DNS/adguard-home from 3115-domain-case to master Updates #3115. Squashed commit of the following: commit 02b6d27d862b3e3dc2a17220cec35f0f18e31fb3 Author: Eugene Burkov Date: Tue May 11 19:56:06 2021 +0300 all: fix typos commit cdd1de64d5f79605b5fdcad5879204194856b083 Author: Eugene Burkov Date: Tue May 11 19:37:37 2021 +0300 dnsforward: fix disallowed domains case matching --- CHANGELOG.md | 6 ++++++ internal/dnsforward/access.go | 2 +- internal/dnsforward/filter.go | 6 +++++- 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b715104..42aef610 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -17,6 +17,12 @@ and this project adheres to ## [v0.106.3] - 2021-05-17 (APPROX.) --> +### Fixed + +- Disallowed domains are now case-insensitive ([#3115]). + +[#3115]: https://github.com/AdguardTeam/AdGuardHome/issues/3115 + ## [v0.106.2] - 2021-05-06 diff --git a/internal/dnsforward/access.go b/internal/dnsforward/access.go index dba0015d..f27eb667 100644 --- a/internal/dnsforward/access.go +++ b/internal/dnsforward/access.go @@ -47,7 +47,7 @@ func newAccessCtx(allowedClients, disallowedClients, blockedHosts []string) (a * b := &strings.Builder{} for _, s := range blockedHosts { - aghstrings.WriteToBuilder(b, s, "\n") + aghstrings.WriteToBuilder(b, strings.ToLower(s), "\n") } listArray := []filterlist.RuleList{} diff --git a/internal/dnsforward/filter.go b/internal/dnsforward/filter.go index b0e3ff89..93a72a86 100644 --- a/internal/dnsforward/filter.go +++ b/internal/dnsforward/filter.go @@ -20,7 +20,11 @@ func (s *Server) beforeRequestHandler(_ *proxy.Proxy, d *proxy.DNSContext) (bool } if len(d.Req.Question) == 1 { - host := strings.TrimSuffix(d.Req.Question[0].Name, ".") + // It's lowercased here since this handler is called before any + // other one. + name := strings.ToLower(d.Req.Question[0].Name) + d.Req.Question[0].Name = name + host := strings.TrimSuffix(name, ".") if s.access.IsBlockedDomain(host) { log.Tracef("Domain %s is blocked by settings", host) return false, nil