Skip to content

Commit

Permalink
feat: macro expansion support in include method in Test-SpfHost
Browse files Browse the repository at this point in the history
  • Loading branch information
jformacek committed Dec 29, 2024
1 parent d4a60cd commit b8722e0
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
21 changes: 21 additions & 0 deletions Commands/Public/Test-SpfIHost.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,27 @@ More about SPF, see http://www.openspf.org/ and https://tools.ietf.org/html/rfc7
#silently ignore not found expanded macro
}
}
$record.Entries `
| Where-Object { $_.Prefix -eq 'include' } `
| Where-Object { $_.Value -match '%{.' } `
| ForEach-Object {
$macro = Expand-SpfMacro -Macro $_.Value -Domain $spfRecords[0].Source -IpAddress $ip -SenderAddress $SenderAddress
if($macro -match '%{.' ) {
throw "Unsupported macro $macro after expansion of $( $_.Value )"
}
try {
$rawRecord = [Dns]::GetRecord($macro, [DnsClient.QueryType]::TXT)
if($null -ne $rawRecord)
{
$additionalRecord = [SpfRecord]::Parse($_.Source, $rawRecord)
$additionalRecord `
| Test-SpfHost -IpAddress $IpAddress -SenderAddress $SenderAddress
}
}
catch {
#silently ignore not found expanded macro
}
}
}
}
}
2 changes: 1 addition & 1 deletion Module/SpfAnalyzer/SpfAnalyzer.psd1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
RootModule = '.\SpfAnalyzer.psm1'

# Version number of this module.
ModuleVersion = '1.0.1'
ModuleVersion = '1.0.2'

# Supported PSEditions
CompatiblePSEditions = @('Core')
Expand Down
21 changes: 21 additions & 0 deletions Module/SpfAnalyzer/SpfAnalyzer.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,27 @@ More about SPF, see http://www.openspf.org/ and https://tools.ietf.org/html/rfc7
#silently ignore not found expanded macro
}
}
$record.Entries `
| Where-Object { $_.Prefix -eq 'include' } `
| Where-Object { $_.Value -match '%{.' } `
| ForEach-Object {
$macro = Expand-SpfMacro -Macro $_.Value -Domain $spfRecords[0].Source -IpAddress $ip -SenderAddress $SenderAddress
if($macro -match '%{.' ) {
throw "Unsupported macro $macro after expansion of $( $_.Value )"
}
try {
$rawRecord = [Dns]::GetRecord($macro, [DnsClient.QueryType]::TXT)
if($null -ne $rawRecord)
{
$additionalRecord = [SpfRecord]::Parse($_.Source, $rawRecord)
$additionalRecord `
| Test-SpfHost -IpAddress $IpAddress -SenderAddress $SenderAddress
}
}
catch {
#silently ignore not found expanded macro
}
}
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ Module provides additional helper commands that return list of IP addresses and
IPv4 and IPv6 addresses are supported.
Only Powershell Core edition is supported.
Macro expansion in `exists` mechanism does not yet cover complete specification in RFC 7208 - looking for collaborators to enhance parsing.
Macros in `include` method aren't currently expanded and such record is not tried to be parsed
Macros in `include` method aren't currently expanded and such record is not tried to be parsed. Hoever, such record is processed by `Test-SpfHost` command

0 comments on commit b8722e0

Please sign in to comment.