* /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
}
// 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
}
}