Skip to content

Commit 0198c4f

Browse files
authored
fix(auth-spf): ZMS-165. if remote IP is private default to softfail with custom message (#42)
* given private network default to SPF neutral * change neutral to softfail, add custom message * fix comment
1 parent 24a6a20 commit 0198c4f

File tree

1 file changed

+12
-1
lines changed

1 file changed

+12
-1
lines changed

lib/auth.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,25 @@ async function hookMail(plugin, connection, params) {
2323
let spfResult;
2424

2525
try {
26+
const isRemotePrivate = connection.remote.is_private;
27+
2628
spfResult = await checkSpf({
2729
resolver: plugin.resolver,
28-
ip: connection.remote.ip, // SMTP client IP
30+
ip: isRemotePrivate ? undefined : connection.remote.ip, // SMTP client IP (undefined for if remote is private network)
2931
helo: connection.hello?.host, // EHLO/HELO hostname
3032
sender: txn.notes.sender, // MAIL FROM address
3133
mta: connection.local?.host, // MX hostname
3234
maxResolveCount: plugin.cfg?.auth?.dns?.maxLookups
3335
});
36+
37+
if (isRemotePrivate) {
38+
// given undefined IP as client IP in case client is from remote IP, SPF will default to neutral, replace with softfail and custom message
39+
spfResult.status.result = 'softfail';
40+
spfResult.status.comment = 'cannot assess local addresses';
41+
spfResult.header = `Received-SPF: softfail (cannot assess local addresses) client-ip=${connection.remote.ip};`;
42+
spfResult.info = `spf=softfail (cannot assess local addresses)`;
43+
}
44+
3445
txn.notes.spfResult = spfResult;
3546
} catch (err) {
3647
txn.notes.spfResult = { error: err };

0 commit comments

Comments
 (0)