]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Don't accept sub-paths of configured DoH URLs
authorRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 23 Jan 2020 14:21:24 +0000 (15:21 +0100)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Thu, 23 Jan 2020 15:10:55 +0000 (16:10 +0100)
pdns/dnsdistdist/doh.cc
regression-tests.dnsdist/test_DOH.py

index 9b29e650b810bc5179e35964bbfa475ea1cdc483..f45ae902c985e098dbc7cf79f1e350286a48eee3 100644 (file)
@@ -199,6 +199,7 @@ struct DOHServerConfig
   }
 
   LocalHolders holders;
+  std::unordered_set<std::string> paths;
   h2o_globalconf_t h2o_config;
   h2o_context_t h2o_ctx;
   DOHAcceptContext* accept_ctx{nullptr};
@@ -687,6 +688,12 @@ try
 
   string path(req->path.base, req->path.len);
 
+  string pathOnly(req->path_normalized.base, req->path_normalized.len);
+  if (dsc->paths.count(pathOnly) == 0) {
+    h2o_send_error_404(req, "Not Found", "there is no endpoint configured for this path", 0);
+    return 0;
+  }
+
   for (const auto& entry : dsc->df->d_responsesMap) {
     if (entry->matches(path)) {
       const auto& customHeaders = entry->getHeaders();
@@ -1195,6 +1202,7 @@ try
 
   for(const auto& url : df->d_urls) {
     register_handler(hostconf, url.c_str(), doh_handler);
+    dsc->paths.insert(url);
   }
 
   h2o_context_init(&dsc->h2o_ctx, h2o_evloop_create(), &dsc->h2o_config);
index bb27fde2861e192435a9b3eecaf2de0f24278c0b..80cc0a294c519e23d40f950d39fafe3ecea694ef 100644 (file)
@@ -166,7 +166,7 @@ class TestDOH(DNSDistDOHTest):
     _config_template = """
     newServer{address="127.0.0.1:%s"}
 
-    addDOHLocal("127.0.0.1:%s", "%s", "%s", { "/" }, {customResponseHeaders={["access-control-allow-origin"]="*",["user-agent"]="derp",["UPPERCASE"]="VaLuE"}})
+    addDOHLocal("127.0.0.1:%s", "%s", "%s", { "/", "/coffee", "/PowerDNS", "/PowerDNS2", "/PowerDNS-999" }, {customResponseHeaders={["access-control-allow-origin"]="*",["user-agent"]="derp",["UPPERCASE"]="VaLuE"}})
     dohFE = getDOHFrontend(0)
     dohFE:setResponsesMap({newDOHResponseMapEntry('^/coffee$', 418, 'C0FFEE', {['FoO']='bar'})})
 
@@ -505,6 +505,12 @@ class TestDOH(DNSDistDOHTest):
         self.checkQueryEDNSWithoutECS(expectedQuery, receivedQuery)
         self.assertEquals(response, receivedResponse)
 
+        # this path is not in the URLs map and should lead to a 404
+        (_, receivedResponse) = self.sendDOHQuery(self._dohServerPort, self._serverName, self._dohBaseURL + "PowerDNS/something", query, caFile=self._caCert, useQueue=False, rawResponse=True)
+        self.assertTrue(receivedResponse)
+        self.assertEquals(receivedResponse, b'there is no endpoint configured for this path')
+        self.assertEquals(self._rcode, 404)
+
     def testHTTPPathRegex(self):
         """
         DOH: HTTPPathRegex