Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
addresses.forEach(addr => {
// Handle MX records that are IP addresses
// This is invalid - but a lot of MTAs allow it.
if (net_utils.get_ipany_re('^\\[','\\]$','').test(addr.exchange)) {
connection.logwarn(plugin, domain + ': invalid MX ' +
addr.exchange);
if (c.allow_mx_ip) {
records[addr.exchange] = 1;
}
return;
}
pending_queries++;
net_utils.get_ips_by_host(addr.exchange, (err2, addresses2) => {
pending_queries--;
if (!txn) return;
if (err2 && err2.length === 2) {
results.add(plugin, {msg: err2[0].message});
connection.logdebug(plugin, domain + ': MX ' +
addr.priority + ' ' + addr.exchange +
' => ' + err2[0].message);
exports.dynamic = function (next, connection, helo) {
const plugin = this;
if (plugin.should_skip(connection, 'dynamic')) { return next(); }
// Skip if no dots or an IP literal or address
if (!/\./.test(helo)) {
connection.results.add(plugin, {skip: 'dynamic(no dots)'});
return next();
}
if (net_utils.get_ipany_re('^\\[?(?:IPv6:)?','\\]?$','').test(helo)) {
connection.results.add(plugin, {skip: 'dynamic(literal)'});
return next();
}
if (net_utils.is_ip_in_str(connection.remote.ip, helo)) {
connection.results.add(plugin, {fail: 'dynamic'});
if (plugin.cfg.reject.dynamic) {
return next(DENY, 'HELO is dynamic');
}
return next();
}
connection.results.add(plugin, {pass: 'dynamic'});
return next();
}
exports.bare_ip = function (next, connection, helo) {
const plugin = this;
if (plugin.should_skip(connection, 'bare_ip')) { return next(); }
// RFC 2821, 4.1.1.1 Address literals must be in brackets
// RAW IPs must be formatted: "[1.2.3.4]" not "1.2.3.4" in HELO
if (net_utils.get_ipany_re('^(?:IPv6:)?','$','').test(helo)) {
connection.results.add(plugin, {fail: 'bare_ip(invalid literal)'});
if (plugin.cfg.reject.bare_ip) {
return next(DENY, "Invalid address format in HELO");
}
return next();
}
connection.results.add(plugin, {pass: 'bare_ip'});
return next();
}
return next();
/* The code below needs some kind of test to say the domain isn't local.
this would be hard to do without knowing how you have Haraka configured.
e.g. it could be config/host_list, or it could be some other way.
- hence I added the return next() above or this test can never be correct.
*/
// we wouldn't have accepted the bounce if the recipient wasn't local
// transaction.results.add(plugin,
// {fail: 'Message-ID not local', emit: true });
// if (!plugin.cfg.reject.non_local_msgid) return next();
// return next(DENY, "bounce with non-local Message-ID (RFC 3834)");
}
// Lazy regexp to get IPs from Received: headers in bounces
const received_re = net_utils.get_ipany_re('^Received:[\\s\\S]*?[\\[\\(](?:IPv6:)?', '[\\]\\)]');
function find_received_headers (ips, body, connection, self) {
if (!body) return;
let match;
while ((match = received_re.exec(body.bodytext))) {
const ip = match[1];
if (net_utils.is_private_ip(ip)) continue;
ips[ip] = true;
}
for (let i=0,l=body.children.length; i < l; i++) {
// Recurse in any MIME children
find_received_headers(ips, body.children[i], connection, self);
}
}
exports.bounce_spf_enable = function (next, connection) {
exports.hook_ehlo = function (next, connection, helo) {
this.load_uri_config(next);
// Handle IP literals
let literal;
if ((literal = net_utils.get_ipany_re('^\\[(?:IPv6:)?', '\\]$','').exec(helo))) {
this.do_lookups(connection, next, literal[1], 'helo');
}
else {
this.do_lookups(connection, next, helo, 'helo');
}
}
exports.hook_helo = exports.hook_ehlo;
exports.literal_mismatch = function (next, connection, helo) {
const plugin = this;
if (plugin.should_skip(connection, 'literal_mismatch')) { return next(); }
const literal = net_utils.get_ipany_re('^\\[(?:IPv6:)?','\\]$','').exec(helo);
if (!literal) {
connection.results.add(plugin, {pass: 'literal_mismatch'});
return next();
}
const lmm_mode = parseInt(plugin.cfg.check.literal_mismatch, 10);
const helo_ip = literal[1];
if (lmm_mode > 2 && net_utils.is_private_ip(helo_ip)) {
connection.results.add(plugin, {pass: 'literal_mismatch(private)'});
return next();
}
if (lmm_mode > 1) {
if (net_utils.same_ipv4_network(connection.remote.ip, [helo_ip])) {
connection.results.add(plugin, {pass: 'literal_mismatch'});
return next();