From fa46d02d8ee9a56740d1a83cac64204edcb93733 Mon Sep 17 00:00:00 2001 From: Steve Freegard Date: Mon, 18 Nov 2024 11:05:39 +0000 Subject: [PATCH 1/4] Fix undefined error on empty MX --- lib/spf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/spf.js b/lib/spf.js index 1540493..99bd467 100644 --- a/lib/spf.js +++ b/lib/spf.js @@ -506,7 +506,7 @@ class SPF { resolve_method = 'resolve6' } - let addrs + let addrs = []; try { addrs = await dns[resolve_method](mx) } catch (err) { From 2479f7b5d163e2d03c7ddc19e74b4d318017b367 Mon Sep 17 00:00:00 2001 From: Steve Freegard Date: Mon, 18 Nov 2024 17:10:44 +0000 Subject: [PATCH 2/4] Add spf_record_include_match property to store matching include records --- lib/spf.js | 6 ++++++ test/spf.js | 7 +++++++ 2 files changed, 13 insertions(+) diff --git a/lib/spf.js b/lib/spf.js index 99bd467..ec0e792 100644 --- a/lib/spf.js +++ b/lib/spf.js @@ -13,6 +13,9 @@ class SPF { this.helo = 'unknown' this.spf_record = '' + // Store any matching include record for analysis + this.spf_record_include_match = {} + // RFC 4408 Section 10.1 // Limit the number of mechanisms/modifiers that require DNS lookups to complete. this.count = 0 @@ -358,6 +361,9 @@ class SPF { ) switch (result) { case this.SPF_PASS: + // Store matching "include" mechanisms + this.spf_record_include_match = { ...this.spf_record_include_match, ...recurse.spf_record_include_match } + this.spf_record_include_match[domain] = recurse.spf_record return this.SPF_PASS case this.SPF_FAIL: case this.SPF_SOFTFAIL: diff --git a/test/spf.js b/test/spf.js index 4a24e07..b2cfa8b 100644 --- a/test/spf.js +++ b/test/spf.js @@ -107,4 +107,11 @@ describe('SPF', function () { assert.equal(this.SPF.valid_ip(':212.70.d.94'), false) done() }) + + it('sets spf_record_include_match correctly', async function () { + this.timeout = 3000 + this.SPF.count = 0 + const rc = await this.SPF.check_host('130.211.0.1', 'google.com') + assert.ok(this.SPF.spf_record_include_match?.['_netblocks3.google.com'], 'expected include not found') + }) }) From 472b0fd567a79e57e9b98097c6e01be0384c32f5 Mon Sep 17 00:00:00 2001 From: Steve Freegard Date: Mon, 18 Nov 2024 17:17:31 +0000 Subject: [PATCH 3/4] Update CHANGELOG.md --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3b5c403..646adc0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/). ### Unreleased +- fix: undefined variable in mech_mx if no valid MX found +- add: new spf_record_include_match property to allow for additional filtering + ### [1.2.5] - 2024-04-17 - get_mx: filter out implicit MX records From f8252db24f1afaaeadb86dc0ea0df57f73890281 Mon Sep 17 00:00:00 2001 From: Steve Freegard Date: Tue, 19 Nov 2024 09:05:31 +0000 Subject: [PATCH 4/4] Fix lint error --- test/spf.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/spf.js b/test/spf.js index cef61bf..f79241f 100644 --- a/test/spf.js +++ b/test/spf.js @@ -111,7 +111,7 @@ describe('SPF', function () { it('sets spf_record_include_match correctly', async function () { this.timeout = 3000 this.SPF.count = 0 - const rc = await this.SPF.check_host('130.211.0.1', 'google.com') + await this.SPF.check_host('130.211.0.1', 'google.com') assert.ok(this.SPF.spf_record_include_match?.['_netblocks3.google.com'], 'expected include not found') }) })