Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ZMS-165 #42

Merged
merged 3 commits into from
Aug 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,25 @@ async function hookMail(plugin, connection, params) {
let spfResult;

try {
const isRemotePrivate = connection.remote.is_private;

spfResult = await checkSpf({
resolver: plugin.resolver,
ip: connection.remote.ip, // SMTP client IP
ip: isRemotePrivate ? undefined : connection.remote.ip, // SMTP client IP (undefined for if remote is private network)
helo: connection.hello?.host, // EHLO/HELO hostname
sender: txn.notes.sender, // MAIL FROM address
mta: connection.local?.host, // MX hostname
maxResolveCount: plugin.cfg?.auth?.dns?.maxLookups
});

if (isRemotePrivate) {
// given undefined IP as client IP in case client is from remote IP, SPF will default to neutral, replace with softfail and custom message
spfResult.status.result = 'softfail';
spfResult.status.comment = 'cannot assess local addresses';
spfResult.header = `Received-SPF: softfail (cannot assess local addresses) client-ip=${connection.remote.ip};`;
spfResult.info = `spf=softfail (cannot assess local addresses)`;
}

txn.notes.spfResult = spfResult;
} catch (err) {
txn.notes.spfResult = { error: err };
Expand Down