How to use the haraka-net-utils.is_private_ip function in haraka-net-utils

To help you get started, we’ve selected a few haraka-net-utils examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github haraka / Haraka / plugins / data.uribl.js View on Github external
host = arpa.join('.');
                }
                else if ( ip_format === 'ip6') {
                    if (arpa.length < 32) continue; // Only full IP addresses
                    host = arpa.join('.');
                }
            }
            let lookup;
            // Handle zones that do not allow IP queries (e.g. Spamhaus DBL)
            if (net.isIPv4(host)) {
                if (/^(?:1|true|yes|enabled|on)$/i.test(lists[zone].no_ip_lookups)) {
                    results.add(plugin, {skip: `IP (${host}) not supported for ${zone}` });
                    continue;
                }
                // Skip any private IPs
                if (net_utils.is_private_ip(host)) {
                    results.add(plugin, {skip: 'private IP' });
                    continue;
                }
                // Reverse IP for lookup
                lookup = host.split(/\./).reverse().join('.');
            }
            if (net.isIPv6(host)) {
                if (/^(?:1|true|yes|enabled|on)$/i.test(lists[zone].not_ipv6_compatible) || /^(?:1|true|yes|enabled|on)$/i.test(lists[zone].no_ip_lookups)) {
                    results.add(plugin, {skip: `IP (${host}) not supported for ${zone}` });
                    continue;
                }
                // Skip any private IPs
                if (net_utils.is_private_ip(host)) {
                    results.add(plugin, {skip: 'private IP' });
                    continue;
                }
github haraka / Haraka / plugins / bounce.js View on Github external
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);
    }
}
github haraka / Haraka / plugins / helo.checks.js View on Github external
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();
        }

        connection.results.add(plugin, {fail: 'literal_mismatch'});
        if (plugin.cfg.reject.literal_mismatch) {
            return next(DENY, 'HELO IP literal not in the same /24 as your IP address');
        }
        return next();
    }