]> granicus.if.org Git - pdns/commitdiff
auth-api: restrict creation of OPT and TSIG rrsets
authorCharles-Henri Bruyand <charles-henri.bruyand@open-xchange.com>
Wed, 16 May 2018 15:02:02 +0000 (17:02 +0200)
committerPieter Lexis <pieter.lexis@powerdns.com>
Wed, 23 May 2018 10:32:04 +0000 (12:32 +0200)
(cherry picked from commit a53b24d006304e00d9c865629f6f0de7e30afbc2)

pdns/ws-auth.cc
regression-tests.api/test_Zones.py

index 61bd9e2570eeca262c6eada70c0b6aab67eee986..052ff362a06170d65126286a76e31c85b03c3250 100644 (file)
@@ -1658,6 +1658,10 @@ static void patchZone(HttpRequest* req, HttpResponse* resp) {
         if (!qname.isPartOf(zonename) && qname != zonename)
           throw ApiException("RRset "+qname.toString()+" IN "+qtype.getName()+": Name is out of zone");
 
+        if (qtype.getCode() == QType::OPT || qtype.getCode() == QType::TSIG) {
+          throw ApiException("RRset "+qname.toString()+" IN "+stringFromJson(rrset, "type")+": invalid type given");
+        }
+
         bool replace_records = rrset["records"].is_array();
         bool replace_comments = rrset["comments"].is_array();
 
index 6d4c7f845be531777d5592122bd53fa1140e1bd5..b27b2e808b5114ed06849da65800aaeb538c9df9 100644 (file)
@@ -892,6 +892,29 @@ fred   IN  A      192.168.0.4
         data = self.session.get(self.url("/api/v1/servers/localhost/zones/" + name)).json()
         self.assertEquals(get_rrset(data, name, 'MX')['records'], rrset['records'])
 
+    def test_zone_rr_update_opt(self):
+        name, payload, zone = self.create_zone()
+        # do a replace (= update)
+        rrset = {
+            'changetype': 'replace',
+            'name': name,
+            'type': 'OPT',
+            'ttl': 3600,
+            'records': [
+                {
+                    "content": "9",
+                    "disabled": False
+                }
+            ]
+        }
+        payload = {'rrsets': [rrset]}
+        r = self.session.patch(
+            self.url("/api/v1/servers/localhost/zones/" + name),
+            data=json.dumps(payload),
+            headers={'content-type': 'application/json'})
+        self.assertEquals(r.status_code, 422)
+        self.assertIn('OPT: invalid type given', r.json()['error'])
+
     def test_zone_rr_update_multiple_rrsets(self):
         name, payload, zone = self.create_zone()
         rrset1 = {