Skip to content

Commit

Permalink
fix(dmarc-alignment): Fixed tldts usage to allow private domains
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jun 4, 2024
1 parent d1cf569 commit cc7dfa8
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 71 deletions.
5 changes: 3 additions & 2 deletions lib/dmarc/get-dmarc-record.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
'use strict';

const tldts = require('tldts');
const dns = require('node:dns').promises;
const tldts = require('tldts');
const { TLDTS_OPTS } = require('../tools');

const resolveTxt = async (domain, resolver) => {
try {
Expand Down Expand Up @@ -33,7 +34,7 @@ const getDmarcRecord = async (domain, resolver) => {
let isOrgRecord = false;

if (!txt) {
let orgDomain = tldts.getDomain(domain);
let orgDomain = tldts.getDomain(domain, TLDTS_OPTS);
if (orgDomain !== domain) {
// try org domain as well
txt = await resolveTxt(orgDomain, resolver);
Expand Down
4 changes: 2 additions & 2 deletions lib/dmarc/verify.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
const dns = require('node:dns').promises;
const punycode = require('punycode.js');
const tldts = require('tldts');
const { formatAuthHeaderRow, getAlignment } = require('../tools');
const { formatAuthHeaderRow, getAlignment, TLDTS_OPTS } = require('../tools');
const getDmarcRecord = require('./get-dmarc-record');

const verifyDmarc = async opts => {
Expand Down Expand Up @@ -41,7 +41,7 @@ const verifyDmarc = async opts => {
return response;
};

let orgDomain = tldts.getDomain(domain);
let orgDomain = tldts.getDomain(domain, TLDTS_OPTS);

let status = {
result: 'neutral',
Expand Down
15 changes: 11 additions & 4 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ const keyOrderingDKIM = ['v', 'a', 'c', 'd', 'h', 'i', 'l', 'q', 's', 't', 'x',
const keyOrderingARC = ['i', 'a', 'c', 'd', 'h', 'l', 'q', 's', 't', 'x', 'z', 'bh', 'b'];
const keyOrderingAS = ['i', 'a', 't', 'cv', 'd', 's', 'b'];

const TLDTS_OPTS = {
allowIcannDomains: true,
allowPrivateDomains: true
};

const writeToStream = async (stream, input, chunkSize) => {
chunkSize = chunkSize || 64 * 1024;

Expand Down Expand Up @@ -483,17 +488,17 @@ const getAlignment = (fromDomain, domainList, strict) => {
if (strict) {
fromDomain = formatDomain(fromDomain);
for (let entry of domainList) {
let domain = formatDomain(tldts.getDomain(entry.domain) || entry.domain);
let domain = formatDomain(tldts.getDomain(entry.domain, TLDTS_OPTS) || entry.domain);
if (formatDomain(domain) === fromDomain) {
return entry;
}
}
}

// match org domains
fromDomain = formatDomain(tldts.getDomain(fromDomain) || fromDomain);
fromDomain = formatDomain(tldts.getDomain(fromDomain, TLDTS_OPTS) || fromDomain);
for (let entry of domainList) {
let domain = formatDomain(tldts.getDomain(entry.domain) || entry.domain);
let domain = formatDomain(tldts.getDomain(entry.domain, TLDTS_OPTS) || entry.domain);
if (domain === fromDomain) {
return entry;
}
Expand Down Expand Up @@ -591,5 +596,7 @@ module.exports = {

getPtrHostname,

getCurTime
getCurTime,

TLDTS_OPTS
};
103 changes: 42 additions & 61 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"license-report": "6.5.0",
"marked": "0.7.0",
"marked-man": "0.7.0",
"mbox-reader": "1.1.5",
"mbox-reader": "1.2.0",
"mocha": "10.4.0"
},
"dependencies": {
Expand All @@ -52,7 +52,7 @@
"libmime": "5.3.5",
"nodemailer": "6.9.13",
"punycode.js": "2.3.1",
"tldts": "6.1.23",
"tldts": "6.1.24",
"undici": "5.28.4",
"uuid": "9.0.1",
"yargs": "17.7.2"
Expand Down

0 comments on commit cc7dfa8

Please sign in to comment.