From 24cd86ca0449fbb3ca861b846575093cb03ee661 Mon Sep 17 00:00:00 2001 From: Christian Hofstaedtler Date: Sat, 7 Feb 2015 13:38:33 +0100 Subject: [PATCH] API: Reject unknown types (TYPE0) Fixes #2130. --- pdns/ws-auth.cc | 4 ++++ regression-tests.api/test_Zones.py | 23 +++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/pdns/ws-auth.cc b/pdns/ws-auth.cc index baa35d020..d3f63a2b3 100644 --- a/pdns/ws-auth.cc +++ b/pdns/ws-auth.cc @@ -396,6 +396,10 @@ static void gatherRecords(const Value& container, vector& new rr.ttl = intFromJson(record, "ttl"); rr.disabled = boolFromJson(record, "disabled"); + if (rr.qtype.getCode() == 0) { + throw ApiException("Record "+rr.qname+"/"+stringFromJson(record, "type")+" is of unknown type"); + } + try { shared_ptr drc(DNSRecordContent::mastermake(rr.qtype.getCode(), 1, rr.content)); string tmp = drc->serialize(rr.qname); diff --git a/regression-tests.api/test_Zones.py b/regression-tests.api/test_Zones.py index 3e2087297..f05117efc 100644 --- a/regression-tests.api/test_Zones.py +++ b/regression-tests.api/test_Zones.py @@ -704,6 +704,29 @@ fred IN A 192.168.0.4 self.assertEquals(r.status_code, 422) self.assertIn('out of zone', r.json()['error']) + def test_rrset_unknown_type(self): + payload, zone = self.create_zone() + name = payload['name'] + rrset = { + 'changetype': 'replace', + 'name': name, + 'type': 'FAFAFA', + 'records': [ + { + "name": name, + "type": "FAFAFA", + "ttl": 3600, + "content": "4.3.2.1", + "disabled": False + } + ] + } + payload = {'rrsets': [rrset]} + r = self.session.patch(self.url("/servers/localhost/zones/" + name), data=json.dumps(payload), + headers={'content-type': 'application/json'}) + self.assertEquals(r.status_code, 422) + self.assertIn('unknown type', r.json()['error']) + def test_zone_rr_delete_out_of_zone(self): payload, zone = self.create_zone() name = payload['name'] -- 2.40.0