T13nn3s / Invoke-SpfDkimDmarc

PowerShell Module for checking SPF, DKIM and DMARC-record.
https://binsec.nl/powershell-script-for-spf-dmarc-and-dkim-validation/
MIT License
43 stars 8 forks source link

Get-SPFRecord.ps1 bug - SPF record that over 255 characters #31

Closed limjianan-camelody closed 1 year ago

limjianan-camelody commented 1 year ago

There is a bug, that if the DNS records turn on in an array but it is because 255 characters, the logics says you need to split into 2 array

So the if ($SPF -is [array]) { $SpfAdvisory = "Domain has more than one SPF-record. One SPF record for one domain. This is explicitly defined in RFC4408" }

might need to change it to

if ($spf -is [array] -and (($spf | ? {$_ -like "v=spf1*"}) | measure | select -expand count) -gt 1) { $SpfAdvisory = "Domain has more than one SPF-record. One SPF record for one domain. This is explicitly defined in RFC4408" }

We might also want to have have a check if the spf has longer than 255 Character to make sure it is not breaking anything.

if ($spf -is [array] -and (($spf | ? {$_ -like "v=spf1*"}) | measure | select -expand count) -eq 1) { foreach ($s in $spf) { if ($s.length -gt 255) { $SpfAdvisory = "Your SPF-record has more than 255 characters. This is explicitly defined in RFC4408"} } else {

if ($spf.length -gt 255) { $SpfAdvisory = "Your SPF-record has more than 255 characters. This is explicitly defined in RFC4408" }

}

T13nn3s commented 1 year ago

This will be fixed in the next release. The requested max SPF record length feature will also be implemented in the next release. Thanks for the code snippet, it helped me a lot.