From eb3999a261de41fb3a99917638ae476563b1028a Mon Sep 17 00:00:00 2001 From: Simon Zolin Date: Fri, 21 Aug 2020 15:54:16 +0300 Subject: [PATCH] * /control/dns_config: allow all valid bootstrap server notations Close #1843 Squashed commit of the following: commit cc82b373816b76a803d29e4baae18384aa0f8c67 Author: Simon Zolin Date: Thu Aug 20 14:20:35 2020 +0300 * /control/dns_config: allow all valid bootstrap server notations * use dnsproxy v0.31.1 --- dnsforward/dnsforward_http.go | 18 +++++++++++++++--- go.mod | 2 +- go.sum | 4 ++-- home/home_test.go | 3 ++- 4 files changed, 20 insertions(+), 7 deletions(-) diff --git a/dnsforward/dnsforward_http.go b/dnsforward/dnsforward_http.go index b3caecbc..63e82d95 100644 --- a/dnsforward/dnsforward_http.go +++ b/dnsforward/dnsforward_http.go @@ -93,6 +93,18 @@ func checkBlockingMode(req dnsConfigJSON) bool { return true } +// Validate bootstrap server address +func checkBootstrap(addr string) error { + if addr == "" { // additional check is required because NewResolver() allows empty address + return fmt.Errorf("invalid bootstrap server address: empty") + } + _, err := upstream.NewResolver(addr, 0) + if err != nil { + return fmt.Errorf("invalid bootstrap server address: %s", err) + } + return nil +} + // nolint(gocyclo) - we need to check each JSON field separately func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) { req := dnsConfigJSON{} @@ -113,9 +125,9 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) { } if js.Exists("bootstrap_dns") { - for _, host := range req.Bootstraps { - if err := checkPlainDNS(host); err != nil { - httpError(r, w, http.StatusBadRequest, "%s can not be used as bootstrap dns cause: %s", host, err) + for _, boot := range req.Bootstraps { + if err := checkBootstrap(boot); err != nil { + httpError(r, w, http.StatusBadRequest, "%s can not be used as bootstrap dns cause: %s", boot, err) return } } diff --git a/go.mod b/go.mod index 7bae4404..c9d192c1 100644 --- a/go.mod +++ b/go.mod @@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome go 1.14 require ( - github.com/AdguardTeam/dnsproxy v0.30.1 + github.com/AdguardTeam/dnsproxy v0.31.1 github.com/AdguardTeam/golibs v0.4.2 github.com/AdguardTeam/urlfilter v0.11.2 github.com/NYTimes/gziphandler v1.1.1 diff --git a/go.sum b/go.sum index d043c5ec..d6c7f340 100644 --- a/go.sum +++ b/go.sum @@ -1,5 +1,5 @@ -github.com/AdguardTeam/dnsproxy v0.30.1 h1:SnsL5kM/eFTrtLLdww1EePOhVDZTWzMkse+5tadGhvc= -github.com/AdguardTeam/dnsproxy v0.30.1/go.mod h1:hOYFV9TW+pd5XKYz7KZf2FFD8SvSPqjyGTxUae86s58= +github.com/AdguardTeam/dnsproxy v0.31.1 h1:kYnlLGM20LjPlEH+fqwCy08gMP5EVdp1FRaJ7uzyIJ0= +github.com/AdguardTeam/dnsproxy v0.31.1/go.mod h1:hOYFV9TW+pd5XKYz7KZf2FFD8SvSPqjyGTxUae86s58= github.com/AdguardTeam/golibs v0.4.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o= github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= diff --git a/home/home_test.go b/home/home_test.go index 89901387..0868cb71 100644 --- a/home/home_test.go +++ b/home/home_test.go @@ -142,7 +142,8 @@ func TestHome(t *testing.T) { assert.Equal(t, http.StatusOK, resp.StatusCode) // test DNS over UDP - r := upstream.NewResolver("127.0.0.1:5354", 3*time.Second) + r, err := upstream.NewResolver("127.0.0.1:5354", 3*time.Second) + assert.Nil(t, err) addrs, err := r.LookupIPAddr(context.TODO(), "static.adguard.com") assert.Nil(t, err) haveIP := len(addrs) != 0