Skip to content
This repository has been archived by the owner on Dec 12, 2024. It is now read-only.

Commit

Permalink
fix: fixed error handling on DNS lookups (false positives)
Browse files Browse the repository at this point in the history
  • Loading branch information
niftylettuce committed Sep 27, 2021
1 parent 08c6cdc commit 9e71971
Showing 1 changed file with 38 additions and 24 deletions.
62 changes: 38 additions & 24 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1057,7 +1057,7 @@ class ForwardEmail {
}

// store it in the cache in the background
if (client) {
if (value && client) {
client
.set(key, safeStringify(value), 'PX', ttl)
// eslint-disable-next-line promise/prefer-await-to-then
Expand Down Expand Up @@ -1096,32 +1096,46 @@ class ForwardEmail {
}

if (_.isArray(this.config.dnsbl.domains)) {
const results = await this.resolver(ip, 'DNSBL_BATCH');
if (!_.isArray(results) || results.length === 0) return false;
const blacklistedResults = results.filter((result) => result.listed);
if (blacklistedResults.length === 0) return false;
return blacklistedResults
.map((result) =>
util.format(
this.config.blacklistedStr,
ip,
result.blacklist,
this.config.dnsbl.removals[
this.config.dnsbl.domains.indexOf(result.blacklist)
]
try {
const results = await this.resolver(ip, 'DNSBL_BATCH');
if (!_.isArray(results) || results.length === 0) return false;
const blacklistedResults = results.filter((result) => result.listed);
if (blacklistedResults.length === 0) return false;
return blacklistedResults
.map((result) =>
util.format(
this.config.blacklistedStr,
ip,
result.blacklist,
this.config.dnsbl.removals[
this.config.dnsbl.domains.indexOf(result.blacklist)
]
)
)
)
.join(' ');
.join(' ');
} catch (err) {
this.config.logger.warn(err);
this.config.logger.warn(
new Error('DNS lookup failed to get IP', { ip })
);
return false;
}
}

const result = await this.resolver(ip, 'DNSBL');
if (!result) return false;
return util.format(
this.config.blacklistedStr,
ip,
this.config.dnsbl.domains,
this.config.dnsbl.removals
);
try {
const result = await this.resolver(ip, 'DNSBL');
if (!result) return false;
return util.format(
this.config.blacklistedStr,
ip,
this.config.dnsbl.domains,
this.config.dnsbl.removals
);
} catch (err) {
this.config.logger.warn(err);
this.config.logger.warn(new Error('DNS lookup failed to get IP', { ip }));
return false;
}
}

async onConnect(session, fn) {
Expand Down

0 comments on commit 9e71971

Please sign in to comment.