Skip to content

Commit

Permalink
fix(psl): Replaced psl module with tldts for up to date public suffix…
Browse files Browse the repository at this point in the history
… list
  • Loading branch information
andris9 committed May 30, 2024
1 parent 3830086 commit cab894b
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 3,303 deletions.
4 changes: 2 additions & 2 deletions lib/dmarc/get-dmarc-record.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const psl = require('psl');
const tldts = require('tldts');
const dns = require('node:dns').promises;

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

if (!txt) {
let orgDomain = psl.get(domain);
let orgDomain = tldts.getDomain(domain);

This comment has been minimized.

Copy link
@remusao

remusao Jun 3, 2024

Nit. By default the parsing of tldts does not take the "private" section of the public suffix list into account. If it's important for your use-case you might want to consider adding allowPrivateDomains option.

let orgDomain = tldts.getDomain(domain, { allowPrivateDomains: true });

This comment has been minimized.

Copy link
@andris9

andris9 Jun 4, 2024

Author Collaborator

Thanks a lot! I did not notice the distinction. Fixed in v4.6.8

This comment has been minimized.

Copy link
@titanism

titanism Jun 14, 2024

awesome find and share @remusao and thank you @andris9 as always 🙏

if (orgDomain !== domain) {
// try org domain as well
txt = await resolveTxt(orgDomain, resolver);
Expand Down
6 changes: 3 additions & 3 deletions lib/dmarc/verify.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict';

const dns = require('node:dns').promises;
const punycode = require('punycode/');
const psl = require('psl');
const punycode = require('punycode.js');
const tldts = require('tldts');
const { formatAuthHeaderRow, getAlignment } = require('../tools');
const getDmarcRecord = require('./get-dmarc-record');

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

let orgDomain = psl.get(domain);
let orgDomain = tldts.getDomain(domain);

let status = {
result: 'neutral',
Expand Down
2 changes: 1 addition & 1 deletion lib/mta-sts.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict';

const { Buffer } = require('node:buffer');
const punycode = require('punycode/');
const punycode = require('punycode.js');
const dns = require('node:dns');
const parseDkimHeaders = require('./parse-dkim-headers');
const https = require('node:https');
Expand Down
2 changes: 1 addition & 1 deletion lib/spf/spf-verify.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict';

const punycode = require('punycode/');
const punycode = require('punycode.js');
const net = require('net');
const macro = require('./macro');
const dns = require('node:dns').promises;
Expand Down
10 changes: 5 additions & 5 deletions lib/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
'use strict';

const { Buffer } = require('node:buffer');
const punycode = require('punycode/');
const punycode = require('punycode.js');
const libmime = require('libmime');
const dns = require('node:dns').promises;
const crypto = require('node:crypto');
const https = require('node:https');
const packageData = require('../package');
const parseDkimHeaders = require('./parse-dkim-headers');
const psl = require('psl');
const tldts = require('tldts');
const Joi = require('joi');
const base64Schema = Joi.string().base64({ paddingRequired: false });

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

// match org domains
fromDomain = formatDomain(psl.get(fromDomain) || fromDomain);
fromDomain = formatDomain(tldts.getDomain(fromDomain) || fromDomain);
for (let entry of domainList) {
let domain = formatDomain(psl.get(entry.domain) || entry.domain);
let domain = formatDomain(tldts.getDomain(entry.domain) || entry.domain);
if (domain === fromDomain) {
return entry;
}
Expand Down
Loading

0 comments on commit cab894b

Please sign in to comment.