Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const getFirstSecureResponse = (result, type) => {
const repliesTree = result.replies_tree;
// Validate that there is a reply with an answer.
if (!repliesTree || !repliesTree.length
|| !repliesTree[0].answer
|| !repliesTree[0].answer.length) {
return "empty answer list for type " + type;
}
const reply = repliesTree[0];
// Ensure the reply is secure.
if (reply.dnssec_status !== getdns.DNSSEC_SECURE) {
return "insecure reply for type " + type;
}
let answers = reply.answer;
// Get the records of that type.
answers = answers.filter((answer) => {
return answer.type === type;
});
if (!answers.length) {
return "no answers of type " + type;
}
return answers[0];
};
const dnssecSecureReplies = replies.filter(function(reply) {
return reply.dnssec_status === getdns.DNSSEC_SECURE;
});