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

Fix undefined variable exception when no MX is found and add spf_record_include_match property #32

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.8] - 2024-10-07

- fix: mech_MX crit error on logging undef addrs
Expand Down
8 changes: 7 additions & 1 deletion lib/spf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -506,7 +512,7 @@ class SPF {
resolve_method = 'resolve6'
}

let addrs
let addrs = [];
try {
addrs = await dns[resolve_method](mx)
} catch (err) {
Expand Down
7 changes: 7 additions & 0 deletions test/spf.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
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')
})
})