Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

caa

Package Overview
Dependencies
Maintainers
1
Versions
45
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

caa - npm Package Compare versions

Comparing version 6.0.1 to 6.0.2

102

index.js

@@ -7,4 +7,2 @@ "use strict";

const tldSet = new Set(tlds);
const defaults = {

@@ -19,42 +17,20 @@ ignoreTLDs: false,

function isTLD(name) {
return tldSet.has(name);
}
const tldSet = new Set(tlds);
const isTLD = name => tldSet.has(name);
const isWildcard = name => /\*/.test(name);
const parent = name => name.split(".").splice(1).join(".");
const selectServer = (servers, retries, tries) => servers[(tries - retries) % servers.length];
function isWildcard(name) {
return /\*/.test(name);
function normalizeName(name = "") {
name = name.toLowerCase();
return (name.endsWith(".") && name.length > 1) ? name.substring(0, name.length - 1) : name;
}
function normalizeName(name) {
name = (name || "").toLowerCase();
if (name.endsWith(".") && name.length > 1) {
name = name.substring(0, name.length - 1);
}
return name;
}
function selectServer(servers, retries, tries) {
return servers[(tries - retries) % servers.length];
}
function parent(name) {
return name.split(".").splice(1).join(".");
}
// resolve a CAA record, possibly via recursion
const resolve = async ({name, query, servers, port, recursions, retries, tries, ignoreTLDs}) => {
name = normalizeName(name);
if (!name) return [];
if (ignoreTLDs && isTLD(name)) return [];
if (recursions <= 0 || retries <= 0) return [];
if (!name) {
return [];
}
if (ignoreTLDs && isTLD(name)) {
return [];
}
if (recursions <= 0 || retries <= 0) {
return [];
}
// Given a request for a specific domain X, or a request for a wildcard

@@ -64,12 +40,7 @@ // domain *.X, the relevant record set R(X) is determined ...

const server = selectServer(servers, retries, tries);
let res;
try {
res = await query({questions: [{name, type: "CAA"}]}, port, server);
res = await query({questions: [{name, type: "CAA"}]}, port, selectServer(servers, retries, tries));
} catch {
if (retries <= 0) {
return [];
}
if (retries <= 0) return [];
retries -= 1;

@@ -80,6 +51,3 @@ return await resolve({name, query, servers, port, recursions, retries, tries, ignoreTLDs});

if (!res || (!res.answers && !["NXDOMAIN", "NOERROR"].includes(res.rcode))) {
if (retries <= 0) {
return [];
}
if (retries <= 0) return [];
retries -= 1;

@@ -92,9 +60,6 @@ return await resolve({name, query, servers, port, recursions, retries, tries, ignoreTLDs});

if (res && res.answers && res.answers.length) {
for (const answer of res.answers) {
if (!answer.type || !answer.data) continue;
if (!records[answer.type]) records[answer.type] = [];
records[answer.type].push({
name: answer.name,
data: answer.data,
});
for (const {name, type, data} of res.answers || {}) {
if (!name || !type || !data) continue;
if (!records[type]) records[type] = [];
records[type].push({name, data});
}

@@ -106,5 +71,3 @@ }

const caas = records.CAA.filter(record => record.name === name).map(record => record.data);
if (caas.length) {
return caas;
}
if (caas.length) return caas;
}

@@ -114,6 +77,6 @@

if (records.CNAME && records.CNAME.length) {
const dest = records.CNAME.filter(record => record.name === name)[0];
const dest = records.CNAME.find(record => record.name === name);
alias = dest.data;
} else if (records.DNAME && records.DNAME.length) {
const dest = records.DNAME.filter(record => record.name === name)[0];
const dest = records.DNAME.find(record => record.name === name);
alias = name.replace(dest.name, dest.data);

@@ -123,6 +86,4 @@ }

// If A(X) is not null, and CAA(A(X)) is not empty, then R(X) = CAA(A(X)), otherwise
if (alias) {
if (records.CAA && records.CAA.length) {
return records.CAA.filter(record => record.name === alias && record.data).map(record => record.data);
}
if (alias && records.CAA && records.CAA.length) {
return records.CAA.filter(record => record.name === alias && record.data).map(record => record.data);
}

@@ -140,6 +101,3 @@

const caa = module.exports = async (name, opts = {}) => {
if (typeof name !== "string") {
throw new Error(`Expected a string for 'name', got ${name}`);
}
if (typeof name !== "string") throw new Error(`Expected a string for 'name', got ${name}`);
name = normalizeName(name);

@@ -172,8 +130,4 @@

caa.matches = async (name, ca, opts = {}) => {
if (typeof name !== "string") {
throw new Error(`Expected a string for 'name', got ${name}`);
}
if (typeof ca !== "string") {
throw new Error(`Expected a string for 'ca', got ${ca}`);
}
if (typeof name !== "string") throw new Error(`Expected a string for 'name', got ${name}`);
if (typeof ca !== "string") throw new Error(`Expected a string for 'ca', got ${ca}`);

@@ -184,5 +138,3 @@ name = normalizeName(name);

const caas = await caa(name, opts);
if (!caas.length) {
return true;
}
if (!caas.length) return true;

@@ -189,0 +141,0 @@ const issueNames = caas

{
"name": "caa",
"version": "6.0.1",
"version": "6.0.2",
"description": "rfc6844-conform CAA record lookup and validation",

@@ -24,11 +24,11 @@ "author": "silverwind <me@silverwind.io>",

"dependencies": {
"dns-socket": "^4.2.0",
"tlds": "1.207.0"
"dns-socket": "^4.2.1",
"tlds": "1.210.0"
},
"devDependencies": {
"eslint": "7.2.0",
"eslint-config-silverwind": "13.4.6",
"jest": "26.0.1",
"updates": "10.2.14",
"versions": "8.4.1"
"eslint": "7.10.0",
"eslint-config-silverwind": "20.0.0",
"jest": "26.4.2",
"updates": "11.1.5",
"versions": "8.4.3"
},

@@ -35,0 +35,0 @@ "jest": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc