diff --git a/CHANGES b/CHANGES index f6871d583..8dff1b05d 100644 --- a/CHANGES +++ b/CHANGES @@ -2095,4 +2095,5 @@ * Update docker to 19.03.12 * Focal support * Fix sorting of user listing in the UI +* namecheap: fix crash when server returns invalid response diff --git a/src/dns/namecheap.js b/src/dns/namecheap.js index b7ffcceee..8c114486b 100644 --- a/src/dns/namecheap.js +++ b/src/dns/namecheap.js @@ -78,13 +78,11 @@ function getInternal(dnsConfig, zoneName, subdomain, type, callback) { return callback(new BoxError(BoxError.EXTERNAL_ERROR, errorMessage)); } - if (!tmp.CommandResponse[0]) return callback(new BoxError(BoxError.EXTERNAL_ERROR, 'Invalid response')); - if (!tmp.CommandResponse[0].DomainDNSGetHostsResult[0]) return callback(new BoxError(BoxError.EXTERNAL_ERROR, 'Invalid response')); - - var hosts = result.ApiResponse.CommandResponse[0].DomainDNSGetHostsResult[0].host.map(function (h) { - return h['$']; - }); + const host = safe.query(tmp, 'CommandResponse[0].DomainDNSGetHostsResult[0].host'); + if (!host) return callback(new BoxError(BoxError.EXTERNAL_ERROR, `Invalid response: ${JSON.stringify(tmp)}`)); + if (!Array.isArray(host)) return callback(new BoxError(BoxError.EXTERNAL_ERROR, `host is not an array: ${JSON.stringify(tmp)}`)); + const hosts = host.map(h => h['$']); callback(null, hosts); }); });