Skip to content

Commit

Permalink
dnsforward: preserve domain name case
Browse files Browse the repository at this point in the history
  • Loading branch information
ainar-g committed May 31, 2021
1 parent 78d47d8 commit 42a363c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ released by then.

### Fixed

- Domain name case in responses ([#3194]).
- Custom upstreams selection for clients with client IDs in DNS-over-TLS and
DNS-over-HTTP ([#3186]).
- Incorrect client-based filtering applying logic ([#2875]).
Expand All @@ -48,6 +49,7 @@ released by then.
[#3184]: https://github.com/AdguardTeam/AdGuardHome/issues/3184
[#3185]: https://github.com/AdguardTeam/AdGuardHome/issues/3185
[#3186]: https://github.com/AdguardTeam/AdGuardHome/issues/3186
[#3194]: https://github.com/AdguardTeam/AdGuardHome/issues/3194
[#3198]: https://github.com/AdguardTeam/AdGuardHome/issues/3198


Expand Down
8 changes: 5 additions & 3 deletions internal/dnsforward/access.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,10 +129,12 @@ func (a *accessCtx) IsBlockedIP(ip net.IP) (bool, string) {
}

// IsBlockedDomain - return TRUE if this domain should be blocked
func (a *accessCtx) IsBlockedDomain(host string) bool {
func (a *accessCtx) IsBlockedDomain(host string) (ok bool) {
a.lock.Lock()
_, ok := a.blockedHostsEngine.Match(host)
a.lock.Unlock()
defer a.lock.Unlock()

_, ok = a.blockedHostsEngine.Match(strings.ToLower(host))

return ok
}

Expand Down
9 changes: 3 additions & 6 deletions internal/dnsforward/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,10 @@ func (s *Server) beforeRequestHandler(_ *proxy.Proxy, d *proxy.DNSContext) (bool
}

if len(d.Req.Question) == 1 {
// 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, ".")
host := strings.TrimSuffix(d.Req.Question[0].Name, ".")
if s.access.IsBlockedDomain(host) {
log.Tracef("Domain %s is blocked by settings", host)
log.Tracef("domain %s is blocked by access settings", host)

return false, nil
}
}
Expand Down

0 comments on commit 42a363c

Please sign in to comment.