]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
Merge pull request #16360 from miodvallat/backport-16352-to-auth-5.0.x
authorMiod Vallat <miod.vallat@powerdns.com>
Mon, 27 Oct 2025 11:32:07 +0000 (12:32 +0100)
committerGitHub <noreply@github.com>
Mon, 27 Oct 2025 11:32:07 +0000 (12:32 +0100)
auth 5.0: backport "api: relax zone name check in view removal "

1  2 
pdns/ws-auth.cc

diff --cc pdns/ws-auth.cc
index c2e82b6b75b396778d65edfb866b3aedcb2fd4ff,e3de1d2abea3a7f44d8953e8ba21bd4b32c7f7a2..de089567b63dffe3c424e3ed2230bc05bb8cd691
@@@ -2743,21 -2742,15 +2743,19 @@@ static void apiServerViewsGET(HttpReque
  // POST /views/<view> + name in json adds ZoneName "name" to view "view"
  static void apiServerViewsPOST(HttpRequest* req, HttpResponse* resp)
  {
-   UeberBackend backend;
-   DomainInfo domainInfo;
    const auto& document = req->json();
+   // We can't use a ZoneData object here, as the zone being added to the
+   // view may not exist yet.
    ZoneName zonename = apiNameToZoneName(stringFromJson(document, "name"));
  
-   if (!backend.getDomainInfo(zonename, domainInfo)) {
-     throw ApiException("Zone " + zonename.toString() + " does not exist");
-   }
    std::string view{req->parameters["view"]};
 +  std::string error;
 +  if (!Check::validateViewName(view, error)) {
 +    throw ApiException(error);
 +  }
  
-   if (!domainInfo.backend->viewAddZone(view, zonename)) {
+   UeberBackend backend;
+   if (!backend.viewAddZone(view, zonename)) {
      throw ApiException("Failed to add " + zonename.toString() + " to view " + view);
    }
    // Notify zone cache of the new association
  // DELETE /views/<view>/<id>     removes ZoneName "id" from view "view"
  static void apiServerViewsDELETE(HttpRequest* req, HttpResponse* resp)
  {
-   ZoneData zoneData{req};
+   // We can't use a ZoneData object here, as the zone being removed from the
+   // view may no longer exist.
+   ZoneName zoneName(apiZoneIdToName(req->parameters["id"]));
    std::string view{req->parameters["view"]};
 +  std::string error;
 +  if (!Check::validateViewName(view, error)) {
 +    throw ApiException(error);
 +  }
  
-   if (!zoneData.domainInfo.backend->viewDelZone(view, zoneData.zoneName)) {
-     throw ApiException("Failed to remove " + zoneData.zoneName.toString() + " from view " + view);
+   UeberBackend backend;
+   if (!backend.viewDelZone(view, zoneName)) {
+     throw ApiException("Failed to remove " + zoneName.toString() + " from view " + view);
    }
    // Notify zone cache of the removed association
    bool emptyView{false};