Skip to content

Commit

Permalink
fix(dkim): Log spf results in dkim signature log rows
Browse files Browse the repository at this point in the history
  • Loading branch information
andris9 committed Jan 25, 2024
1 parent e113728 commit d93ae97
Showing 1 changed file with 39 additions and 31 deletions.
70 changes: 39 additions & 31 deletions lib/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ async function hookDataPost(stream, plugin, connection) {

const queueId = txn.uuid;

const contentTypeHeaders = txn.header.get_all('Content-Type').map(line => libmime.parseHeaderValue(`${line}`));

// Step 2. DKIM
let dkimResult;
try {
Expand All @@ -61,41 +63,10 @@ async function hookDataPost(stream, plugin, connection) {
});
txn.notes.dkimResult = dkimResult;

const contentTypeHeaders = txn.header.get_all('Content-Type').map(line => libmime.parseHeaderValue(`${line}`));

for (let result of dkimResult?.results || []) {
if (result.info) {
connection.auth_results(result.info);
}

const signingHeaders = (result.signingHeaders?.keys || '')
.toString()
.split(':')
.map(e => e.toLowerCase().trim());

plugin.loggelf({
short_message: '[DKIM] ' + result.status?.result,
_queue_id: queueId,
_mail_action: 'dkim_verify',
_dkim_info: result.info,
_dkim_status: result.status?.result,
_dkim_length_limited: result.canonBodyLengthLimited ? 'yes' : 'no',
_dkim_over_sized: result.status?.overSized,
_dkim_aligned: result.status?.aligned,
_dkim_signing_domain: result.signingDomain,
_dkim_selector: result.selector,
_dkim_algo: result.algo,
_dkim_mod_len: result.modulusLength,
_dkim_canon_header: result.format.split('/').shift(),
_dkim_canon_body: result.format.split('/').pop(),
_dkim_body_size_source: result.sourceBodyLength,
_dkim_body_size_canon: result.canonBodyLengthTotal,
_dkim_body_size_limit: result.canonBodyLengthLimited && result.canonBodyLengthLimit,
_dkim_signing_headers: signingHeaders.join(','),
_dkim_signing_headers_content_type: signingHeaders.includes('content-type') ? 'yes' : 'no',
_content_type_count: contentTypeHeaders.length,
_content_type_boundary: contentTypeHeaders.length ? contentTypeHeaders.at(-1)?.params?.boundary?.substr(0, 20) : null
});
}
} catch (err) {
txn.notes.dkimResult = { error: err };
Expand Down Expand Up @@ -178,6 +149,43 @@ async function hookDataPost(stream, plugin, connection) {
plugin.logerror(err, plugin, connection);
}
}

for (let result of dkimResult?.results || []) {
if (result.info) {
connection.auth_results(result.info);
}

const signingHeaders = (result.signingHeaders?.keys || '')
.toString()
.split(':')
.map(e => e.toLowerCase().trim());

plugin.loggelf({
short_message: '[DKIM] ' + result.status?.result,
_queue_id: queueId,
_mail_action: 'dkim_verify',
_dkim_info: result.info,
_dkim_status: result.status?.result,
_dkim_length_limited: result.canonBodyLengthLimited ? 'yes' : 'no',
_dkim_over_sized: result.status?.overSized,
_dkim_aligned: result.status?.aligned,
_dkim_signing_domain: result.signingDomain,
_dkim_selector: result.selector,
_dkim_algo: result.algo,
_dkim_mod_len: result.modulusLength,
_dkim_canon_header: result.format.split('/').shift(),
_dkim_canon_body: result.format.split('/').pop(),
_dkim_body_size_source: result.sourceBodyLength,
_dkim_body_size_canon: result.canonBodyLengthTotal,
_dkim_body_size_limit: result.canonBodyLengthLimited && result.canonBodyLengthLimit,
_dkim_signing_headers: signingHeaders.join(','),
_dkim_signing_headers_content_type: signingHeaders.includes('content-type') ? 'yes' : 'no',
_spf_status: txn.notes.spfResult?.status?.result,
_dmarc_spf_aligned: dmarcResult?.alignment?.spf?.result,
_content_type_count: contentTypeHeaders.length,
_content_type_boundary: contentTypeHeaders.length ? contentTypeHeaders.at(-1)?.params?.boundary?.substr(0, 20) : null
});
}
}

module.exports = { hookDataPost, hookMail };

0 comments on commit d93ae97

Please sign in to comment.