* /control/dns_config: allow all valid bootstrap server notations

Close #1843

Squashed commit of the following:

commit cc82b373816b76a803d29e4baae18384aa0f8c67
Author: Simon Zolin <s.zolin@adguard.com>
Date:   Thu Aug 20 14:20:35 2020 +0300

    * /control/dns_config: allow all valid bootstrap server notations

    * use dnsproxy v0.31.1
This commit is contained in:
Simon Zolin 2020-08-21 15:54:16 +03:00
parent 546a02b49e
commit eb3999a261
4 changed files with 20 additions and 7 deletions

View File

@ -93,6 +93,18 @@ func checkBlockingMode(req dnsConfigJSON) bool {
return true 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 // nolint(gocyclo) - we need to check each JSON field separately
func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) { func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
req := dnsConfigJSON{} req := dnsConfigJSON{}
@ -113,9 +125,9 @@ func (s *Server) handleSetConfig(w http.ResponseWriter, r *http.Request) {
} }
if js.Exists("bootstrap_dns") { if js.Exists("bootstrap_dns") {
for _, host := range req.Bootstraps { for _, boot := range req.Bootstraps {
if err := checkPlainDNS(host); err != nil { if err := checkBootstrap(boot); err != nil {
httpError(r, w, http.StatusBadRequest, "%s can not be used as bootstrap dns cause: %s", host, err) httpError(r, w, http.StatusBadRequest, "%s can not be used as bootstrap dns cause: %s", boot, err)
return return
} }
} }

2
go.mod
View File

@ -3,7 +3,7 @@ module github.com/AdguardTeam/AdGuardHome
go 1.14 go 1.14
require ( 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/golibs v0.4.2
github.com/AdguardTeam/urlfilter v0.11.2 github.com/AdguardTeam/urlfilter v0.11.2
github.com/NYTimes/gziphandler v1.1.1 github.com/NYTimes/gziphandler v1.1.1

4
go.sum
View File

@ -1,5 +1,5 @@
github.com/AdguardTeam/dnsproxy v0.30.1 h1:SnsL5kM/eFTrtLLdww1EePOhVDZTWzMkse+5tadGhvc= github.com/AdguardTeam/dnsproxy v0.31.1 h1:kYnlLGM20LjPlEH+fqwCy08gMP5EVdp1FRaJ7uzyIJ0=
github.com/AdguardTeam/dnsproxy v0.30.1/go.mod h1:hOYFV9TW+pd5XKYz7KZf2FFD8SvSPqjyGTxUae86s58= 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.0/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=
github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o= github.com/AdguardTeam/golibs v0.4.2 h1:7M28oTZFoFwNmp8eGPb3ImmYbxGaJLyQXeIFVHjME0o=
github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4= github.com/AdguardTeam/golibs v0.4.2/go.mod h1:skKsDKIBB7kkFflLJBpfGX+G8QFTx0WKUzB6TIgtUj4=

View File

@ -142,7 +142,8 @@ func TestHome(t *testing.T) {
assert.Equal(t, http.StatusOK, resp.StatusCode) assert.Equal(t, http.StatusOK, resp.StatusCode)
// test DNS over UDP // 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") addrs, err := r.LookupIPAddr(context.TODO(), "static.adguard.com")
assert.Nil(t, err) assert.Nil(t, err)
haveIP := len(addrs) != 0 haveIP := len(addrs) != 0