]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Move to a string instead of a boolean flag, as suggested by zeha
authorOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 7 May 2026 12:20:38 +0000 (14:20 +0200)
committerOtto Moerbeek <otto.moerbeek@open-xchange.com>
Thu, 7 May 2026 12:20:38 +0000 (14:20 +0200)
Signed-off-by: Otto Moerbeek <otto.moerbeek@open-xchange.com>
builder
docs/settings.rst
pdns/auth-main.cc
pdns/recursordist/docs/upgrade.rst
pdns/recursordist/rec-rust-lib/rust/src/web.rs
pdns/recursordist/rec-rust-lib/table.py
pdns/recursordist/ws-recursor.cc
pdns/webserver.cc
pdns/webserver.hh
pdns/ws-auth.cc

diff --git a/builder b/builder
index 16bc1604c48821c12b708d7afa88d9612ebdd0da..f2c8c68dccb142152d8e2120b29e597e24222ddc 160000 (submodule)
--- a/builder
+++ b/builder
@@ -1 +1 @@
-Subproject commit 16bc1604c48821c12b708d7afa88d9612ebdd0da
+Subproject commit f2c8c68dccb142152d8e2120b29e597e24222ddc
index d9e0639096a7cd6916d95844228715ffd8de0e55..aae2ba21bc2b860aa3bf295147d488b8300cda1d 100644 (file)
@@ -2261,10 +2261,10 @@ If the webserver should print arguments.
 -----------------------------------------
 .. versionadded:: 5.1.0
 
--  Boolean
--  Default: no
+-  String
+-  Default: empty
 
-If the webserver should allow cross origin requests.
+The value if the access-control-allow-origin HTTP header to include. This header is not inluded if the value is empty.
 
 .. _setting-write-pid:
 
index 0b8e72af1e978812f2c5bca712611a67d88c26c4..fd56d6e6caffe3b7792849047aefef01660f3e8e 100644 (file)
@@ -255,7 +255,7 @@ static void declareArguments()
   ::arg().set("webserver-max-concurrent-connections", "Webserver/API maximum concurrent connections allowed") = "100";
   ::arg().set("webserver-connection-timeout", "Webserver/API request/response timeout in seconds") = "5";
   ::arg().setSwitch("webserver-hash-plaintext-credentials", "Whether to hash passwords and api keys supplied in plaintext, to prevent keeping the plaintext version in memory at runtime") = "no";
-  ::arg().setSwitch("webserver-allow-cross-origin-requests", "If the webserver should allow cross origin requests") = "no";
+  ::arg().set("webserver-allow-cross-origin-requests", "Webserver cross origin request header value") = "";
 
   ::arg().setSwitch("query-logging", "Hint backends that queries should be logged") = "no";
 
index 7431074c511b831e6430d2577e58b9099da3566a..d16352ab4f1107b45eed8b6eaa8c26bdeab65550 100644 (file)
@@ -22,7 +22,7 @@ New settings
 - The :ref:`setting-yaml-outgoing.max_bytesperq` setting has been introduced to limit the amount of incoming bytes per client query.
 - The :ref:`setting-yaml-recordcache.max_entry_size` setting has been introduced to limit the maximum size of a stored record set.
 - The :ref:`setting-yaml-packetcache.max_entry_size` setting has been introduced to limit the maximum size of a packet cache entry.
-- The :ref:`setting-yaml-webservice.allow_cross_origin_requests` setting has been introduced, default ``false``. This is a change of behaviour, as older versions do allow cross origin requests.
+- The :ref:`setting-yaml-webservice.allow_cross_origin_requests` setting has been introduced, default is not set. This is a change of behaviour, as older versions do set the access-control-allow-origin header.
 
 
 5.3.0 to 5.4.0
index 8cf5c29afc2dd35c561f04ff844b9a8a81a231e5..9c49b5b4611c0a8c2271fe6df3f194a09c5d6d7e 100644 (file)
@@ -176,11 +176,13 @@ fn api_wrapper(
     allow_password: bool,
 ) {
     // security headers
-    if ctx.allow_cross_origin_requests {
-        headers.insert(
-            header::ACCESS_CONTROL_ALLOW_ORIGIN,
-            header::HeaderValue::from_static("*"),
-        );
+    if !ctx.allow_cross_origin_requests.is_empty()  {
+        if let Ok(value) = header::HeaderValue::from_str(&ctx.allow_cross_origin_requests) {
+            headers.insert(
+                header::ACCESS_CONTROL_ALLOW_ORIGIN,
+                value,
+            );
+        }
     }
 
     // XXX AUDIT!
@@ -282,7 +284,7 @@ struct Context {
     logger: cxx::SharedPtr<rustmisc::Logger>,
     loglevel: rustmisc::LogLevel,
     max_request_size: u64,
-    allow_cross_origin_requests: bool,
+    allow_cross_origin_requests: String,
 }
 
 // Serve a file
@@ -458,10 +460,10 @@ fn collect_options(
     response.status = 200;
     methods.push(Method::OPTIONS.to_string());
 
-    if ctx.allow_cross_origin_requests {
+    if !ctx.allow_cross_origin_requests.is_empty() {
         response.headers.push(rustweb::KeyValue {
             key: String::from("access-control-allow-origin"),
-            value: String::from("*"),
+            value: String::from(ctx.allow_cross_origin_requests.clone()),
         });
     }
 
@@ -949,7 +951,7 @@ pub fn serveweb(
     logger: cxx::SharedPtr<rustmisc::Logger>,
     loglevel: rustmisc::LogLevel,
     max_request_size: u64,
-    allow_cross_origin_requests: bool,
+    allow_cross_origin_requests: String,
 ) -> Result<(), std::io::Error> {
     // Context, atomically reference counted
     let ctx = Arc::new(Context {
@@ -1260,7 +1262,7 @@ mod rustweb {
             logger: SharedPtr<Logger>,
             loglevel: LogLevel,
             max_request_size: u64,
-            allow_cross_origin_requests: bool,
+            allow_cross_origin_requests: String,
         ) -> Result<()>;
     }
 
index 36b57286eb6dff4d214d66acedbe76d0e34b2801..e202369d0accc7e370d09bbb15ea3fd9caa6901e 100644 (file)
@@ -278,11 +278,11 @@ Static pre-shared authentication key for access to the REST API. Since 4.6.0 the
     {
         "name": "allow_cross_origin_requests",
         "section": "webservice",
-        "type": LType.Bool,
-        "default": "false",
-        "help": "Whether the webserver allows cross-origin HTTP requests",
+        "type": LType.String,
+        "default": "",
+        "help": "Value of access-control-allow-origin HTTP header",
         "doc": """
-Whether the webserver allows cross-origin HTTP requests. This might allow a malicious website to read metrics provided by the API if a user’s browser has valid credentials cached for the webserver while the user visits the malicious website.
+Whether the webserver allows cross-origin HTTP requests. If set, the access-control-cross-origin HTTP header is included with the given value. This might allow a malicious website to read metrics provided by the API if a user’s browser has valid credentials cached for the webserver while the user visits the malicious website.
  """,
         "versionadded": "5.5.0",
     },
index a9cd69758bef2ab43e1cfdeac3f9a1c8d42d0bf5..bfb629d3d1d65ff6719275c3b1fe36c8db3b7825 100644 (file)
@@ -1203,7 +1203,7 @@ void serveRustWeb()
   // This function returns after having created the web server object that handles the requests.
   // That object and its runtime are associated with a Posix thread that waits until all tasks are
   // done, which normally never happens. See rec-rust-lib/rust/src/web.rs for details
-  pdns::rust::web::rec::serveweb(config, std::move(password), std::move(apikey), std::move(aclPtr), std::move(logPtr), loglevel, arg().asNum("webserver-max-request-size") * 1024ULL * 1024ULL, arg().mustDo("allow-cross-origin-requests"));
+  pdns::rust::web::rec::serveweb(config, std::move(password), std::move(apikey), std::move(aclPtr), std::move(logPtr), loglevel, arg().asNum("webserver-max-request-size") * 1024ULL * 1024ULL, arg()["allow-cross-origin-requests"]);
 }
 
 static void fromCxxToRust(const HttpResponse& cxxresp, pdns::rust::web::rec::Response& rustResponse)
index 45fb68b5cab97ac3c9b2bc83b8fd60c67f3ae812..2666334a52dfdc2bb40889dea98ef58069087a02 100644 (file)
@@ -147,8 +147,8 @@ void WebServer::registerBareHandler(const string& url, const HandlerFunction& ha
 
 void WebServer::apiWrapper(const WebServer::HandlerFunction& handler, HttpRequest* req, HttpResponse* resp, bool allowPassword)
 {
-  if (d_allow_cross_origin_requests) {
-      resp->headers["access-control-allow-origin"] = "*";
+  if (!d_allow_cross_origin_requests.empty()) {
+    resp->headers["access-control-allow-origin"] = d_allow_cross_origin_requests;
   }
 
   if (!d_apikey) {
@@ -629,8 +629,8 @@ WebServer::WebServer(std::shared_ptr<ConcurrentConnectionManager> ccm, string li
           return;
        }
        methods.emplace_back("OPTIONS");
-       if (allowCors) {
-         resp->headers["access-control-allow-origin"] = "*";
+       if (!allowCors.empty()) {
+         resp->headers["access-control-allow-origin"] = allowCors;
        }
        resp->headers["access-control-allow-headers"] = "Content-Type, X-API-Key";
        resp->headers["access-control-allow-methods"] = boost::algorithm::join(methods, ", ");
index f771bf2fb1a51b24c9e4f056b6143cde59aa3a7b..ef299a7593d1a6e2710eeac150ab87849062db92 100644 (file)
@@ -284,7 +284,7 @@ public:
     return d_loglevel;
   };
 
-  void setAllowCrossOriginRequests(bool value)
+  void setAllowCrossOriginRequests(const std::string& value)
   {
     d_allow_cross_origin_requests = value;
   }
@@ -315,7 +315,7 @@ protected:
   int d_connectiontimeout{5}; // in seconds
 
   NetmaskGroup d_acl;
-  bool d_allow_cross_origin_requests{false};
+  std::string d_allow_cross_origin_requests;
 
   const string d_logprefix = "[webserver] ";
 
index d8b2d6abb0207196285c559602aaca4993d3fe3b..92170b5e036f8a9c58125d91d03f682f3abdd0b5 100644 (file)
@@ -116,7 +116,7 @@ AuthWebServer::AuthWebServer() :
     d_ws->setMaxBodySize(::arg().asNum("webserver-max-bodysize"));
     d_ws->setConnectionTimeout(::arg().asNum("webserver-connection-timeout"));
 
-    d_ws->setAllowCrossOriginRequests(arg().mustDo("webserver-allow-cross-origin-requests"));
+    d_ws->setAllowCrossOriginRequests(arg()["webserver-allow-cross-origin-requests"]);
     d_ws->bind();
   }
 }