From ae75e27c33f278870cbf525473a1edeaf1e4b194 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Wed, 4 Nov 2026 11:30:46 +1300 Subject: [PATCH 01/20] Add CIS parked-domain audit handling --- .../Get-MtCisParkedDomainClassification.ps1 | 137 ++++++++++++++ .../services/exchange/Resolve-MtDnsRecord.ps1 | 132 ++++++++++++++ .../exchange/Resolve-MtDnsTxtRecord.ps1 | 58 +----- ...-MtCisParkedDomainClassification.Tests.ps1 | 160 +++++++++++++++++ .../functions/Resolve-MtDnsRecord.Tests.ps1 | 170 ++++++++++++++++++ .../Test-MtCisDmarcRecordsPublished.Tests.ps1 | 114 +++++++++++- .../Test-MtCisSpfRecordsPublished.Tests.ps1 | 107 +++++++++++ .../tests/functions/Test-MtDkim.Tests.ps1 | 60 ++++++- tests/cis/Test.CIS.M365.2.1.10.md | 12 +- tests/cis/Test.CIS.M365.2.1.10.ps1 | 77 ++++++-- tests/cis/Test.CIS.M365.2.1.8.md | 12 +- tests/cis/Test.CIS.M365.2.1.8.ps1 | 64 +++++-- tests/cis/Test.CIS.M365.2.1.9.md | 10 +- tests/cis/Test.CIS.M365.2.1.9.ps1 | 84 ++++++--- 14 files changed, 1075 insertions(+), 122 deletions(-) create mode 100644 powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 create mode 100644 powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 create mode 100644 powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 create mode 100644 powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 create mode 100644 powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 diff --git a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 new file mode 100644 index 0000000000..90634ac61c --- /dev/null +++ b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 @@ -0,0 +1,137 @@ +function Get-MtCisParkedDomainClassification { + <# + .SYNOPSIS + Classifies an accepted domain using DNS evidence for the CIS email-authentication checks. + + .DESCRIPTION + Sending requires a positive SPF mechanism, a DKIM selector record, or an Exchange DKIM signing + configuration. NotSending requires a single SPF record with only a non-authorizing all + mechanism and no known DKIM selector records or Exchange signing configuration. Parked + additionally requires no MX record (or a null MX) and no address or CNAME record at the domain + apex. Incomplete or conflicting evidence is Unknown and must not receive the parked-domain + audit exception. + + .PARAMETER DomainName + The accepted domain to classify. + + .PARAMETER DkimSigningConfigs + Exchange DKIM signing configurations already retrieved by the calling test. + #> + [CmdletBinding()] + [OutputType([pscustomobject])] + param( + [Parameter(Mandatory)] + [string]$DomainName, + + [object[]]$DkimSigningConfigs = @(), + + [string[]]$ParkedDomains = @() + ) + + $lookups = [ordered]@{ + SPF = Resolve-MtDnsRecord -Name $DomainName -Type TXT + MX = Resolve-MtDnsRecord -Name $DomainName -Type MX + A = Resolve-MtDnsRecord -Name $DomainName -Type A + AAAA = Resolve-MtDnsRecord -Name $DomainName -Type AAAA + CNAME = Resolve-MtDnsRecord -Name $DomainName -Type CNAME + } + foreach ($selector in 'selector1', 'selector2') { + foreach ($type in 'CNAME', 'TXT') { + $lookupName = "$selector._domainkey.$DomainName" + $lookups["DKIM:$selector`:$type"] = Resolve-MtDnsRecord -Name $lookupName -Type $type + } + } + + $spfAnswers = @($lookups.SPF.Answers | ForEach-Object { $_.Value } | Where-Object { $_ -match '^\s*v=spf1(?:\s|$)' }) + $spfRecord = if ($spfAnswers.Count -eq 1) { [string]$spfAnswers[0] } else { $null } + $spfTerms = if ($spfRecord) { @($spfRecord.Trim() -split '\s+' | Select-Object -Skip 1) } else { @() } + $spfAllTerms = @($spfTerms | Where-Object { $_ -match '^(?i)[+?~-]?all$' }) + $spfRedirectTerms = @($spfTerms | Where-Object { $_ -match '^(?i)redirect=' }) + $spfOtherTerms = @($spfTerms | Where-Object { $_ -notmatch '^(?i)[+?~-]?all$' -and $_ -notmatch '^(?i)exp=' -and $_ -notmatch '^(?i)redirect=' }) + $spfAllQualifier = if ($spfAllTerms.Count -eq 1) { + $qualifier = [regex]::Match($spfAllTerms[0], '^(?[+?~-]?)all$', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase).Groups['qualifier'].Value + if ($qualifier) { $qualifier } else { '+' } + } else { + $null + } + $spfDoesNotAuthorizeSenders = $spfAllTerms.Count -eq 1 -and $spfAllQualifier -in @('-', '~', '?') -and $spfOtherTerms.Count -eq 0 + $spfHasSenderMechanisms = $spfRecord -and -not $spfDoesNotAuthorizeSenders -and ($spfOtherTerms.Count -gt 0 -or $spfAllQualifier -eq '+') + + $domainConfigs = @($DkimSigningConfigs | Where-Object { + $configDomain = $null + if ($_.PSObject.Properties['Domain']) { + $configDomain = $_.Domain + } elseif ($_.PSObject.Properties['Name']) { + $configDomain = $_.Name + } + $configDomain -and [string]::Equals([string]$configDomain, $DomainName, [System.StringComparison]::OrdinalIgnoreCase) + }) + $dkimLookups = @($lookups.GetEnumerator() | Where-Object { $_.Key -like 'DKIM:*' }) + $hasDkimEvidence = $domainConfigs.Count -gt 0 -or @($dkimLookups | Where-Object { @($_.Value.Answers).Count -gt 0 }).Count -gt 0 + $unknownDkimLookups = @($dkimLookups | Where-Object { $_.Value.Status -notin @('Success', 'NXDomain') }) + + $classification = 'Unknown' + $reason = 'The DNS evidence does not establish whether the domain sends email.' + if ($hasDkimEvidence -or $spfHasSenderMechanisms) { + $classification = 'Sending' + $reason = 'An Exchange DKIM configuration, a known DKIM selector record, or an SPF mechanism other than -all indicates email-sending use.' + } elseif ($spfDoesNotAuthorizeSenders -and $unknownDkimLookups.Count -eq 0) { + $classification = 'NotSending' + $reason = 'SPF has only a non-authorizing all mechanism and no Exchange DKIM configuration or selector1/selector2 records were found.' + + $mxRecords = @($lookups.MX.Answers) + $nullMx = $mxRecords.Count -eq 1 -and [string]$mxRecords[0].Value -eq '.' -and [string]$mxRecords[0].Preference -eq '0' + $hasMx = @($mxRecords | Where-Object { [string]$_.Value -and [string]$_.Value -ne '.' }).Count -gt 0 + $hasAddress = @($lookups.A.Answers).Count -gt 0 -or @($lookups.AAAA.Answers).Count -gt 0 + $hasCname = @($lookups.CNAME.Answers).Count -gt 0 + $receivingLookupsKnown = @($lookups.MX, $lookups.A, $lookups.AAAA, $lookups.CNAME | Where-Object { $_.Status -notin @('Success', 'NXDomain') }).Count -eq 0 + $hasNoMx = $mxRecords.Count -eq 0 + + if ($receivingLookupsKnown -and -not $hasMx -and -not $hasAddress -and -not $hasCname -and ($hasNoMx -or $nullMx)) { + $classification = 'Parked' + $reason = if ($nullMx) { + 'SPF has only a non-authorizing all mechanism, no DKIM configuration or known selector records exist, and null MX plus no apex address or CNAME records indicates no email or other DNS use.' + } else { + 'SPF has only a non-authorizing all mechanism, no DKIM configuration or known selector records exist, and no MX, fallback address, or apex CNAME records were found.' + } + } + } + + if ($classification -eq 'Unknown') { + $failedLookups = @($lookups.GetEnumerator() | Where-Object { $_.Value.Status -notin @('Success', 'NXDomain') }) + if ($failedLookups.Count -gt 0) { + $reason = "DNS lookup results are incomplete for $($failedLookups.Key -join ', '); the domain is not classified as parked." + } elseif (-not $spfRecord) { + $reason = 'A single SPF v1 record was not found; the domain is not classified as parked.' + } else { + $reason = 'The SPF and DKIM evidence is conflicting or inconclusive; the domain is not classified as parked.' + } + } elseif ($classification -eq 'NotSending') { + $failedReceivingLookups = @($lookups.MX, $lookups.A, $lookups.AAAA, $lookups.CNAME | Where-Object { $_.Status -notin @('Success', 'NXDomain') }) + if ($failedReceivingLookups.Count -gt 0) { + $reason += ' Receiving or other domain use could not be ruled out because some DNS lookups failed.' + } elseif ($hasMx -or $hasAddress -or $hasCname) { + $reason += ' Receiving or other domain use is present, so the domain is not classified as parked.' + } + } + + $isOverride = @($ParkedDomains | Where-Object { + [string]::Equals($_.TrimEnd('.'), $DomainName.TrimEnd('.'), [System.StringComparison]::OrdinalIgnoreCase) + }).Count -gt 0 + if ($isOverride) { + $automaticClassification = $classification + $classification = 'Parked' + $reason = "The domain was explicitly listed in ParkedDomains. Automatic DNS classification was '$automaticClassification'." + } + + return [pscustomobject]@{ + DomainName = $DomainName + Classification = $classification + IsParked = $classification -eq 'Parked' + IsOverride = $isOverride + SpfRecord = $spfRecord + SpfDeniesAll = $spfDoesNotAuthorizeSenders -and $spfAllQualifier -eq '-' -and $spfRedirectTerms.Count -eq 0 + DkimEvidence = $hasDkimEvidence + Reason = $reason + } +} \ No newline at end of file diff --git a/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 new file mode 100644 index 0000000000..7430139d01 --- /dev/null +++ b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 @@ -0,0 +1,132 @@ +function Resolve-MtDnsRecord { + <# + .SYNOPSIS + Resolves DNS records with consistent results across supported platforms. + + .DESCRIPTION + Uses Resolve-DnsName on Windows and Resolve-Dns from DnsClient-PS on other platforms. + A successful query with no answers has Status Success and an empty Answers array. + + .PARAMETER Name + The DNS name to query. + + .PARAMETER Type + The DNS record type to query. + #> + [CmdletBinding()] + [OutputType([pscustomobject])] + param( + [Parameter(Mandatory)] + [string]$Name, + + [Parameter(Mandatory)] + [ValidateSet('A', 'AAAA', 'CNAME', 'MX', 'TXT')] + [string]$Type + ) + + $result = [pscustomobject]@{ + Name = $Name + Type = $Type + Status = 'Success' + Answers = [object[]]@() + Error = $null + } + $answers = @() + + if ($IsWindows) { + try { + $response = Resolve-DnsName -Name $Name -Type $Type -ErrorAction Stop + $answers = @($response | Where-Object { $_.Section -eq 'Answer' -and $_.Type -eq $Type }) + } catch [System.Management.Automation.CommandNotFoundException] { + $result.Status = 'NotAvailable' + $result.Error = 'Unsupported platform, Resolve-DnsName not available' + return $result + } catch { + if ($_.FullyQualifiedErrorId -like 'DNS_ERROR_RCODE_NAME_ERROR*') { + $result.Status = 'NXDomain' + } elseif ($_.FullyQualifiedErrorId -notlike 'DNS_INFO_NO_RECORDS*') { + $result.Status = 'Error' + $result.Error = "$_" + } + return $result + } + } else { + if (-not (Get-Command -Name 'Resolve-Dns' -ErrorAction SilentlyContinue)) { + $result.Status = 'NotAvailable' + $result.Error = 'Missing dependency, Resolve-Dns not available' + return $result + } + + try { + $response = Resolve-Dns -Query $Name -QueryType $Type -ErrorAction Stop + if ($response.HasError) { + if ("$($response.Header.ResponseCode)" -eq 'NotExistentDomain') { + $result.Status = 'NXDomain' + } else { + $result.Status = 'Error' + $result.Error = $response.ErrorMessage + } + return $result + } + $answers = @($response.Answers | Where-Object { "$($_.RecordType)" -eq $Type }) + } catch { + $result.Status = 'Error' + $result.Error = "$_" + return $result + } + } + + foreach ($answer in $answers) { + $value = $null + $preference = $null + switch ($Type) { + 'TXT' { + if ($answer.PSObject.Properties['Strings']) { + $value = @($answer.Strings) -join '' + } elseif ($answer.PSObject.Properties['Text']) { + $value = @($answer.Text) -join '' + } + } + 'MX' { + if ($answer.PSObject.Properties['NameExchange']) { + $value = $answer.NameExchange + } elseif ($answer.PSObject.Properties['Exchange']) { + $value = $answer.Exchange + } + if ($answer.PSObject.Properties['Preference']) { + $preference = $answer.Preference + } + } + 'CNAME' { + foreach ($propertyName in 'NameHost', 'CanonicalName', 'CName', 'HostName') { + if ($answer.PSObject.Properties[$propertyName]) { + $value = $answer.PSObject.Properties[$propertyName].Value + break + } + } + } + { $_ -in 'A', 'AAAA' } { + foreach ($propertyName in 'IPAddress', 'IPv4Address', 'IPv6Address', 'Address') { + if ($answer.PSObject.Properties[$propertyName]) { + $value = $answer.PSObject.Properties[$propertyName].Value + break + } + } + } + } + + if ($null -eq $value -or [string]::IsNullOrWhiteSpace([string]$value)) { + $result.Status = 'Error' + $result.Error = "The DNS resolver returned an unusable $Type answer for $Name." + $result.Answers = [object[]]@() + return $result + } + + $result.Answers += [pscustomobject]@{ + Value = [string]$value + Preference = $preference + } + } + + return $result +} \ No newline at end of file diff --git a/powershell/internal/services/exchange/Resolve-MtDnsTxtRecord.ps1 b/powershell/internal/services/exchange/Resolve-MtDnsTxtRecord.ps1 index e40b7698d4..1bc6b4aeb0 100644 --- a/powershell/internal/services/exchange/Resolve-MtDnsTxtRecord.ps1 +++ b/powershell/internal/services/exchange/Resolve-MtDnsTxtRecord.ps1 @@ -1,4 +1,4 @@ -function Resolve-MtDnsTxtRecord { +function Resolve-MtDnsTxtRecord { <# .SYNOPSIS Returns the TXT records published at a DNS name, without filtering them. @@ -29,55 +29,11 @@ function Resolve-MtDnsTxtRecord { [string]$Name ) - $result = [pscustomobject]@{ - Name = $Name - Status = 'Success' - Answers = [string[]]@() - Error = $null + $dnsResult = Resolve-MtDnsRecord -Name $Name -Type TXT + return [pscustomobject]@{ + Name = $dnsResult.Name + Status = $dnsResult.Status + Answers = [string[]]@($dnsResult.Answers | ForEach-Object { $_.Value }) + Error = $dnsResult.Error } - - if ($IsWindows) { - try { - $response = Resolve-DnsName -Name $Name -Type TXT -ErrorAction Stop - $result.Answers = [string[]]@($response | Where-Object { $_.Section -eq 'Answer' -and $_.Type -eq 'TXT' } | ForEach-Object { $_.Strings -join '' }) - } catch [System.Management.Automation.CommandNotFoundException] { - $result.Status = 'NotAvailable' - $result.Error = 'Unsupported platform, Resolve-DnsName not available' - } catch { - Write-Verbose "TXT lookup for $($Name) failed: $_" - if ($_.FullyQualifiedErrorId -like 'DNS_ERROR_RCODE_NAME_ERROR*') { - $result.Status = 'NXDomain' - } elseif ($_.FullyQualifiedErrorId -notlike 'DNS_INFO_NO_RECORDS*') { - $result.Status = 'Error' - $result.Error = "$_" - } - } - return $result - } - - if (-not (Get-Command -Name 'Resolve-Dns' -ErrorAction SilentlyContinue)) { - Write-Verbose 'For non-Windows platforms, please install the DnsClient-PS module: Install-Module DnsClient-PS -Scope CurrentUser' - $result.Status = 'NotAvailable' - $result.Error = 'Missing dependency, Resolve-Dns not available' - return $result - } - - try { - $response = Resolve-Dns -Query $Name -QueryType TXT -ErrorAction Stop - if ($response.HasError) { - if ("$($response.Header.ResponseCode)" -eq 'NotExistentDomain') { - $result.Status = 'NXDomain' - } else { - $result.Status = 'Error' - $result.Error = $response.ErrorMessage - } - } else { - $result.Answers = [string[]]@($response.Answers | Where-Object { "$($_.RecordType)" -eq 'TXT' } | ForEach-Object { $_.Text -join '' }) - } - } catch { - Write-Verbose "TXT lookup for $($Name) failed: $_" - $result.Status = 'Error' - $result.Error = "$_" - } - return $result } diff --git a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 new file mode 100644 index 0000000000..7230a8c7a5 --- /dev/null +++ b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 @@ -0,0 +1,160 @@ +Describe 'Get-MtCisParkedDomainClassification' { + BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force -WarningAction SilentlyContinue + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + Use-MtModuleFunction -Name Get-MtCisParkedDomainClassification + + function New-TestDnsResult { + param( + [string]$Name, + [string]$Type, + [object[]]$Answers = @(), + [string]$Status = 'Success' + ) + [pscustomobject]@{ Name = $Name; Type = $Type; Status = $Status; Answers = $Answers; Error = $null } + } + } + + BeforeEach { + $script:dnsResults = @{} + Mock Resolve-MtDnsRecord -ModuleName Maester { + $key = "$Type|$Name" + if ($script:dnsResults.ContainsKey($key)) { + return $script:dnsResults[$key] + } + return New-TestDnsResult -Name $Name -Type $Type + } + } + + It 'classifies a deny-all domain with null MX and no other DNS use as parked' { + $script:dnsResults['TXT|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } + ) + $script:dnsResults['MX|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type MX -Answers @( + [pscustomobject]@{ Value = '.'; Preference = 0 } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' + + $result.Classification | Should -Be 'Parked' + $result.IsParked | Should -BeTrue + } + + It 'classifies a deny-all domain without MX or fallback addresses as parked' { + $script:dnsResults['TXT|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' + + $result.Classification | Should -Be 'Parked' + } + + It 'classifies a softfail-only domain as parked so the audit can enforce hard fail' { + $script:dnsResults['TXT|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 ~all'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' + + $result.Classification | Should -Be 'Parked' + $result.SpfDeniesAll | Should -BeFalse + } + + It 'does not classify a domain with fallback address records as parked' { + $script:dnsResults['TXT|mail.example'] = New-TestDnsResult -Name 'mail.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } + ) + $script:dnsResults['A|mail.example'] = New-TestDnsResult -Name 'mail.example' -Type A -Answers @( + [pscustomobject]@{ Value = '192.0.2.10'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'mail.example' + + $result.Classification | Should -Be 'NotSending' + $result.IsParked | Should -BeFalse + } + + It 'classifies a configured DKIM domain as sending' { + $config = [pscustomobject]@{ Domain = 'sender.example'; Enabled = $false } + + $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' -DkimSigningConfigs @($config) + + $result.Classification | Should -Be 'Sending' + } + + It 'classifies a domain with a published standard DKIM selector as sending' { + $script:dnsResults['TXT|sender.example'] = New-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } + ) + $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = New-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( + [pscustomobject]@{ Value = 'selector1-sender._domainkey.example.onmicrosoft.com'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' + + $result.Classification | Should -Be 'Sending' + $result.DkimEvidence | Should -BeTrue + } + + It 'applies an explicit parked override while retaining conflicting DKIM evidence' { + $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = New-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( + [pscustomobject]@{ Value = 'selector1-sender._domainkey.example.onmicrosoft.com'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' -ParkedDomains 'SENDER.EXAMPLE.' + + $result.Classification | Should -Be 'Parked' + $result.IsOverride | Should -BeTrue + $result.DkimEvidence | Should -BeTrue + } + + It 'classifies a domain with SPF mechanisms as sending' { + $script:dnsResults['TXT|sender.example'] = New-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 include:spf.example.net -all'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' + + $result.Classification | Should -Be 'Sending' + } + + It 'treats an unqualified all mechanism as a sending signal' { + $script:dnsResults['TXT|sender.example'] = New-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 all'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' + + $result.Classification | Should -Be 'Sending' + } + + It 'leaves a domain unknown when SPF is missing' { + $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' + + $result.Classification | Should -Be 'Unknown' + $result.IsParked | Should -BeFalse + } + + It 'leaves redirect-only SPF unknown until the redirect target is evaluated' { + $script:dnsResults['TXT|unknown.example'] = New-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 redirect=_spf.example.net'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' + + $result.Classification | Should -Be 'Unknown' + $result.SpfDeniesAll | Should -BeFalse + } + + It 'leaves a domain unknown when a DKIM DNS lookup fails' { + $script:dnsResults['TXT|unknown.example'] = New-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } + ) + $script:dnsResults['CNAME|selector1._domainkey.unknown.example'] = New-TestDnsResult -Name 'selector1._domainkey.unknown.example' -Type CNAME -Status Error + + $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' + + $result.Classification | Should -Be 'Unknown' + } +} \ No newline at end of file diff --git a/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 new file mode 100644 index 0000000000..f4f32a3528 --- /dev/null +++ b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 @@ -0,0 +1,170 @@ +Describe 'Resolve-MtDnsRecord with Resolve-DnsName' -Skip:(-not $IsWindows) { + BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force -WarningAction SilentlyContinue + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + Use-MtModuleFunction -Name Resolve-MtDnsRecord + } + + BeforeEach { + Mock Resolve-DnsName -ModuleName Maester {} + } + + It 'normalizes MX answers and their preference' { + Mock Resolve-DnsName -ModuleName Maester { + [pscustomobject]@{ + Section = 'Answer' + Type = 'MX' + NameExchange = 'mail.example.com' + Preference = 10 + } + } + + $result = Resolve-MtDnsRecord -Name 'example.com' -Type MX + + $result.Status | Should -Be 'Success' + $result.Answers.Count | Should -Be 1 + $result.Answers[0].Value | Should -Be 'mail.example.com' + $result.Answers[0].Preference | Should -Be 10 + } + + It 'joins TXT character strings into one record' { + Mock Resolve-DnsName -ModuleName Maester { + [pscustomobject]@{ + Section = 'Answer' + Type = 'TXT' + Strings = @('v=spf1 ', '-all') + } + } + + $result = Resolve-MtDnsRecord -Name 'example.com' -Type TXT + + $result.Answers[0].Value | Should -Be 'v=spf1 -all' + } + + It 'returns success with no answers when the record type is absent' { + $result = Resolve-MtDnsRecord -Name 'example.com' -Type MX + + $result.Status | Should -Be 'Success' + $result.Answers.Count | Should -Be 0 + } + + It 'distinguishes a missing DNS name from a resolver failure' { + Mock Resolve-DnsName -ModuleName Maester { + throw [System.Management.Automation.ErrorRecord]::new( + [System.Exception]::new('The DNS name does not exist.'), + 'DNS_ERROR_RCODE_NAME_ERROR', + [System.Management.Automation.ErrorCategory]::ObjectNotFound, + $null + ) + } + + $missing = Resolve-MtDnsRecord -Name 'missing.example' -Type MX + + Mock Resolve-DnsName -ModuleName Maester { + throw [System.Management.Automation.ErrorRecord]::new( + [System.Exception]::new('The DNS server is unavailable.'), + 'DNS_ERROR_RCODE_SERVER_FAILURE', + [System.Management.Automation.ErrorCategory]::ResourceUnavailable, + $null + ) + } + + $unavailable = Resolve-MtDnsRecord -Name 'example.com' -Type MX + + $missing.Status | Should -Be 'NXDomain' + $unavailable.Status | Should -Be 'Error' + } +} + +Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { + BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force -WarningAction SilentlyContinue + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + Use-MtModuleFunction -Name Resolve-MtDnsRecord + + $script:createdDnsStub = & (Get-Module Maester) { + if (-not (Get-Command -Name 'Resolve-Dns' -ErrorAction SilentlyContinue)) { + Set-Item -Path 'Function:script:Resolve-Dns' -Value { + [CmdletBinding()] + param($Query, $QueryType, $NameServer) + throw 'The DNS resolver must be mocked in this test.' + } + $true + } else { + $false + } + } + } + + AfterAll { + if ($script:createdDnsStub) { + & (Get-Module Maester) { Remove-Item -Path 'Function:script:Resolve-Dns' } + } + } + + BeforeEach { + Mock Resolve-Dns -ModuleName Maester {} + } + + It 'normalizes MX answers and their preference' { + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $false + Header = [pscustomobject]@{ ResponseCode = 'NoError' } + Answers = @([pscustomobject]@{ RecordType = 'MX'; Exchange = 'mail.example.com'; Preference = 10 }) + } + } + + $result = Resolve-MtDnsRecord -Name 'example.com' -Type MX + + $result.Status | Should -Be 'Success' + $result.Answers.Count | Should -Be 1 + $result.Answers[0].Value | Should -Be 'mail.example.com' + $result.Answers[0].Preference | Should -Be 10 + Should -Invoke -ModuleName Maester Resolve-Dns -Exactly 1 -ParameterFilter { + $Query -eq 'example.com' -and $QueryType -eq 'MX' + } + } + + It 'joins TXT character strings into one record' { + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $false + Header = [pscustomobject]@{ ResponseCode = 'NoError' } + Answers = @([pscustomobject]@{ RecordType = 'TXT'; Text = @('v=spf1 ', '-all') }) + } + } + + $result = Resolve-MtDnsRecord -Name 'example.com' -Type TXT + + $result.Answers[0].Value | Should -Be 'v=spf1 -all' + } + + It 'distinguishes a missing DNS name from a resolver failure' { + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $true + Header = [pscustomobject]@{ ResponseCode = 'NotExistentDomain' } + ErrorMessage = 'Non-Existent Domain' + Answers = @() + } + } + + $missing = Resolve-MtDnsRecord -Name 'missing.example' -Type MX + + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $true + Header = [pscustomobject]@{ ResponseCode = 'ServerFailure' } + ErrorMessage = 'Server Failure' + Answers = @() + } + } + + $unavailable = Resolve-MtDnsRecord -Name 'example.com' -Type MX + + $missing.Status | Should -Be 'NXDomain' + $unavailable.Status | Should -Be 'Error' + $unavailable.Error | Should -Be 'Server Failure' + } +} \ No newline at end of file diff --git a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 index 75200ec0e9..cffee9fbbf 100644 --- a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 @@ -4,20 +4,82 @@ . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" Use-MtModuleFunction -Name Test-MtCisDmarcRecordsPublished + $script:dmarcRecordText = 'v=DMARC1; p=reject' + $script:dnsResolverCommand = if ($IsWindows) { 'Resolve-DnsName' } else { 'Resolve-Dns' } + $script:createdDnsResolverStub = & (Get-Module Maester) { + param($CommandName) + if (-not (Get-Command -Name $CommandName -ErrorAction SilentlyContinue)) { + Set-Item -Path "Function:script:$CommandName" -Value { + [CmdletBinding()] + param($Name, $Type, $Query, $QueryType, $NameServer) + throw 'The DNS resolver must be mocked in this test.' + } + $true + } else { + $false + } + } $script:dnsResolverCommand + Mock -CommandName $script:dnsResolverCommand -ModuleName Maester { + if ($script:dnsResolverCommand -eq 'Resolve-DnsName') { + [pscustomobject]@{ Section = 'Answer'; Type = 'TXT'; Strings = @($script:dmarcRecordText) } + } else { + [pscustomobject]@{ + HasError = $false + Header = [pscustomobject]@{ ResponseCode = 'NoError' } + Answers = @([pscustomobject]@{ RecordType = 'TXT'; Text = @($script:dmarcRecordText) }) + } + } + } + $script:parkedDmarcRecord = ConvertFrom-MailAuthenticationRecordDmarc -DomainName 'parked.example' + $script:dmarcRecordText = 'v=DMARC1; p=quarantine' + $script:quarantineDmarcRecord = ConvertFrom-MailAuthenticationRecordDmarc -DomainName 'quarantine.example' + $script:dmarcRecordText = 'v=DMARC1; p=reject; pct=100; rua=mailto:reports@example.com; ruf=mailto:forensic@example.com' + $script:fullyCompliantDmarcRecord = ConvertFrom-MailAuthenticationRecordDmarc -DomainName 'sending.example' + $script:domains = @() $script:registrableDomains = @{} $script:dmarcResults = @{} + $script:classifications = @{} + $script:dkimSigningConfigs = @() - Mock Get-MtExo -ModuleName Maester { $script:domains } + Mock Get-MtExo -ModuleName Maester { + if ($Request -eq 'AcceptedDomain') { return $script:domains } + return $script:dkimSigningConfigs + } Mock Get-MtRegistrableDomain -ModuleName Maester { $script:registrableDomains[$DomainName] } Mock ConvertFrom-MailAuthenticationRecordDmarc -ModuleName Maester { $script:dmarcResults[$DomainName] } - Mock Add-MtTestResultDetail -ModuleName Maester {} + Mock Get-MtCisParkedDomainClassification -ModuleName Maester { + $classification = if ($script:classifications.ContainsKey($DomainName)) { + $script:classifications[$DomainName] + } else { + [pscustomobject]@{ Classification = 'Sending'; Reason = 'Sending-domain test default.' } + } + if ($ParkedDomains -contains $DomainName) { + $classification.Classification = 'Parked' + } + return $classification + } + Mock Add-MtTestResultDetail -ModuleName Maester { + $script:resultDetail = [pscustomobject]@{ Result = $Result; Investigate = [bool]$Investigate; SkippedBecause = $SkippedBecause } + } + } + + AfterAll { + if ($script:createdDnsResolverStub) { + & (Get-Module Maester) { + param($CommandName) + Remove-Item -Path "Function:script:$CommandName" + } $script:dnsResolverCommand + } } BeforeEach { $script:domains = @() $script:registrableDomains = @{} $script:dmarcResults = @{} + $script:classifications = @{} + $script:dkimSigningConfigs = @() + $script:resultDetail = $null } It 'fails a known noncompliant domain before skipping an unavailable lookup' { @@ -59,4 +121,52 @@ $Result -match 'Invalid DMARC record' -and $Result -match 'mail.example.com' } } + + It 'requires p=reject but not reporting tags for parked domains' { + $script:domains = @([pscustomobject]@{ DomainName = 'parked.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'parked.example' = 'parked.example' } + $script:dmarcResults = @{ 'parked.example' = $script:parkedDmarcRecord } + $script:classifications = @{ 'parked.example' = [pscustomobject]@{ Classification = 'Parked'; Reason = 'No mail-use signals were found.' } } + + Test-MtCisDmarcRecordsPublished | Should -BeTrue + $script:resultDetail.Investigate | Should -BeFalse + } + + It 'fails a parked domain whose DMARC policy is quarantine' { + $script:domains = @([pscustomobject]@{ DomainName = 'parked.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'parked.example' = 'parked.example' } + $script:dmarcResults = @{ 'parked.example' = $script:quarantineDmarcRecord } + $script:classifications = @{ 'parked.example' = [pscustomobject]@{ Classification = 'Parked'; Reason = 'No mail-use signals were found.' } } + + Test-MtCisDmarcRecordsPublished | Should -BeFalse + } + + It 'investigates an unknown domain when only the parked-domain policy passes' { + $script:domains = @([pscustomobject]@{ DomainName = 'unknown.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'unknown.example' = 'unknown.example' } + $script:dmarcResults = @{ 'unknown.example' = $script:parkedDmarcRecord } + $script:classifications = @{ 'unknown.example' = [pscustomobject]@{ Classification = 'Unknown'; Reason = 'DNS evidence is incomplete.' } } + + Test-MtCisDmarcRecordsPublished | Should -BeTrue + $script:resultDetail.Investigate | Should -BeTrue + } + + It 'applies an explicit parked override and requires reject policy' { + $script:domains = @([pscustomobject]@{ DomainName = 'unknown.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'unknown.example' = 'unknown.example' } + $script:dmarcResults = @{ 'unknown.example' = $script:quarantineDmarcRecord } + $script:classifications = @{ 'unknown.example' = [pscustomobject]@{ Classification = 'Unknown'; Reason = 'DNS evidence is incomplete.' } } + + Test-MtCisDmarcRecordsPublished -ParkedDomains 'unknown.example' | Should -BeFalse + } + + It 'accepts a fully compliant DMARC record when both procedures pass' { + $script:domains = @([pscustomobject]@{ DomainName = 'unknown.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'unknown.example' = 'unknown.example' } + $script:dmarcResults = @{ 'unknown.example' = $script:fullyCompliantDmarcRecord } + $script:classifications = @{ 'unknown.example' = [pscustomobject]@{ Classification = 'Unknown'; Reason = 'DNS evidence is incomplete.' } } + + Test-MtCisDmarcRecordsPublished | Should -BeTrue + $script:resultDetail.Investigate | Should -BeFalse + } } diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 new file mode 100644 index 0000000000..fbaf964ec3 --- /dev/null +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -0,0 +1,107 @@ +Describe 'CIS M365 SPF check' { + BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force -WarningAction SilentlyContinue + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + Use-MtModuleFunction -Name Test-MtCisSpfRecordsPublished + + Mock Get-MtExo -ModuleName Maester { + if ($Request -eq 'AcceptedDomain') { return $script:domains } + return $script:dkimSigningConfigs + } + Mock ConvertFrom-MailAuthenticationRecordSpf -ModuleName Maester { $script:spfResults[$DomainName] } + Mock Get-MtCisParkedDomainClassification -ModuleName Maester { + $classification = $script:classifications[$DomainName] + if ($ParkedDomains -contains $DomainName) { + $classification.Classification = 'Parked' + } + return $classification + } + Mock Add-MtTestResultDetail -ModuleName Maester { + $script:resultDetail = [pscustomobject]@{ + Result = $Result + Investigate = [bool]$Investigate + SkippedBecause = $SkippedBecause + } + } + } + + BeforeEach { + $script:domains = @([pscustomobject]@{ DomainName = 'example.com'; InitialDomain = $false; IsCoExistenceDomain = $false }) + $script:dkimSigningConfigs = @() + $script:spfResults = @{} + $script:classifications = @{} + $script:resultDetail = $null + } + + It 'requires a hard-fail SPF record for a parked domain' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = 'Parked' + SpfDeniesAll = $false + Reason = 'No sending or receiving signals were found.' + } + + Test-MtCisSpfRecordsPublished | Should -BeFalse + $script:resultDetail.Result | Should -Match 'parked/non-sending audit requires an SPF record' + } + + It 'accepts a hard-fail SPF record for a parked domain' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 -all' } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = 'Parked' + SpfDeniesAll = $true + Reason = 'No sending or receiving signals were found.' + } + + Test-MtCisSpfRecordsPublished | Should -BeTrue + $script:resultDetail.Investigate | Should -BeFalse + } + + It 'keeps the soft-fail rule for sending domains' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 include:spf.example.net ~all' } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = 'Sending' + SpfDeniesAll = $false + Reason = 'An SPF sending mechanism was found.' + } + + Test-MtCisSpfRecordsPublished | Should -BeTrue + $script:resultDetail.Investigate | Should -BeFalse + } + + It 'investigates when a soft-fail record passes only the sending-domain rule' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = 'Unknown' + SpfDeniesAll = $false + Reason = 'Mail use is inconclusive.' + } + + Test-MtCisSpfRecordsPublished | Should -BeTrue + $script:resultDetail.Investigate | Should -BeTrue + } + + It 'investigates an indirect all policy when parked status is unknown' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 redirect=_spf.example.net' } + $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 -all' } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = 'Unknown' + SpfDeniesAll = $false + Reason = 'The SPF redirect target is inconclusive.' + } + + Test-MtCisSpfRecordsPublished | Should -BeTrue + $script:resultDetail.Investigate | Should -BeTrue + } + + It 'applies a parked override but still requires hard fail' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = 'Unknown' + SpfDeniesAll = $false + Reason = 'Mail use is inconclusive.' + } + + Test-MtCisSpfRecordsPublished -ParkedDomains 'example.com' | Should -BeFalse + } +} \ No newline at end of file diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index 53616a393d..4b7d8c76e9 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -1,4 +1,4 @@ -BeforeAll { +BeforeAll { . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" # Check functions that became native tests are not exported. Use-MtModuleFunction -Name Test-MtCisaDkim, Test-MtCisDkim @@ -12,6 +12,18 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( BeforeEach { Mock -ModuleName Maester Test-MtConnection { return $true } Mock -ModuleName Maester Add-MtTestResultDetail { } + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + $classification = if ($DomainName -eq 'parked.example') { 'Parked' } else { 'Sending' } + [PSCustomObject]@{ + DomainName = $DomainName + Classification = $classification + IsParked = $classification -eq 'Parked' + SpfRecord = $null + SpfDeniesAll = $false + DkimEvidence = $false + Reason = 'Mock domain classification' + } + } Mock -ModuleName Maester Get-MailAuthenticationRecord { throw 'DNS lookup should not be attempted without a DKIM signing configuration' } @@ -45,8 +57,8 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( InitialDomain = $false IsCoexistenceDomain = $false SendingFromDomainDisabled = $true - ExpectedResultByCommand = @{ - 'Test-MtCisDkim' = $null + ExpectedResultByCommand = @{ + 'Test-MtCisDkim' = $true 'Test-MtCisaDkim' = $null } } @@ -107,6 +119,48 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( } } +Describe 'CIS DKIM domain classification outcomes' { + BeforeEach { + Mock -ModuleName Maester Add-MtTestResultDetail { + $script:detail = [PSCustomObject]@{ Result = $Result; Investigate = [bool]$Investigate; SkippedBecause = $SkippedBecause } + } + Mock -ModuleName Maester Get-MtExo { + if ($Request -eq 'AcceptedDomain') { + return @([PSCustomObject]@{ DomainName = 'unknown.example'; InitialDomain = $false; IsCoexistenceDomain = $false }) + } + return @() + } + Mock -ModuleName Maester Get-MailAuthenticationRecord { throw 'No DKIM lookup should be needed for this classification.' } + } + + It 'investigates domains whose sending use cannot be established' { + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + [PSCustomObject]@{ Classification = 'Unknown'; IsParked = $false; Reason = 'DNS evidence is incomplete.' } + } + + Test-MtCisDkim | Should -BeTrue + $script:detail.Investigate | Should -BeTrue + } + + It 'fails a parked override when DKIM evidence remains' { + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + $classification = if ($ParkedDomains -contains $DomainName) { 'Parked' } else { 'Sending' } + [PSCustomObject]@{ Classification = $classification; DkimEvidence = $true; Reason = 'Explicit parked override.' } + } + + Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeFalse + } + + It 'marks a non-sending receive domain out of scope for DKIM' { + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + [PSCustomObject]@{ Classification = 'NotSending'; IsParked = $false; Reason = 'The domain has receive-only DNS records.' } + } + + Test-MtCisDkim | Should -BeNullOrEmpty + $script:detail.SkippedBecause | Should -Be 'NotApplicable' + } +} + Describe 'DKIM checks for coexistence domains with a signing configuration' -ForEach @( @{ CommandName = 'Test-MtCisDkim' } @{ CommandName = 'Test-MtCisaDkim' } diff --git a/tests/cis/Test.CIS.M365.2.1.10.md b/tests/cis/Test.CIS.M365.2.1.10.md index 08004eea57..a87d292392 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.md +++ b/tests/cis/Test.CIS.M365.2.1.10.md @@ -1,13 +1,19 @@ -Every accepted domain, including the initial onmicrosoft.com domain, has a DMARC policy of quarantine or reject that covers all mail and names addresses for aggregate and forensic reports. +Every accepted domain, including the initial onmicrosoft.com domain, must meet the applicable DMARC audit. Sending domains require a quarantine or reject policy that covers all mail and names addresses for aggregate and forensic reports. Parked or otherwise non-sending domains require a valid DMARC record with `p=reject`. DMARC tells receiving servers what to do with mail that fails SPF and DKIM alignment, and sends you reports about who is sending mail in your name. With a policy of none, spoofed mail is still delivered. Quarantine or reject stops it, and the reports show abuse and legitimate senders that you forgot. -The test uses the record at the domain, or at its organisational domain (for example contoso.com for mail.contoso.com) when the domain has no valid record, including a malformed record, applying the subdomain policy where one exists. The policy must apply to 100 percent of mail (no pct tag, or pct=100). Both rua and ruf addresses must be mailto addresses. Move to enforcement in steps and review the aggregate reports first. +The test uses the record at the domain, or at its organisational domain (for example contoso.com for mail.contoso.com) when the domain has no valid record, including a malformed record, applying the subdomain policy where one exists. For sending domains, the policy must apply to 100 percent of mail (no pct tag, or pct=100), and both rua and ruf addresses must be mailto addresses. + +Maester identifies a likely non-sending domain when it finds one SPF v1 record with only a non-authorizing `-all`, `~all`, or `?all` mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. It classifies the domain as parked only when those signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. + +Parked or non-sending domains use the CIS parked-domain requirement: a valid DMARC record with `p=reject`; rua, ruf, and pct are not required for this branch. Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only SPF policies do not receive the parked exception. When only one of the sending and non-sending audit procedures passes, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. + +When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement for a valid DMARC record with `p=reject`. #### Remediation action 1. Open the DNS zone of each custom domain at your DNS host. For the initial `*.onmicrosoft.com` domain, use the Microsoft 365 admin center instead: go to **Settings** > **Domains**, select the `*.onmicrosoft.com` domain, open the **DNS records** tab and select **Add record**. -2. Create or edit the TXT record `_dmarc.` (in the admin center, the host name is `_dmarc`) with a value such as `v=DMARC1; p=reject; pct=100; rua=mailto:dmarc-reports@; ruf=mailto:dmarc-forensic@`. +2. Create or edit the TXT record `_dmarc.` (in the admin center, the host name is `_dmarc`). For a sending domain, use a value such as `v=DMARC1; p=reject; pct=100; rua=mailto:dmarc-reports@; ruf=mailto:dmarc-forensic@`. For a parked or non-sending domain, `v=DMARC1; p=reject` meets the parked-domain requirement. 3. Start with `p=none` or `p=quarantine` if you are not sure that all your senders are aligned, review the reports and then move to `p=reject`. 4. Check the record with `Resolve-DnsName -Name _dmarc. -Type TXT`. diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index 73944087cd..4eadd65900 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -1,16 +1,16 @@ function Test-MtCisDmarcRecordsPublished { <# .SYNOPSIS - Checks that every accepted domain has a DMARC policy of quarantine or reject with aggregate and forensic reporting. + Checks the applicable CIS DMARC requirement for each accepted domain. .DESCRIPTION - Looks up the DMARC record that applies to each accepted domain, falling back to the organisational domain when the domain has no valid record, including a malformed record. Passes when the applied policy is quarantine or reject, covers 100 percent of mail and defines mailto addresses for aggregate (rua) and forensic (ruf) reports. + Looks up the DMARC record that applies to each accepted domain, falling back to the organisational domain when the domain has no valid record, including a malformed record. Sending domains require quarantine or reject, 100 percent coverage, and mailto aggregate (rua) and forensic (ruf) report addresses. Parked or otherwise non-sending domains require a valid record with p=reject. Ambiguous domain-use evidence is reported for investigation when the two procedures produce different results. CIS Microsoft 365 Foundations Benchmark v7.0.0 (2.1.10, L1) .EXAMPLE Test-MtCisDmarcRecordsPublished - Returns true if all accepted domains have an enforcing DMARC policy with reporting addresses. + Returns true if all accepted domains meet the applicable CIS DMARC requirement. .LINK https://maester.dev/docs/tests/CIS.M365.2.1.10 @@ -32,13 +32,18 @@ )] [CmdletBinding()] [OutputType([bool])] - param() + param( + # Domains explicitly confirmed as parked; the parked DMARC audit still applies. + [string[]]$ParkedDomains = @() + ) Write-Verbose 'Getting accepted domains...' $domains = @(Get-MtExo -Request AcceptedDomain | Where-Object { $_.IsCoExistenceDomain -eq $false }) + $dkimSigningConfigs = @(Get-MtExo -Request DkimSigningConfig) $report = foreach ($domain in $domains) { $name = $domain.DomainName + $classification = Get-MtCisParkedDomainClassification -DomainName $name -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains $dmarc = $null $source = $null $unavailable = $false @@ -59,45 +64,81 @@ } } if ($unavailable) { - [pscustomobject]@{ Domain = $name; Policy = 'Not checked'; Source = 'None'; Failed = 'DNS lookup not available'; Pass = $null } + [pscustomobject]@{ Domain = $name; Classification = $classification.Classification; Policy = 'Not checked'; Source = 'None'; Failed = 'DNS lookup not available'; Pass = $null; Investigate = $false } continue } $policy = $null if ($dmarc) { $policy = if ($source -ne $name -and $dmarc.policySubdomain) { $dmarc.policySubdomain } else { $dmarc.policy } } - $checks = [ordered]@{ + $sendingChecks = [ordered]@{ 'Record is valid' = $null -ne $dmarc -and $dmarc.valid 'Policy is quarantine or reject' = $policy -in @('quarantine', 'reject') 'Applies to 100 percent' = $null -eq $dmarc -or $dmarc.percentage -eq 100 -or $null -eq $dmarc.percentage 'Aggregate reports (rua)' = @($dmarc.reportAggregate | Where-Object { $_.mailAddress }).Count -gt 0 'Forensic reports (ruf)' = @($dmarc.reportForensic | Where-Object { $_.mailAddress }).Count -gt 0 } - $failedChecks = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) + $nonSendingChecks = [ordered]@{ + 'Record is valid' = $null -ne $dmarc -and $dmarc.valid + 'Parked-domain policy is reject' = $policy -eq 'reject' + } + $sendingFailures = @($sendingChecks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) + $nonSendingFailures = @($nonSendingChecks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) + $failedChecks = @() + $investigate = $false + if ($classification.Classification -in @('Parked', 'NotSending')) { + $failedChecks = $nonSendingFailures + $pass = $failedChecks.Count -eq 0 + } elseif ($classification.Classification -eq 'Unknown') { + if ($sendingFailures.Count -eq 0 -and $nonSendingFailures.Count -eq 0) { + $pass = $true + } elseif ($sendingFailures.Count -eq 0 -or $nonSendingFailures.Count -eq 0) { + $pass = $true + $investigate = $true + $failedChecks = if ($sendingFailures.Count -eq 0) { + @("If parked or non-sending: $($nonSendingFailures -join ', ')") + } else { + @("If sending: $($sendingFailures -join ', ')") + } + } else { + $pass = $false + $failedChecks = @( + @($sendingFailures | ForEach-Object { "If sending: $_" }) + + @($nonSendingFailures | ForEach-Object { "If parked or non-sending: $_" }) + ) + } + } else { + $failedChecks = $sendingFailures + $pass = $failedChecks.Count -eq 0 + } [pscustomobject]@{ - Domain = $name - Policy = if ($policy) { $policy } elseif ($invalidCandidate) { 'Invalid DMARC record' } else { 'No valid record' } - Source = if ($source) { $source } elseif ($invalidCandidate) { $invalidCandidate } else { 'None' } - Failed = $failedChecks -join ', ' - Pass = $failedChecks.Count -eq 0 + Domain = $name + Classification = $classification.Classification + Policy = if ($policy) { $policy } elseif ($invalidCandidate) { 'Invalid DMARC record' } else { 'No valid record' } + Source = if ($source) { $source } elseif ($invalidCandidate) { $invalidCandidate } else { 'None' } + Failed = $failedChecks -join ', ' + Pass = $pass + Investigate = $investigate } } $checked = @($report | Where-Object { $null -ne $_.Pass }) - $unchecked = @($report | Where-Object { $null -eq $_.Pass }) + $unchecked = @($report | Where-Object { $null -eq $_.Pass -and -not $_.Investigate }) $failed = @($checked | Where-Object { -not $_.Pass }) + $investigated = @($report | Where-Object { $_.Investigate }) if ($failed.Count -eq 0 -and $unchecked.Count -gt 0) { Add-MtTestResultDetail -SkippedBecause NotSupported return $null } $testResult = $failed.Count -eq 0 - $passText = 'All accepted domains have an enforcing DMARC policy with reporting addresses.' + $passText = 'All accepted domains meet the applicable CIS DMARC requirement.' $failText = "$($failed.Count) domain(s) do not have a compliant DMARC policy." - $resultMd = "| Domain | Applied policy | Record found at | Failed checks | Result |`n" - $resultMd += "| --- | --- | --- | --- | --- |`n" + $resultMd = "| Domain | Classification | Applied policy | Record found at | Failed checks | Result |`n" + $resultMd += "| --- | --- | --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultMd += "| $($row.Domain) | $($row.Policy) | $($row.Source) | $(if ($row.Failed) { $row.Failed } else { 'None' }) | $(if ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" + $resultText = if ($null -eq $row.Pass -and $row.Investigate) { 'Investigate' } elseif ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } + $resultMd += "| $($row.Domain) | $($row.Classification) | $($row.Policy) | $($row.Source) | $(if ($row.Failed) { $row.Failed } else { 'None' }) | $resultText |`n" } if ($testResult) { @@ -107,6 +148,6 @@ } $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate:($investigated.Count -gt 0 -and $failed.Count -eq 0) return $testResult } diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index fef425aa76..607b65fcb1 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -1,13 +1,19 @@ -Every custom domain that is accepted by Exchange Online publishes an SPF record that ends in a hard fail (-all) or soft fail (~all). +Sending domains must publish an SPF record that ends in a hard fail (-all) or soft fail (~all). Parked or otherwise non-sending domains must publish an SPF policy that denies all senders with -all. SPF lists the servers that may send mail for a domain. Receiving servers use it to reject, or to mark as suspicious, mail that pretends to come from your domain. Without an SPF record, or with one that ends in a neutral or permissive qualifier, anyone can send mail that looks like it comes from you without raising a flag. -The test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. Parked domains that never send mail should publish a record of "v=spf1 -all". +Maester identifies a likely non-sending domain when it finds one SPF v1 record with no sender-authorizing mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. It classifies the domain as parked only when those signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. + +For a parked or non-sending domain, the SPF record must explicitly use `-all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. + +Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only policies do not receive the parked exception. When the record passes the sending-domain rule but could fail the parked-domain rule, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. + +When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement to publish `v=spf1 -all`. #### Remediation action 1. Open the DNS zone of each custom domain at your DNS host. -2. Create or edit the TXT record at the domain root so that it lists your sending services and ends with `-all` (or `~all`). For Exchange Online only, use `v=spf1 include:spf.protection.outlook.com -all`. +2. Create or edit the TXT record at the domain root. For a sending domain, list its sending services and end with `-all` or `~all`; for a parked or non-sending domain, publish `v=spf1 -all`. For Exchange Online only, use `v=spf1 include:spf.protection.outlook.com -all`. 3. Wait for the change to propagate and check the record with `Resolve-DnsName -Name -Type TXT`. #### Related links diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 4909a0d6f2..3980d6d9b1 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -1,16 +1,16 @@ function Test-MtCisSpfRecordsPublished { <# .SYNOPSIS - Checks that every custom accepted domain publishes an SPF record that ends in -all or ~all. + Checks the applicable CIS SPF requirement for each custom accepted domain. .DESCRIPTION - Looks up the SPF record of each custom accepted domain and passes when a record exists and ends with a hard fail or soft fail, either directly or through a redirect. Domains in the onmicrosoft.com namespace are excluded because Microsoft manages their SPF. + Sending domains must publish an SPF record that ends with -all or ~all, directly or through a redirect. Parked or otherwise non-sending domains must publish an SPF policy that denies all senders with -all. Domains in the onmicrosoft.com namespace are excluded because Microsoft manages their SPF. Ambiguous domain-use evidence is reported for investigation rather than receiving the parked-domain exception. CIS Microsoft 365 Foundations Benchmark v7.0.0 (2.1.8, L1) .EXAMPLE Test-MtCisSpfRecordsPublished - Returns true if all custom domains publish an SPF record that ends in -all or ~all. + Returns true if all custom domains meet the applicable CIS SPF requirement. .LINK https://maester.dev/docs/tests/CIS.M365.2.1.8 @@ -32,20 +32,25 @@ )] [CmdletBinding()] [OutputType([bool])] - param() + param( + # Domains explicitly confirmed as parked; the parked SPF audit still applies. + [string[]]$ParkedDomains = @() + ) Write-Verbose 'Getting accepted domains...' $domains = @(Get-MtExo -Request AcceptedDomain | Where-Object { $_.InitialDomain -eq $false -and $_.IsCoExistenceDomain -eq $false }) + $dkimSigningConfigs = @(Get-MtExo -Request DkimSigningConfig) $report = foreach ($domain in $domains) { $name = $domain.DomainName + $classification = Get-MtCisParkedDomainClassification -DomainName $name -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains $detail = '' $spf = ConvertFrom-MailAuthenticationRecordSpf -DomainName $name if ($spf -is [string] -and ($spf -like '*not available' -or $spf -eq 'DNS lookup unavailable')) { - [pscustomobject]@{ Domain = $name; Record = $null; Pass = $null; Detail = 'DNS lookup not available' } + [pscustomobject]@{ Domain = $name; Record = $null; Classification = $classification.Classification; Pass = $null; Investigate = $false; Detail = 'DNS lookup not available' } continue } - $record = if ($spf.GetType().Name -eq 'SPFRecord') { $spf.record } else { $null } + $record = if ($spf -and $spf.PSObject.Properties['record']) { $spf.record } else { $null } $effective = $record $redirectTargets = @() $redirectError = $null @@ -77,8 +82,7 @@ $redirectUnavailable = $true break } - $redirectedType = if ($null -ne $redirected) { $redirected.GetType().Name } else { $null } - $effective = if ($redirectedType -eq 'SPFRecord') { $redirected.record } else { $null } + $effective = if ($null -ne $redirected -and $redirected.PSObject.Properties['record']) { $redirected.record } else { $null } if (-not $effective) { $redirectError = "No SPF record was found at redirect target $target." break @@ -86,11 +90,13 @@ } if ($redirectUnavailable) { - [pscustomobject]@{ Domain = $name; Record = $record; Pass = $null; Detail = "DNS lookup not available for $($redirectTargets[-1])" } + [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification.Classification; Pass = $null; Investigate = $false; Detail = "DNS lookup not available for $($redirectTargets[-1])" } continue } $effectiveAll = [regex]::Match([string]$effective, '(?i)(^|\s)(?[+?~-]?)all(\s|$)') - $pass = $effectiveAll.Success -and $effectiveAll.Groups['q'].Value -in '-', '~' + $sendingDomainPass = $effectiveAll.Success -and $effectiveAll.Groups['q'].Value -in '-', '~' + $pass = $sendingDomainPass + $investigate = $false if (-not $record) { $detail = 'No SPF record found' } elseif ($redirectError) { @@ -103,27 +109,49 @@ elseif (-not $pass) { $detail = 'The record does not end with -all or ~all' } - [pscustomobject]@{ Domain = $name; Record = $record; Pass = $pass; Detail = $detail } + + if ($classification.Classification -in @('Parked', 'NotSending')) { + $pass = $classification.SpfDeniesAll + $detail = if ($pass) { + 'The parked/non-sending audit requires an SPF record that explicitly denies all senders; this record uses -all.' + } else { + 'The parked/non-sending audit requires an SPF record that explicitly denies all senders with -all.' + } + } elseif ($classification.Classification -eq 'Unknown' -and $sendingDomainPass -and -not $classification.SpfDeniesAll) { + $pass = $null + $investigate = $true + $detail = 'The sending-domain SPF audit passes, but the available evidence cannot rule out the parked-domain requirement for -all.' + } elseif ($classification.Classification -eq 'Unknown' -and $sendingDomainPass) { + $pass = $true + $detail = 'The record meets both the sending-domain and parked-domain SPF requirements.' + } + + $detail = "$($classification.Reason) $detail" + [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification.Classification; Pass = $pass; Investigate = $investigate; Detail = $detail } } - $unchecked = @($report | Where-Object { $null -eq $_.Pass }) + $unchecked = @($report | Where-Object { $null -eq $_.Pass -and -not $_.Investigate }) $failed = @($report | Where-Object { $_.Pass -eq $false }) + $investigated = @($report | Where-Object { $_.Investigate }) if ($failed.Count -gt 0) { $testResult = $false } elseif ($unchecked.Count -gt 0) { Add-MtTestResultDetail -SkippedBecause NotSupported return $null + } elseif ($investigated.Count -gt 0) { + $testResult = $true } else { $testResult = $true } - $passText = if ($domains.Count -eq 0) { 'There are no custom domains, so no SPF records are required.' } else { 'All custom domains publish an SPF record that ends in -all or ~all.' } - $failText = "$($failed.Count) custom domain(s) do not publish a compliant SPF record." + $passText = if ($domains.Count -eq 0) { 'There are no custom domains, so no SPF records are required.' } else { 'All custom domains meet the applicable CIS SPF requirement.' } + $failText = "$($failed.Count) custom domain(s) do not meet the applicable CIS SPF requirement." - $resultMd = "| Domain | SPF record | Detail | Result |`n" - $resultMd += "| --- | --- | --- | --- |`n" + $resultMd = "| Domain | Classification | SPF record | Detail | Result |`n" + $resultMd += "| --- | --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultMd += "| $($row.Domain) | $($row.Record) | $($row.Detail) | $(if ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" + $resultText = if ($null -eq $row.Pass -and $row.Investigate) { 'Investigate' } elseif ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } + $resultMd += "| $($row.Domain) | $($row.Classification) | $($row.Record) | $($row.Detail) | $resultText |`n" } if ($testResult) { @@ -134,6 +162,6 @@ } $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate:($investigated.Count -gt 0 -and $failed.Count -eq 0) return $testResult } diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index 6d347be554..facb7b91d8 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -12,7 +12,13 @@ There should be no impact of setting up DKIM however, organizations should ensur >Note: Initial (MOERA, e.g. `contoso.onmicrosoft.com`) and coexistence (`*.mail.onmicrosoft.com`) domains are excluded from this check, as Microsoft automatically signs outbound mail for those domains. -For each sending domain, the check requires Exchange DKIM to be enabled and its status to be **Valid**. +For domains classified as sending, the check requires Exchange DKIM to be enabled and its status to be **Valid**. A likely sending domain has an SPF sender-authorizing mechanism, an Exchange DKIM signing configuration, or a selector1/selector2 DKIM CNAME/TXT record. + +Maester classifies a domain as not sending when its single SPF v1 record has only a non-authorizing `-all`, `~all`, or `?all` mechanism and no Exchange DKIM signing configuration or selector1/selector2 records are found. It is classified as parked only when it also has no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This classification does not use `AcceptedDomain.SendingFromDomainDisabled`. + +For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no Exchange DKIM configuration or standard selector1/selector2 records are found. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence, or failed DNS lookups, are marked for investigation rather than automatically treated as parked. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. + +When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; any detected Exchange DKIM configuration or standard selector record still fails the check. #### Remediation action @@ -46,6 +52,8 @@ The initial domain is the domain that you used when you signed up for Office 365 5. Select **DKIM** 6. Click on each domain and click **Enable** next to **Sign messages for this domain with DKIM signature**. +For a confirmed parked domain, do not create an Exchange DKIM signing configuration or publish selector records. Before removing existing records, confirm the domain is not used to send email through Exchange Online or another service. + Final remediation step using the Exchange Online PowerShell Module: 1. Connect to Exchange Online service using `Connect-ExchangeOnline`. diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index 9a427ac2a3..d645d0bd3b 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -1,17 +1,16 @@ function Test-MtCisDkim { <# .SYNOPSIS - Checks state of DKIM for all EXO domains + Checks DKIM for domains that send email and verifies parked domains have no DKIM records. .DESCRIPTION - DKIM should be enabled with a valid Exchange status for all sending domains. Initial (MOERA) and coexistence domains are excluded, as Microsoft automatically signs outbound mail for those domains. + Sending domains require DKIM to be enabled with a valid Exchange status. Parked domains must not publish DKIM records. Initial (MOERA) and coexistence domains are excluded, as Microsoft automatically signs outbound mail for those domains. Ambiguous domain-use evidence is reported for investigation. CIS Microsoft 365 Foundations Benchmark v7.0.0 (2.1.9, L1) .EXAMPLE Test-MtCisDkim - Returns true if every evaluated domain has a DKIM record, DKIM enabled in Exchange, and Exchange status Valid. - Initial, coexistence, and Exchange sending-disabled domains are excluded; if no domains remain, the test is skipped. + Returns true if every sending domain has DKIM enabled with Exchange status Valid and every parked domain has no known Exchange selector records. Initial and coexistence domains are excluded. Domains classified as not sending are out of scope; ambiguous domains require investigation. .LINK https://maester.dev/docs/commands/Test-MtCisDkim @@ -37,22 +36,21 @@ [OutputType([bool])] param( # Selector-name for the DKIM record to test.. - [string]$Selector = 'selector1' + [string]$Selector = 'selector1', + + # Domains explicitly confirmed as parked; any detected DKIM configuration or selector still fails the audit. + [string[]]$ParkedDomains = @() ) $dkimSigningConfigs = Get-MtExo -Request DkimSigningConfig $acceptedDomains = Get-MtExo -Request AcceptedDomain - <# DKIM record without key for parked domains - $sendingDomains = $acceptedDomains | Where-Object { - -not $_.SendingFromDomainDisabled - } - #> $dkimRecords = @() foreach ($domain in $acceptedDomains) { if ($domain.InitialDomain -eq $true -or $domain.IsCoExistenceDomain -eq $true) { $dkimRecord = [PSCustomObject]@{ domain = $domain.DomainName + classification = 'Excluded' pass = 'Skipped' reason = 'Initial or coexistence domain excluded from DKIM audit (Microsoft auto-signs outbound mail for this domain)' exchangeStatus = 'Excluded' @@ -62,6 +60,44 @@ continue } + $classification = Get-MtCisParkedDomainClassification -DomainName $domain.DomainName -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains + if ($classification.Classification -eq 'Parked') { + $hasDkimEvidence = $classification.DkimEvidence + $dkimRecords += [PSCustomObject]@{ + domain = $domain.DomainName + classification = $classification.Classification + pass = if ($hasDkimEvidence) { 'Failed' } else { 'Passed' } + reason = if ($hasDkimEvidence) { "Parked domain has a DKIM configuration or known selector record that must be removed. $($classification.Reason)" } else { "Parked domain has no known DKIM selector records. $($classification.Reason)" } + exchangeStatus = 'Not applicable' + dkimRecord = $null + } + continue + } + + if ($classification.Classification -eq 'NotSending') { + $dkimRecords += [PSCustomObject]@{ + domain = $domain.DomainName + classification = $classification.Classification + pass = 'Skipped' + reason = "The CIS DKIM audit applies to domains configured to send email. $($classification.Reason)" + exchangeStatus = 'Not applicable' + dkimRecord = $null + } + continue + } + + if ($classification.Classification -eq 'Unknown') { + $dkimRecords += [PSCustomObject]@{ + domain = $domain.DomainName + classification = $classification.Classification + pass = 'Investigate' + reason = "Sending use could not be established; the domain was not classified as parked. $($classification.Reason)" + exchangeStatus = 'Not determined' + dkimRecord = $null + } + continue + } + $dkimSigningConfig = $dkimSigningConfigs | Where-Object { $_.domain -eq $domain.domainname } @@ -69,8 +105,9 @@ if (-not $dkimSigningConfig) { $dkimRecord = [PSCustomObject]@{ domain = $domain.DomainName - pass = if ($domain.SendingFromDomainDisabled) { 'Skipped' } else { 'Failed' } - reason = if ($domain.SendingFromDomainDisabled) { 'Parked domain' } else { 'No DkimSigningConfig found for domain' } + classification = $classification.Classification + pass = 'Failed' + reason = 'No DkimSigningConfig found for a domain classified as sending' exchangeStatus = 'Not configured' dkimRecord = $null } @@ -103,11 +140,9 @@ $dkimRecord | Add-Member -MemberType NoteProperty -Name 'pass' -Value 'Failed' $dkimRecord | Add-Member -MemberType NoteProperty -Name 'reason' -Value '' $dkimRecord | Add-Member -MemberType NoteProperty -Name 'exchangeStatus' -Value $dkimSigningConfig.Status + $dkimRecord | Add-Member -MemberType NoteProperty -Name 'classification' -Value $classification.Classification - if ($domain.SendingFromDomainDisabled) { - $dkimRecord.pass = 'Skipped' - $dkimRecord.reason = 'Parked domain' - } elseif (-not $dkimSigningConfig.enabled) { + if (-not $dkimSigningConfig.enabled) { $dkimRecord.pass = 'Failed' $dkimRecord.reason = 'DKIM is disabled' } elseif ($dkimSigningConfig.Status -ne 'Valid') { @@ -133,8 +168,10 @@ if ('Failed' -in $dkimRecords.pass) { $testResult = $false - } elseif ('Failed' -notin $dkimRecords.pass -and 'Passed' -notin $dkimRecords.pass) { - Add-MtTestResultDetail -SkippedBecause NotSupported + } elseif ('Investigate' -in $dkimRecords.pass) { + $testResult = $true + } elseif ('Passed' -notin $dkimRecords.pass) { + Add-MtTestResultDetail -SkippedBecause NotApplicable return $null } else { $testResult = $true @@ -143,7 +180,7 @@ if ('Failed' -in $dkimRecords.pass) { $portalLink = 'https://security.microsoft.com/authentication?viewid=DKIM' if ($testResult) { - $testResultMarkdown = "Well done. Your tenant's domains have DKIM configured and valid records exist.`n`n%TestResult%" + $testResultMarkdown = "Well done. Sending domains have DKIM configured and valid records exist, and parked domains have no known Exchange selector records.`n`n%TestResult%" } else { $testResultMarkdown = "Your tenant's domains do not have DKIM fully deployed. Review [EXO configuration]($portalLink) and DNS records.`n`n%TestResult%" } @@ -151,19 +188,20 @@ if ('Failed' -in $dkimRecords.pass) { $passResult = '✅ Pass' $failResult = '❌ Fail' $skipResult = '🗄️ Skip' - $result = "| Domain | Result | Exchange status | Reason |`n" - $result += "| --- | --- | --- | --- |`n" + $result = "| Domain | Classification | Result | Exchange status | Reason |`n" + $result += "| --- | --- | --- | --- | --- |`n" foreach ($item in $dkimRecords | Sort-Object -Property domain) { switch ($item.pass) { 'Passed' { $itemResult = $passResult } 'Skipped' { $itemResult = $skipResult } 'Failed' { $itemResult = $failResult } + 'Investigate' { $itemResult = '🔎 Investigate' } } - $result += "| $($item.domain) | $($itemResult) | $($item.exchangeStatus) | $($item.reason) |`n" + $result += "| $($item.domain) | $($item.classification) | $($itemResult) | $($item.exchangeStatus) | $($item.reason) |`n" } $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $result - Add-MtTestResultDetail -Result $testResultMarkdown + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate:('Investigate' -in $dkimRecords.pass -and 'Failed' -notin $dkimRecords.pass) return $testResult } From 43c141c237a653ee6287ed6f3a39b72916f69968 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Wed, 4 Nov 2026 12:38:19 +1300 Subject: [PATCH 02/20] Fix review findings and DMARC tests --- .../Get-MtCisParkedDomainClassification.ps1 | 2 +- .../services/exchange/Resolve-MtDnsRecord.ps1 | 2 +- ...-MtCisParkedDomainClassification.Tests.ps1 | 34 +++++----- .../functions/Resolve-MtDnsRecord.Tests.ps1 | 4 +- .../Test-MtCisDmarcRecordsPublished.Tests.ps1 | 62 +++++++------------ .../Test-MtCisSpfRecordsPublished.Tests.ps1 | 2 +- tests/cis/Test.CIS.M365.2.1.10.ps1 | 2 +- 7 files changed, 46 insertions(+), 62 deletions(-) diff --git a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 index 90634ac61c..e4e61cc7a5 100644 --- a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 +++ b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 @@ -134,4 +134,4 @@ DkimEvidence = $hasDkimEvidence Reason = $reason } -} \ No newline at end of file +} diff --git a/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 index 7430139d01..9421f5f426 100644 --- a/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 +++ b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 @@ -129,4 +129,4 @@ } return $result -} \ No newline at end of file +} diff --git a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 index 7230a8c7a5..f2b56b3077 100644 --- a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 +++ b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 @@ -4,7 +4,7 @@ . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" Use-MtModuleFunction -Name Get-MtCisParkedDomainClassification - function New-TestDnsResult { + function ConvertTo-TestDnsResult { param( [string]$Name, [string]$Type, @@ -22,15 +22,15 @@ if ($script:dnsResults.ContainsKey($key)) { return $script:dnsResults[$key] } - return New-TestDnsResult -Name $Name -Type $Type + return ConvertTo-TestDnsResult -Name $Name -Type $Type } } It 'classifies a deny-all domain with null MX and no other DNS use as parked' { - $script:dnsResults['TXT|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( + $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } ) - $script:dnsResults['MX|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type MX -Answers @( + $script:dnsResults['MX|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type MX -Answers @( [pscustomobject]@{ Value = '.'; Preference = 0 } ) @@ -41,7 +41,7 @@ } It 'classifies a deny-all domain without MX or fallback addresses as parked' { - $script:dnsResults['TXT|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( + $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } ) @@ -51,7 +51,7 @@ } It 'classifies a softfail-only domain as parked so the audit can enforce hard fail' { - $script:dnsResults['TXT|parked.example'] = New-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( + $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 ~all'; Preference = $null } ) @@ -62,10 +62,10 @@ } It 'does not classify a domain with fallback address records as parked' { - $script:dnsResults['TXT|mail.example'] = New-TestDnsResult -Name 'mail.example' -Type TXT -Answers @( + $script:dnsResults['TXT|mail.example'] = ConvertTo-TestDnsResult -Name 'mail.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } ) - $script:dnsResults['A|mail.example'] = New-TestDnsResult -Name 'mail.example' -Type A -Answers @( + $script:dnsResults['A|mail.example'] = ConvertTo-TestDnsResult -Name 'mail.example' -Type A -Answers @( [pscustomobject]@{ Value = '192.0.2.10'; Preference = $null } ) @@ -84,10 +84,10 @@ } It 'classifies a domain with a published standard DKIM selector as sending' { - $script:dnsResults['TXT|sender.example'] = New-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( + $script:dnsResults['TXT|sender.example'] = ConvertTo-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } ) - $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = New-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( + $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = ConvertTo-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( [pscustomobject]@{ Value = 'selector1-sender._domainkey.example.onmicrosoft.com'; Preference = $null } ) @@ -98,7 +98,7 @@ } It 'applies an explicit parked override while retaining conflicting DKIM evidence' { - $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = New-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( + $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = ConvertTo-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( [pscustomobject]@{ Value = 'selector1-sender._domainkey.example.onmicrosoft.com'; Preference = $null } ) @@ -110,7 +110,7 @@ } It 'classifies a domain with SPF mechanisms as sending' { - $script:dnsResults['TXT|sender.example'] = New-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( + $script:dnsResults['TXT|sender.example'] = ConvertTo-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 include:spf.example.net -all'; Preference = $null } ) @@ -120,7 +120,7 @@ } It 'treats an unqualified all mechanism as a sending signal' { - $script:dnsResults['TXT|sender.example'] = New-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( + $script:dnsResults['TXT|sender.example'] = ConvertTo-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 all'; Preference = $null } ) @@ -137,7 +137,7 @@ } It 'leaves redirect-only SPF unknown until the redirect target is evaluated' { - $script:dnsResults['TXT|unknown.example'] = New-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( + $script:dnsResults['TXT|unknown.example'] = ConvertTo-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 redirect=_spf.example.net'; Preference = $null } ) @@ -148,13 +148,13 @@ } It 'leaves a domain unknown when a DKIM DNS lookup fails' { - $script:dnsResults['TXT|unknown.example'] = New-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( + $script:dnsResults['TXT|unknown.example'] = ConvertTo-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } ) - $script:dnsResults['CNAME|selector1._domainkey.unknown.example'] = New-TestDnsResult -Name 'selector1._domainkey.unknown.example' -Type CNAME -Status Error + $script:dnsResults['CNAME|selector1._domainkey.unknown.example'] = ConvertTo-TestDnsResult -Name 'selector1._domainkey.unknown.example' -Type CNAME -Status Error $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' $result.Classification | Should -Be 'Unknown' } -} \ No newline at end of file +} diff --git a/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 index f4f32a3528..09ec5a3738 100644 --- a/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 +++ b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 @@ -87,7 +87,7 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { Set-Item -Path 'Function:script:Resolve-Dns' -Value { [CmdletBinding()] param($Query, $QueryType, $NameServer) - throw 'The DNS resolver must be mocked in this test.' + throw "Resolve-Dns was called without a mock (query '$Query', type '$QueryType', server '$NameServer')." } $true } else { @@ -167,4 +167,4 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { $unavailable.Status | Should -Be 'Error' $unavailable.Error | Should -Be 'Server Failure' } -} \ No newline at end of file +} diff --git a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 index cffee9fbbf..034bb46a6b 100644 --- a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 @@ -4,37 +4,30 @@ . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" Use-MtModuleFunction -Name Test-MtCisDmarcRecordsPublished - $script:dmarcRecordText = 'v=DMARC1; p=reject' - $script:dnsResolverCommand = if ($IsWindows) { 'Resolve-DnsName' } else { 'Resolve-Dns' } - $script:createdDnsResolverStub = & (Get-Module Maester) { - param($CommandName) - if (-not (Get-Command -Name $CommandName -ErrorAction SilentlyContinue)) { - Set-Item -Path "Function:script:$CommandName" -Value { - [CmdletBinding()] - param($Name, $Type, $Query, $QueryType, $NameServer) - throw 'The DNS resolver must be mocked in this test.' - } - $true - } else { - $false - } - } $script:dnsResolverCommand - Mock -CommandName $script:dnsResolverCommand -ModuleName Maester { - if ($script:dnsResolverCommand -eq 'Resolve-DnsName') { - [pscustomobject]@{ Section = 'Answer'; Type = 'TXT'; Strings = @($script:dmarcRecordText) } - } else { - [pscustomobject]@{ - HasError = $false - Header = [pscustomobject]@{ ResponseCode = 'NoError' } - Answers = @([pscustomobject]@{ RecordType = 'TXT'; Text = @($script:dmarcRecordText) }) - } - } + $script:parkedDmarcRecord = [pscustomobject]@{ + valid = $true + policy = 'reject' + policySubdomain = $null + percentage = 100 + reportAggregate = @() + reportForensic = @() + } + $script:quarantineDmarcRecord = [pscustomobject]@{ + valid = $true + policy = 'quarantine' + policySubdomain = $null + percentage = 100 + reportAggregate = @() + reportForensic = @() + } + $script:fullyCompliantDmarcRecord = [pscustomobject]@{ + valid = $true + policy = 'reject' + policySubdomain = $null + percentage = 100 + reportAggregate = @([pscustomobject]@{ mailAddress = 'reports@example.com' }) + reportForensic = @([pscustomobject]@{ mailAddress = 'forensic@example.com' }) } - $script:parkedDmarcRecord = ConvertFrom-MailAuthenticationRecordDmarc -DomainName 'parked.example' - $script:dmarcRecordText = 'v=DMARC1; p=quarantine' - $script:quarantineDmarcRecord = ConvertFrom-MailAuthenticationRecordDmarc -DomainName 'quarantine.example' - $script:dmarcRecordText = 'v=DMARC1; p=reject; pct=100; rua=mailto:reports@example.com; ruf=mailto:forensic@example.com' - $script:fullyCompliantDmarcRecord = ConvertFrom-MailAuthenticationRecordDmarc -DomainName 'sending.example' $script:domains = @() $script:registrableDomains = @{} @@ -64,15 +57,6 @@ } } - AfterAll { - if ($script:createdDnsResolverStub) { - & (Get-Module Maester) { - param($CommandName) - Remove-Item -Path "Function:script:$CommandName" - } $script:dnsResolverCommand - } - } - BeforeEach { $script:domains = @() $script:registrableDomains = @{} diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index fbaf964ec3..7402781af2 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -104,4 +104,4 @@ Test-MtCisSpfRecordsPublished -ParkedDomains 'example.com' | Should -BeFalse } -} \ No newline at end of file +} diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index 4eadd65900..d22bc5eeb9 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -57,7 +57,7 @@ if ($found -eq 'Invalid DMARC record') { $invalidCandidate = $candidate } continue } - if ($null -ne $found -and $found.GetType().Name -eq 'DMARCRecord') { + if ($null -ne $found -and $found -isnot [string]) { $dmarc = $found $source = $candidate break From eeb9ff29e53c4a18986da3f9899c9546d0c76b01 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Wed, 4 Nov 2026 14:46:31 +1300 Subject: [PATCH 03/20] Align SPF and parked DKIM audit criteria --- .../Get-MtCisParkedDomainClassification.ps1 | 7 ++++-- ...-MtCisParkedDomainClassification.Tests.ps1 | 23 +++++++++++++++++++ .../Test-MtCisSpfRecordsPublished.Tests.ps1 | 11 +++++++++ .../tests/functions/Test-MtDkim.Tests.ps1 | 16 ++++++++++++- tests/cis/Test.CIS.M365.2.1.8.ps1 | 2 +- tests/cis/Test.CIS.M365.2.1.9.md | 6 ++--- tests/cis/Test.CIS.M365.2.1.9.ps1 | 8 +++---- 7 files changed, 62 insertions(+), 11 deletions(-) diff --git a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 index e4e61cc7a5..6186cec5c2 100644 --- a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 +++ b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 @@ -54,6 +54,7 @@ } else { $null } + $spfHardFailAtEnd = $spfRecord -match '(?i)(?:^|\s)-all\s*$' $spfDoesNotAuthorizeSenders = $spfAllTerms.Count -eq 1 -and $spfAllQualifier -in @('-', '~', '?') -and $spfOtherTerms.Count -eq 0 $spfHasSenderMechanisms = $spfRecord -and -not $spfDoesNotAuthorizeSenders -and ($spfOtherTerms.Count -gt 0 -or $spfAllQualifier -eq '+') @@ -67,7 +68,8 @@ $configDomain -and [string]::Equals([string]$configDomain, $DomainName, [System.StringComparison]::OrdinalIgnoreCase) }) $dkimLookups = @($lookups.GetEnumerator() | Where-Object { $_.Key -like 'DKIM:*' }) - $hasDkimEvidence = $domainConfigs.Count -gt 0 -or @($dkimLookups | Where-Object { @($_.Value.Answers).Count -gt 0 }).Count -gt 0 + $hasDkimSelectorRecordEvidence = @($dkimLookups | Where-Object { @($_.Value.Answers).Count -gt 0 }).Count -gt 0 + $hasDkimEvidence = $domainConfigs.Count -gt 0 -or $hasDkimSelectorRecordEvidence $unknownDkimLookups = @($dkimLookups | Where-Object { $_.Value.Status -notin @('Success', 'NXDomain') }) $classification = 'Unknown' @@ -130,8 +132,9 @@ IsParked = $classification -eq 'Parked' IsOverride = $isOverride SpfRecord = $spfRecord - SpfDeniesAll = $spfDoesNotAuthorizeSenders -and $spfAllQualifier -eq '-' -and $spfRedirectTerms.Count -eq 0 + SpfDeniesAll = $spfDoesNotAuthorizeSenders -and $spfAllQualifier -eq '-' -and $spfRedirectTerms.Count -eq 0 -and $spfHardFailAtEnd DkimEvidence = $hasDkimEvidence + DkimSelectorRecordEvidence = $hasDkimSelectorRecordEvidence Reason = $reason } } diff --git a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 index f2b56b3077..a9123382ec 100644 --- a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 +++ b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 @@ -61,6 +61,17 @@ $result.SpfDeniesAll | Should -BeFalse } + It 'does not accept a parked hard-fail record with a trailing modifier' { + $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 -all exp=explain.example'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' + + $result.Classification | Should -Be 'Parked' + $result.SpfDeniesAll | Should -BeFalse + } + It 'does not classify a domain with fallback address records as parked' { $script:dnsResults['TXT|mail.example'] = ConvertTo-TestDnsResult -Name 'mail.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } @@ -83,6 +94,16 @@ $result.Classification | Should -Be 'Sending' } + It 'separates a signing configuration from published selector evidence for a parked override' { + $config = [pscustomobject]@{ Domain = 'parked.example'; Enabled = $false } + + $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' -DkimSigningConfigs @($config) -ParkedDomains 'parked.example' + + $result.Classification | Should -Be 'Parked' + $result.DkimEvidence | Should -BeTrue + $result.DkimSelectorRecordEvidence | Should -BeFalse + } + It 'classifies a domain with a published standard DKIM selector as sending' { $script:dnsResults['TXT|sender.example'] = ConvertTo-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } @@ -95,6 +116,7 @@ $result.Classification | Should -Be 'Sending' $result.DkimEvidence | Should -BeTrue + $result.DkimSelectorRecordEvidence | Should -BeTrue } It 'applies an explicit parked override while retaining conflicting DKIM evidence' { @@ -107,6 +129,7 @@ $result.Classification | Should -Be 'Parked' $result.IsOverride | Should -BeTrue $result.DkimEvidence | Should -BeTrue + $result.DkimSelectorRecordEvidence | Should -BeTrue } It 'classifies a domain with SPF mechanisms as sending' { diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index 7402781af2..2a458d0b83 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -69,6 +69,17 @@ $script:resultDetail.Investigate | Should -BeFalse } + It 'requires the all qualifier to be the final sending-domain term' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 include:spf.example.net -all include:vendor.example' } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = 'Sending' + SpfDeniesAll = $false + Reason = 'An SPF sending mechanism was found.' + } + + Test-MtCisSpfRecordsPublished | Should -BeFalse + } + It 'investigates when a soft-fail record passes only the sending-domain rule' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } $script:classifications['example.com'] = [pscustomobject]@{ diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index 4b7d8c76e9..58f2b2498d 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -21,6 +21,7 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( SpfRecord = $null SpfDeniesAll = $false DkimEvidence = $false + DkimSelectorRecordEvidence = $false Reason = 'Mock domain classification' } } @@ -145,12 +146,25 @@ Describe 'CIS DKIM domain classification outcomes' { It 'fails a parked override when DKIM evidence remains' { Mock -ModuleName Maester Get-MtCisParkedDomainClassification { $classification = if ($ParkedDomains -contains $DomainName) { 'Parked' } else { 'Sending' } - [PSCustomObject]@{ Classification = $classification; DkimEvidence = $true; Reason = 'Explicit parked override.' } + [PSCustomObject]@{ Classification = $classification; DkimEvidence = $true; DkimSelectorRecordEvidence = $true; Reason = 'Explicit parked override.' } } Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeFalse } + It 'passes a parked override with a signing configuration but no published selector records' { + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + [PSCustomObject]@{ + Classification = 'Parked' + DkimEvidence = $true + DkimSelectorRecordEvidence = $false + Reason = 'An Exchange signing configuration exists, but no selector records are published.' + } + } + + Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeTrue + } + It 'marks a non-sending receive domain out of scope for DKIM' { Mock -ModuleName Maester Get-MtCisParkedDomainClassification { [PSCustomObject]@{ Classification = 'NotSending'; IsParked = $false; Reason = 'The domain has receive-only DNS records.' } diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 3980d6d9b1..cf4428ea89 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -93,7 +93,7 @@ [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification.Classification; Pass = $null; Investigate = $false; Detail = "DNS lookup not available for $($redirectTargets[-1])" } continue } - $effectiveAll = [regex]::Match([string]$effective, '(?i)(^|\s)(?[+?~-]?)all(\s|$)') + $effectiveAll = [regex]::Match([string]$effective, '(?i)(^|\s)(?[+?~-]?)all\s*$') $sendingDomainPass = $effectiveAll.Success -and $effectiveAll.Groups['q'].Value -in '-', '~' $pass = $sendingDomainPass $investigate = $false diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index facb7b91d8..a060c0fada 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -16,9 +16,9 @@ For domains classified as sending, the check requires Exchange DKIM to be enable Maester classifies a domain as not sending when its single SPF v1 record has only a non-authorizing `-all`, `~all`, or `?all` mechanism and no Exchange DKIM signing configuration or selector1/selector2 records are found. It is classified as parked only when it also has no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This classification does not use `AcceptedDomain.SendingFromDomainDisabled`. -For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no Exchange DKIM configuration or standard selector1/selector2 records are found. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence, or failed DNS lookups, are marked for investigation rather than automatically treated as parked. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. +For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence, or failed DNS lookups, are marked for investigation rather than automatically treated as parked. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. -When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; any detected Exchange DKIM configuration or standard selector record still fails the check. +When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; any published standard selector record still fails the check. #### Remediation action @@ -52,7 +52,7 @@ The initial domain is the domain that you used when you signed up for Office 365 5. Select **DKIM** 6. Click on each domain and click **Enable** next to **Sign messages for this domain with DKIM signature**. -For a confirmed parked domain, do not create an Exchange DKIM signing configuration or publish selector records. Before removing existing records, confirm the domain is not used to send email through Exchange Online or another service. +For a confirmed parked domain, do not publish standard DKIM selector records. An unused Exchange signing configuration alone does not fail this audit; remove it if the domain no longer needs it. Before removing existing records, confirm the domain is not used to send email through Exchange Online or another service. Final remediation step using the Exchange Online PowerShell Module: diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index d645d0bd3b..5eb1929f92 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -38,7 +38,7 @@ # Selector-name for the DKIM record to test.. [string]$Selector = 'selector1', - # Domains explicitly confirmed as parked; any detected DKIM configuration or selector still fails the audit. + # Domains explicitly confirmed as parked; any published selector record still fails the audit. [string[]]$ParkedDomains = @() ) @@ -62,12 +62,12 @@ $classification = Get-MtCisParkedDomainClassification -DomainName $domain.DomainName -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains if ($classification.Classification -eq 'Parked') { - $hasDkimEvidence = $classification.DkimEvidence + $hasDkimSelectorRecord = $classification.DkimSelectorRecordEvidence $dkimRecords += [PSCustomObject]@{ domain = $domain.DomainName classification = $classification.Classification - pass = if ($hasDkimEvidence) { 'Failed' } else { 'Passed' } - reason = if ($hasDkimEvidence) { "Parked domain has a DKIM configuration or known selector record that must be removed. $($classification.Reason)" } else { "Parked domain has no known DKIM selector records. $($classification.Reason)" } + pass = if ($hasDkimSelectorRecord) { 'Failed' } else { 'Passed' } + reason = if ($hasDkimSelectorRecord) { "Parked domain has a published standard DKIM selector record that must be removed. $($classification.Reason)" } else { "Parked domain has no published standard DKIM selector records. $($classification.Reason)" } exchangeStatus = 'Not applicable' dkimRecord = $null } From 27aee8c4074f94867b5fa4bf6de56553d3cf3dfe Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Wed, 4 Nov 2026 15:15:36 +1300 Subject: [PATCH 04/20] Investigate incomplete parked DKIM lookups --- .../Get-MtCisParkedDomainClassification.ps1 | 1 + ...t-MtCisParkedDomainClassification.Tests.ps1 | 8 +++++--- .../tests/functions/Test-MtDkim.Tests.ps1 | 18 +++++++++++++++++- tests/cis/Test.CIS.M365.2.1.9.md | 2 +- tests/cis/Test.CIS.M365.2.1.9.ps1 | 7 ++++--- 5 files changed, 28 insertions(+), 8 deletions(-) diff --git a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 index 6186cec5c2..4188c6361a 100644 --- a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 +++ b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 @@ -135,6 +135,7 @@ SpfDeniesAll = $spfDoesNotAuthorizeSenders -and $spfAllQualifier -eq '-' -and $spfRedirectTerms.Count -eq 0 -and $spfHardFailAtEnd DkimEvidence = $hasDkimEvidence DkimSelectorRecordEvidence = $hasDkimSelectorRecordEvidence + DkimSelectorLookupsComplete = $unknownDkimLookups.Count -eq 0 Reason = $reason } } diff --git a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 index a9123382ec..4aa1c3813f 100644 --- a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 +++ b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 @@ -102,6 +102,7 @@ $result.Classification | Should -Be 'Parked' $result.DkimEvidence | Should -BeTrue $result.DkimSelectorRecordEvidence | Should -BeFalse + $result.DkimSelectorLookupsComplete | Should -BeTrue } It 'classifies a domain with a published standard DKIM selector as sending' { @@ -170,14 +171,15 @@ $result.SpfDeniesAll | Should -BeFalse } - It 'leaves a domain unknown when a DKIM DNS lookup fails' { + It 'exposes incomplete selector lookup state when a parked override is supplied' { $script:dnsResults['TXT|unknown.example'] = ConvertTo-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } ) $script:dnsResults['CNAME|selector1._domainkey.unknown.example'] = ConvertTo-TestDnsResult -Name 'selector1._domainkey.unknown.example' -Type CNAME -Status Error - $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' + $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' -ParkedDomains 'unknown.example' - $result.Classification | Should -Be 'Unknown' + $result.Classification | Should -Be 'Parked' + $result.DkimSelectorLookupsComplete | Should -BeFalse } } diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index 58f2b2498d..5dd6b83b4d 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -22,6 +22,7 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( SpfDeniesAll = $false DkimEvidence = $false DkimSelectorRecordEvidence = $false + DkimSelectorLookupsComplete = $true Reason = 'Mock domain classification' } } @@ -146,7 +147,7 @@ Describe 'CIS DKIM domain classification outcomes' { It 'fails a parked override when DKIM evidence remains' { Mock -ModuleName Maester Get-MtCisParkedDomainClassification { $classification = if ($ParkedDomains -contains $DomainName) { 'Parked' } else { 'Sending' } - [PSCustomObject]@{ Classification = $classification; DkimEvidence = $true; DkimSelectorRecordEvidence = $true; Reason = 'Explicit parked override.' } + [PSCustomObject]@{ Classification = $classification; DkimEvidence = $true; DkimSelectorRecordEvidence = $true; DkimSelectorLookupsComplete = $true; Reason = 'Explicit parked override.' } } Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeFalse @@ -158,6 +159,7 @@ Describe 'CIS DKIM domain classification outcomes' { Classification = 'Parked' DkimEvidence = $true DkimSelectorRecordEvidence = $false + DkimSelectorLookupsComplete = $true Reason = 'An Exchange signing configuration exists, but no selector records are published.' } } @@ -165,6 +167,20 @@ Describe 'CIS DKIM domain classification outcomes' { Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeTrue } + It 'investigates a parked override when selector DNS lookups are incomplete' { + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + [PSCustomObject]@{ + Classification = 'Parked' + DkimSelectorRecordEvidence = $false + DkimSelectorLookupsComplete = $false + Reason = 'A selector DNS lookup failed.' + } + } + + Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeTrue + $script:detail.Investigate | Should -BeTrue + } + It 'marks a non-sending receive domain out of scope for DKIM' { Mock -ModuleName Maester Get-MtCisParkedDomainClassification { [PSCustomObject]@{ Classification = 'NotSending'; IsParked = $false; Reason = 'The domain has receive-only DNS records.' } diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index a060c0fada..d423535c33 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -16,7 +16,7 @@ For domains classified as sending, the check requires Exchange DKIM to be enable Maester classifies a domain as not sending when its single SPF v1 record has only a non-authorizing `-all`, `~all`, or `?all` mechanism and no Exchange DKIM signing configuration or selector1/selector2 records are found. It is classified as parked only when it also has no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This classification does not use `AcceptedDomain.SendingFromDomainDisabled`. -For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence, or failed DNS lookups, are marked for investigation rather than automatically treated as parked. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. +For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence are marked for investigation rather than automatically treated as parked. If any selector lookup fails, the check reports investigation even when `ParkedDomains` explicitly selects the parked branch; a pass requires all four selector1/selector2 CNAME/TXT lookups to return Success or NXDOMAIN with no records found. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; any published standard selector record still fails the check. diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index 5eb1929f92..95fb92861c 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -63,12 +63,13 @@ $classification = Get-MtCisParkedDomainClassification -DomainName $domain.DomainName -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains if ($classification.Classification -eq 'Parked') { $hasDkimSelectorRecord = $classification.DkimSelectorRecordEvidence + $selectorLookupsComplete = $classification.DkimSelectorLookupsComplete $dkimRecords += [PSCustomObject]@{ domain = $domain.DomainName classification = $classification.Classification - pass = if ($hasDkimSelectorRecord) { 'Failed' } else { 'Passed' } - reason = if ($hasDkimSelectorRecord) { "Parked domain has a published standard DKIM selector record that must be removed. $($classification.Reason)" } else { "Parked domain has no published standard DKIM selector records. $($classification.Reason)" } - exchangeStatus = 'Not applicable' + pass = if (-not $selectorLookupsComplete) { 'Investigate' } elseif ($hasDkimSelectorRecord) { 'Failed' } else { 'Passed' } + reason = if (-not $selectorLookupsComplete) { "Standard DKIM selector DNS lookups did not complete, so record absence could not be confirmed. $($classification.Reason)" } elseif ($hasDkimSelectorRecord) { "Parked domain has a published standard DKIM selector record that must be removed. $($classification.Reason)" } else { "Parked domain has no published standard DKIM selector records. $($classification.Reason)" } + exchangeStatus = if ($selectorLookupsComplete) { 'Not applicable' } else { 'Not determined' } dkimRecord = $null } continue From c16b54a4fcc15642b700a957d495d5172a37b4da Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Wed, 4 Nov 2026 15:42:22 +1300 Subject: [PATCH 05/20] Fail parked domains with known DKIM selectors --- powershell/tests/functions/Test-MtDkim.Tests.ps1 | 15 +++++++++++++++ tests/cis/Test.CIS.M365.2.1.9.md | 2 +- tests/cis/Test.CIS.M365.2.1.9.ps1 | 4 ++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index 5dd6b83b4d..9b373eadb4 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -181,6 +181,21 @@ Describe 'CIS DKIM domain classification outcomes' { $script:detail.Investigate | Should -BeTrue } + It 'fails a parked override when a selector record exists and another lookup is incomplete' { + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + [PSCustomObject]@{ + Classification = 'Parked' + DkimSelectorRecordEvidence = $true + DkimSelectorLookupsComplete = $false + Reason = 'A selector record exists and another lookup failed.' + } + } + + Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeFalse + $script:detail.Investigate | Should -BeFalse + $script:detail.Result | Should -Match 'published standard DKIM selector record that must be removed' + } + It 'marks a non-sending receive domain out of scope for DKIM' { Mock -ModuleName Maester Get-MtCisParkedDomainClassification { [PSCustomObject]@{ Classification = 'NotSending'; IsParked = $false; Reason = 'The domain has receive-only DNS records.' } diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index d423535c33..8666f5f690 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -16,7 +16,7 @@ For domains classified as sending, the check requires Exchange DKIM to be enable Maester classifies a domain as not sending when its single SPF v1 record has only a non-authorizing `-all`, `~all`, or `?all` mechanism and no Exchange DKIM signing configuration or selector1/selector2 records are found. It is classified as parked only when it also has no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This classification does not use `AcceptedDomain.SendingFromDomainDisabled`. -For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence are marked for investigation rather than automatically treated as parked. If any selector lookup fails, the check reports investigation even when `ParkedDomains` explicitly selects the parked branch; a pass requires all four selector1/selector2 CNAME/TXT lookups to return Success or NXDOMAIN with no records found. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. +For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence are marked for investigation rather than automatically treated as parked. Any known standard selector record fails the parked check even if another selector lookup failed. Incomplete selector lookups report investigation only when no selector record is known; passing requires all four selector1/selector2 CNAME/TXT lookups to return Success or NXDOMAIN with no records found. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; any published standard selector record still fails the check. diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index 95fb92861c..a67fc7f3cb 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -67,8 +67,8 @@ $dkimRecords += [PSCustomObject]@{ domain = $domain.DomainName classification = $classification.Classification - pass = if (-not $selectorLookupsComplete) { 'Investigate' } elseif ($hasDkimSelectorRecord) { 'Failed' } else { 'Passed' } - reason = if (-not $selectorLookupsComplete) { "Standard DKIM selector DNS lookups did not complete, so record absence could not be confirmed. $($classification.Reason)" } elseif ($hasDkimSelectorRecord) { "Parked domain has a published standard DKIM selector record that must be removed. $($classification.Reason)" } else { "Parked domain has no published standard DKIM selector records. $($classification.Reason)" } + pass = if ($hasDkimSelectorRecord) { 'Failed' } elseif (-not $selectorLookupsComplete) { 'Investigate' } else { 'Passed' } + reason = if ($hasDkimSelectorRecord) { "Parked domain has a published standard DKIM selector record that must be removed. $($classification.Reason)" } elseif (-not $selectorLookupsComplete) { "Standard DKIM selector DNS lookups did not complete, so record absence could not be confirmed. $($classification.Reason)" } else { "Parked domain has no published standard DKIM selector records. $($classification.Reason)" } exchangeStatus = if ($selectorLookupsComplete) { 'Not applicable' } else { 'Not determined' } dkimRecord = $null } From 68f3d33170952a84645a114bcbba83c664b81864 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 5 Nov 2026 08:11:23 +1300 Subject: [PATCH 06/20] Investigate incomplete receiving DNS evidence --- .../Get-MtCisParkedDomainClassification.ps1 | 1 + ...-MtCisParkedDomainClassification.Tests.ps1 | 22 +++++++++++++++++++ 2 files changed, 23 insertions(+) diff --git a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 index 4188c6361a..1708c4ae1a 100644 --- a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 +++ b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 @@ -111,6 +111,7 @@ } elseif ($classification -eq 'NotSending') { $failedReceivingLookups = @($lookups.MX, $lookups.A, $lookups.AAAA, $lookups.CNAME | Where-Object { $_.Status -notin @('Success', 'NXDomain') }) if ($failedReceivingLookups.Count -gt 0) { + $classification = 'Unknown' $reason += ' Receiving or other domain use could not be ruled out because some DNS lookups failed.' } elseif ($hasMx -or $hasAddress -or $hasCname) { $reason += ' Receiving or other domain use is present, so the domain is not classified as parked.' diff --git a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 index 4aa1c3813f..8fb2751bb4 100644 --- a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 +++ b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 @@ -86,6 +86,28 @@ $result.IsParked | Should -BeFalse } + It 'leaves a domain unknown when a receiving DNS lookup is incomplete' -ForEach @( + @{ Type = 'MX'; Status = 'Error' } + @{ Type = 'MX'; Status = 'NotAvailable' } + @{ Type = 'A'; Status = 'Error' } + @{ Type = 'A'; Status = 'NotAvailable' } + @{ Type = 'AAAA'; Status = 'Error' } + @{ Type = 'AAAA'; Status = 'NotAvailable' } + @{ Type = 'CNAME'; Status = 'Error' } + @{ Type = 'CNAME'; Status = 'NotAvailable' } + ) { + $script:dnsResults['TXT|uncertain.example'] = ConvertTo-TestDnsResult -Name 'uncertain.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } + ) + $script:dnsResults["$Type|uncertain.example"] = ConvertTo-TestDnsResult -Name 'uncertain.example' -Type $Type -Status $Status + + $result = Get-MtCisParkedDomainClassification -DomainName 'uncertain.example' + + $result.Classification | Should -Be 'Unknown' + $result.IsParked | Should -BeFalse + $result.Reason | Should -Match 'Receiving or other domain use could not be ruled out' + } + It 'classifies a configured DKIM domain as sending' { $config = [pscustomobject]@{ Domain = 'sender.example'; Enabled = $false } From 6b56b5a28657f6946bcb31ed50951036b98b4b07 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Fri, 6 Nov 2026 08:44:00 +1300 Subject: [PATCH 07/20] Fix CIS DNS evidence and share lookup caching Preserve empty TXT answers, keep neutral SPF evidence inconclusive, and distinguish unavailable DNS from non-applicability. Render DMARC investigation rows consistently and share normalized DNS lookup results across the three CIS checks, with cache clearing and regression coverage. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- powershell/Maester.psm1 | 1 + .../Get-MtCisParkedDomainClassification.ps1 | 3 +- .../services/exchange/Resolve-MtDnsRecord.ps1 | 19 ++++- .../public/connect/Clear-MtDnsCache.ps1 | 1 + ...-MtCisParkedDomainClassification.Tests.ps1 | 23 ++++- .../functions/Resolve-MtDnsRecord.Tests.ps1 | 84 +++++++++++++++++++ .../Test-MtCisDmarcRecordsPublished.Tests.ps1 | 2 + .../tests/functions/Test-MtDkim.Tests.ps1 | 13 +++ tests/cis/Test.CIS.M365.2.1.10.md | 2 +- tests/cis/Test.CIS.M365.2.1.10.ps1 | 2 +- tests/cis/Test.CIS.M365.2.1.8.md | 2 +- tests/cis/Test.CIS.M365.2.1.8.ps1 | 2 - tests/cis/Test.CIS.M365.2.1.9.md | 2 +- tests/cis/Test.CIS.M365.2.1.9.ps1 | 32 +++++-- 14 files changed, 173 insertions(+), 15 deletions(-) diff --git a/powershell/Maester.psm1 b/powershell/Maester.psm1 index 0bd9625818..100997c0d0 100644 --- a/powershell/Maester.psm1 +++ b/powershell/Maester.psm1 @@ -21,6 +21,7 @@ $__MtSession = @{ NativeReturnValue = @{} # Native tests of the current run: ID -> what the test returned Connections = @() DnsCache = @() + DnsRecordCache = @{} ExoCache = @{} OrcaCache = @{} AIAgentInfo = $null # Get-MtAIAgentInfo cache: @{ Agents; Error }, Error is why no agent data is available diff --git a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 index 1708c4ae1a..b70e5504cd 100644 --- a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 +++ b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 @@ -55,7 +55,7 @@ $null } $spfHardFailAtEnd = $spfRecord -match '(?i)(?:^|\s)-all\s*$' - $spfDoesNotAuthorizeSenders = $spfAllTerms.Count -eq 1 -and $spfAllQualifier -in @('-', '~', '?') -and $spfOtherTerms.Count -eq 0 + $spfDoesNotAuthorizeSenders = $spfAllTerms.Count -eq 1 -and $spfAllQualifier -in @('-', '~') -and $spfOtherTerms.Count -eq 0 $spfHasSenderMechanisms = $spfRecord -and -not $spfDoesNotAuthorizeSenders -and ($spfOtherTerms.Count -gt 0 -or $spfAllQualifier -eq '+') $domainConfigs = @($DkimSigningConfigs | Where-Object { @@ -137,6 +137,7 @@ DkimEvidence = $hasDkimEvidence DkimSelectorRecordEvidence = $hasDkimSelectorRecordEvidence DkimSelectorLookupsComplete = $unknownDkimLookups.Count -eq 0 + DnsResolverUnavailable = @($lookups.GetEnumerator() | Where-Object { $_.Value.Status -ne 'NotAvailable' }).Count -eq 0 Reason = $reason } } diff --git a/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 index 9421f5f426..43b6093625 100644 --- a/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 +++ b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 @@ -24,6 +24,16 @@ [string]$Type ) + if ($null -eq $__MtSession.DnsRecordCache) { + $__MtSession.DnsRecordCache = @{} + } + + $cacheKey = "$($Type.ToUpperInvariant())|$($Name.TrimEnd('.').ToLowerInvariant())" + if ($__MtSession.DnsRecordCache.ContainsKey($cacheKey)) { + Write-Verbose "DNS record exists in cache for $Type $Name - Use Clear-MtDnsCache to reset" + return $__MtSession.DnsRecordCache[$cacheKey] + } + $result = [pscustomobject]@{ Name = $Name Type = $Type @@ -40,6 +50,7 @@ } catch [System.Management.Automation.CommandNotFoundException] { $result.Status = 'NotAvailable' $result.Error = 'Unsupported platform, Resolve-DnsName not available' + $__MtSession.DnsRecordCache[$cacheKey] = $result return $result } catch { if ($_.FullyQualifiedErrorId -like 'DNS_ERROR_RCODE_NAME_ERROR*') { @@ -48,12 +59,14 @@ $result.Status = 'Error' $result.Error = "$_" } + $__MtSession.DnsRecordCache[$cacheKey] = $result return $result } } else { if (-not (Get-Command -Name 'Resolve-Dns' -ErrorAction SilentlyContinue)) { $result.Status = 'NotAvailable' $result.Error = 'Missing dependency, Resolve-Dns not available' + $__MtSession.DnsRecordCache[$cacheKey] = $result return $result } @@ -66,12 +79,14 @@ $result.Status = 'Error' $result.Error = $response.ErrorMessage } + $__MtSession.DnsRecordCache[$cacheKey] = $result return $result } $answers = @($response.Answers | Where-Object { "$($_.RecordType)" -eq $Type }) } catch { $result.Status = 'Error' $result.Error = "$_" + $__MtSession.DnsRecordCache[$cacheKey] = $result return $result } } @@ -115,10 +130,11 @@ } } - if ($null -eq $value -or [string]::IsNullOrWhiteSpace([string]$value)) { + if ($null -eq $value -or ($Type -ne 'TXT' -and [string]::IsNullOrWhiteSpace([string]$value))) { $result.Status = 'Error' $result.Error = "The DNS resolver returned an unusable $Type answer for $Name." $result.Answers = [object[]]@() + $__MtSession.DnsRecordCache[$cacheKey] = $result return $result } @@ -128,5 +144,6 @@ } } + $__MtSession.DnsRecordCache[$cacheKey] = $result return $result } diff --git a/powershell/public/connect/Clear-MtDnsCache.ps1 b/powershell/public/connect/Clear-MtDnsCache.ps1 index 26076559f5..3d4eec04ea 100644 --- a/powershell/public/connect/Clear-MtDnsCache.ps1 +++ b/powershell/public/connect/Clear-MtDnsCache.ps1 @@ -23,4 +23,5 @@ Write-Verbose -Message "Clearing the results cached from DNS lookups in this session" $__MtSession.DnsCache = @() + $__MtSession.DnsRecordCache = @{} } diff --git a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 index 8fb2751bb4..f71d2438b6 100644 --- a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 +++ b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 @@ -17,12 +17,13 @@ BeforeEach { $script:dnsResults = @{} + $script:dnsDefaultStatus = 'Success' Mock Resolve-MtDnsRecord -ModuleName Maester { $key = "$Type|$Name" if ($script:dnsResults.ContainsKey($key)) { return $script:dnsResults[$key] } - return ConvertTo-TestDnsResult -Name $Name -Type $Type + return ConvertTo-TestDnsResult -Name $Name -Type $Type -Status $script:dnsDefaultStatus } } @@ -61,6 +62,17 @@ $result.SpfDeniesAll | Should -BeFalse } + It 'does not treat a neutral SPF policy as proof that the domain is not sending' { + $script:dnsResults['TXT|uncertain.example'] = ConvertTo-TestDnsResult -Name 'uncertain.example' -Type TXT -Answers @( + [pscustomobject]@{ Value = 'v=spf1 ?all'; Preference = $null } + ) + + $result = Get-MtCisParkedDomainClassification -DomainName 'uncertain.example' + + $result.Classification | Should -Be 'Unknown' + $result.IsParked | Should -BeFalse + } + It 'does not accept a parked hard-fail record with a trailing modifier' { $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 -all exp=explain.example'; Preference = $null } @@ -182,6 +194,15 @@ $result.IsParked | Should -BeFalse } + It 'reports when the DNS resolver is unavailable for every lookup' { + $script:dnsDefaultStatus = 'NotAvailable' + + $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' + + $result.Classification | Should -Be 'Unknown' + $result.DnsResolverUnavailable | Should -BeTrue + } + It 'leaves redirect-only SPF unknown until the redirect target is evaluated' { $script:dnsResults['TXT|unknown.example'] = ConvertTo-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( [pscustomobject]@{ Value = 'v=spf1 redirect=_spf.example.net'; Preference = $null } diff --git a/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 index 09ec5a3738..d5f376cc69 100644 --- a/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 +++ b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 @@ -6,6 +6,7 @@ } BeforeEach { + Clear-MtDnsCache Mock Resolve-DnsName -ModuleName Maester {} } @@ -41,6 +42,43 @@ $result.Answers[0].Value | Should -Be 'v=spf1 -all' } + It 'keeps an empty TXT record without discarding other answers' { + Mock Resolve-DnsName -ModuleName Maester { + @( + [pscustomobject]@{ Section = 'Answer'; Type = 'TXT'; Strings = @('') } + [pscustomobject]@{ Section = 'Answer'; Type = 'TXT'; Strings = @('v=spf1 -all') } + ) + } + + $result = Resolve-MtDnsRecord -Name 'example.com' -Type TXT + + $result.Status | Should -Be 'Success' + $result.Answers.Count | Should -Be 2 + $result.Answers.Value | Should -Contain '' + $result.Answers.Value | Should -Contain 'v=spf1 -all' + } + + It 'caches results by case-insensitive DNS name and record type' { + Mock Resolve-DnsName -ModuleName Maester { + [pscustomobject]@{ Section = 'Answer'; Type = 'TXT'; Strings = @('v=spf1 -all') } + } + + $first = Resolve-MtDnsRecord -Name 'Example.com.' -Type TXT + $second = Resolve-MtDnsRecord -Name 'example.COM' -Type TXT + + $second.Answers[0].Value | Should -Be $first.Answers[0].Value + Should -Invoke Resolve-DnsName -ModuleName Maester -Exactly 1 -ParameterFilter { + $Name -eq 'Example.com.' -and $Type -eq 'TXT' + } + + Clear-MtDnsCache + $null = Resolve-MtDnsRecord -Name 'example.com' -Type TXT + + Should -Invoke Resolve-DnsName -ModuleName Maester -Exactly 2 -ParameterFilter { + $Type -eq 'TXT' + } + } + It 'returns success with no answers when the record type is absent' { $result = Resolve-MtDnsRecord -Name 'example.com' -Type MX @@ -103,6 +141,7 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { } BeforeEach { + Clear-MtDnsCache Mock Resolve-Dns -ModuleName Maester {} } @@ -140,6 +179,51 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { $result.Answers[0].Value | Should -Be 'v=spf1 -all' } + It 'keeps an empty TXT record without discarding other answers' { + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $false + Header = [pscustomobject]@{ ResponseCode = 'NoError' } + Answers = @( + [pscustomobject]@{ RecordType = 'TXT'; Text = @('') } + [pscustomobject]@{ RecordType = 'TXT'; Text = @('v=spf1 -all') } + ) + } + } + + $result = Resolve-MtDnsRecord -Name 'example.com' -Type TXT + + $result.Status | Should -Be 'Success' + $result.Answers.Count | Should -Be 2 + $result.Answers.Value | Should -Contain '' + $result.Answers.Value | Should -Contain 'v=spf1 -all' + } + + It 'caches results by case-insensitive DNS name and record type' { + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $false + Header = [pscustomobject]@{ ResponseCode = 'NoError' } + Answers = @([pscustomobject]@{ RecordType = 'TXT'; Text = @('v=spf1 -all') }) + } + } + + $first = Resolve-MtDnsRecord -Name 'Example.com.' -Type TXT + $second = Resolve-MtDnsRecord -Name 'example.COM' -Type TXT + + $second.Answers[0].Value | Should -Be $first.Answers[0].Value + Should -Invoke Resolve-Dns -ModuleName Maester -Exactly 1 -ParameterFilter { + $Query -eq 'Example.com.' -and $QueryType -eq 'TXT' + } + + Clear-MtDnsCache + $null = Resolve-MtDnsRecord -Name 'example.com' -Type TXT + + Should -Invoke Resolve-Dns -ModuleName Maester -Exactly 2 -ParameterFilter { + $QueryType -eq 'TXT' + } + } + It 'distinguishes a missing DNS name from a resolver failure' { Mock Resolve-Dns -ModuleName Maester { [pscustomobject]@{ diff --git a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 index 034bb46a6b..1631528632 100644 --- a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 @@ -133,6 +133,8 @@ Test-MtCisDmarcRecordsPublished | Should -BeTrue $script:resultDetail.Investigate | Should -BeTrue + $script:resultDetail.Result | Should -Match '\| unknown\.example \| Unknown .* \| Investigate \|' + $script:resultDetail.Result | Should -Not -Match '\| unknown\.example .*✅ Pass \|' } It 'applies an explicit parked override and requires reject policy' { diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index 9b373eadb4..4fd0a98d70 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -144,6 +144,19 @@ Describe 'CIS DKIM domain classification outcomes' { $script:detail.Investigate | Should -BeTrue } + It 'skips with NotSupported when the DNS resolver is unavailable' { + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + [PSCustomObject]@{ + Classification = 'Unknown' + DnsResolverUnavailable = $true + Reason = 'DNS resolver is unavailable.' + } + } + + Test-MtCisDkim | Should -BeNullOrEmpty + $script:detail.SkippedBecause | Should -Be 'NotSupported' + } + It 'fails a parked override when DKIM evidence remains' { Mock -ModuleName Maester Get-MtCisParkedDomainClassification { $classification = if ($ParkedDomains -contains $DomainName) { 'Parked' } else { 'Sending' } diff --git a/tests/cis/Test.CIS.M365.2.1.10.md b/tests/cis/Test.CIS.M365.2.1.10.md index a87d292392..5c394abdca 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.md +++ b/tests/cis/Test.CIS.M365.2.1.10.md @@ -4,7 +4,7 @@ DMARC tells receiving servers what to do with mail that fails SPF and DKIM align The test uses the record at the domain, or at its organisational domain (for example contoso.com for mail.contoso.com) when the domain has no valid record, including a malformed record, applying the subdomain policy where one exists. For sending domains, the policy must apply to 100 percent of mail (no pct tag, or pct=100), and both rua and ruf addresses must be mailto addresses. -Maester identifies a likely non-sending domain when it finds one SPF v1 record with only a non-authorizing `-all`, `~all`, or `?all` mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. It classifies the domain as parked only when those signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. +Maester identifies a likely non-sending domain when it finds one SPF v1 record with only a non-authorizing `-all` or `~all` mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. An SPF record ending in `?all` is inconclusive and does not establish that the domain is unused. It classifies the domain as parked only when the non-sending signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. Parked or non-sending domains use the CIS parked-domain requirement: a valid DMARC record with `p=reject`; rua, ruf, and pct are not required for this branch. Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only SPF policies do not receive the parked exception. When only one of the sending and non-sending audit procedures passes, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index d22bc5eeb9..6ff9b19556 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -137,7 +137,7 @@ $resultMd = "| Domain | Classification | Applied policy | Record found at | Failed checks | Result |`n" $resultMd += "| --- | --- | --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultText = if ($null -eq $row.Pass -and $row.Investigate) { 'Investigate' } elseif ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } + $resultText = if ($row.Investigate) { 'Investigate' } elseif ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } $resultMd += "| $($row.Domain) | $($row.Classification) | $($row.Policy) | $($row.Source) | $(if ($row.Failed) { $row.Failed } else { 'None' }) | $resultText |`n" } diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index 607b65fcb1..5173c0ee4b 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -2,7 +2,7 @@ SPF lists the servers that may send mail for a domain. Receiving servers use it to reject, or to mark as suspicious, mail that pretends to come from your domain. Without an SPF record, or with one that ends in a neutral or permissive qualifier, anyone can send mail that looks like it comes from you without raising a flag. -Maester identifies a likely non-sending domain when it finds one SPF v1 record with no sender-authorizing mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. It classifies the domain as parked only when those signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. +Maester identifies a likely non-sending domain when it finds one SPF v1 record with only a non-authorizing `-all` or `~all` mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. An SPF record ending in `?all` is inconclusive and does not establish that the domain is unused. It classifies the domain as parked only when the non-sending signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. For a parked or non-sending domain, the SPF record must explicitly use `-all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index cf4428ea89..3b2bbf2385 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -138,8 +138,6 @@ } elseif ($unchecked.Count -gt 0) { Add-MtTestResultDetail -SkippedBecause NotSupported return $null - } elseif ($investigated.Count -gt 0) { - $testResult = $true } else { $testResult = $true } diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index 8666f5f690..123c1c3a27 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -14,7 +14,7 @@ There should be no impact of setting up DKIM however, organizations should ensur For domains classified as sending, the check requires Exchange DKIM to be enabled and its status to be **Valid**. A likely sending domain has an SPF sender-authorizing mechanism, an Exchange DKIM signing configuration, or a selector1/selector2 DKIM CNAME/TXT record. -Maester classifies a domain as not sending when its single SPF v1 record has only a non-authorizing `-all`, `~all`, or `?all` mechanism and no Exchange DKIM signing configuration or selector1/selector2 records are found. It is classified as parked only when it also has no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This classification does not use `AcceptedDomain.SendingFromDomainDisabled`. +Maester classifies a domain as not sending when its single SPF v1 record has only a non-authorizing `-all` or `~all` mechanism and no Exchange DKIM signing configuration or selector1/selector2 records are found. An SPF record ending in `?all` is inconclusive and does not establish that the domain is unused. A domain is classified as parked only when it also has no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This classification does not use `AcceptedDomain.SendingFromDomainDisabled`. For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence are marked for investigation rather than automatically treated as parked. Any known standard selector record fails the parked check even if another selector lookup failed. Incomplete selector lookups report investigation only when no selector record is known; passing requires all four selector1/selector2 CNAME/TXT lookups to return Success or NXDOMAIN with no records found. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index a67fc7f3cb..73010a02f3 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -30,7 +30,7 @@ Control = ('cis-m365:2.1.9', 'nist-800-53-r5:SC-8'), Service = 'ExchangeOnline', Author = 'NZLostboy', - Contributor = ('JeanPhilippeGeorge', 'brianreidc7', 'amlhive-tech') + Contributor = ('JeanPhilippeGeorge', 'brianreidc7', 'amlhive-tech', 'JeremyFinney-lgtm') )] [CmdletBinding()] [OutputType([bool])] @@ -88,6 +88,18 @@ } if ($classification.Classification -eq 'Unknown') { + if ($classification.DnsResolverUnavailable) { + $dkimRecords += [PSCustomObject]@{ + domain = $domain.DomainName + classification = $classification.Classification + pass = 'NotSupported' + reason = "DNS resolver is unavailable, so sending use and selector records cannot be evaluated. $($classification.Reason)" + exchangeStatus = 'Not determined' + dkimRecord = $null + } + continue + } + $dkimRecords += [PSCustomObject]@{ domain = $domain.DomainName classification = $classification.Classification @@ -158,7 +170,7 @@ } elseif ($domain.DomainName -like '*.onmicrosoft.com') { $dkimRecord.reason = "Recommendation: Disable sending from domain" } elseif ($dkimRecord.dkimRecord -like '*not available') { - $dkimRecord.pass = 'Skipped' + $dkimRecord.pass = 'NotSupported' $dkimRecord.reason = $dkimRecord.dkimRecord } else { $dkimRecord.reason = $dkimRecord.dkimRecord @@ -167,14 +179,21 @@ $dkimRecords += $dkimRecord } -if ('Failed' -in $dkimRecords.pass) { + if ('Failed' -in $dkimRecords.pass) { $testResult = $false - } elseif ('Investigate' -in $dkimRecords.pass) { + } + elseif ('Investigate' -in $dkimRecords.pass) { $testResult = $true - } elseif ('Passed' -notin $dkimRecords.pass) { + } + elseif ('NotSupported' -in $dkimRecords.pass -and 'Passed' -notin $dkimRecords.pass) { + Add-MtTestResultDetail -SkippedBecause NotSupported + return $null + } + elseif ('Passed' -notin $dkimRecords.pass) { Add-MtTestResultDetail -SkippedBecause NotApplicable return $null - } else { + } + else { $testResult = $true } @@ -195,6 +214,7 @@ if ('Failed' -in $dkimRecords.pass) { switch ($item.pass) { 'Passed' { $itemResult = $passResult } 'Skipped' { $itemResult = $skipResult } + 'NotSupported' { $itemResult = $skipResult } 'Failed' { $itemResult = $failResult } 'Investigate' { $itemResult = '🔎 Investigate' } } From 6ac6cf23cbaeab57429e3b9b79b18925056aed31 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Fri, 6 Nov 2026 09:00:32 +1300 Subject: [PATCH 08/20] Preserve mixed CIS SPF and DMARC investigation results Do not let an unavailable DNS lookup hide another domain requiring investigation. Keep NotSupported when no investigation or failure exists, preserve failure precedence, and document mixed-result reporting with regression tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Test-MtCisDmarcRecordsPublished.Tests.ps1 | 35 +++++++++++++++++++ .../Test-MtCisSpfRecordsPublished.Tests.ps1 | 32 +++++++++++++++++ tests/cis/Test.CIS.M365.2.1.10.md | 2 ++ tests/cis/Test.CIS.M365.2.1.10.ps1 | 2 +- tests/cis/Test.CIS.M365.2.1.8.md | 2 ++ tests/cis/Test.CIS.M365.2.1.8.ps1 | 2 +- 6 files changed, 73 insertions(+), 2 deletions(-) diff --git a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 index 1631528632..2da6953aba 100644 --- a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 @@ -89,6 +89,41 @@ } } + It 'preserves when another DMARC lookup is unavailable' -ForEach @( + @{ Outcome = 'investigation'; Classification = 'Unknown'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedSkip = $null } + @{ Outcome = 'failure'; Classification = 'Sending'; ExpectedResult = $false; ExpectedInvestigation = $false; ExpectedSkip = $null } + @{ Outcome = 'NotSupported without investigation'; Classification = 'Parked'; ExpectedResult = $null; ExpectedInvestigation = $false; ExpectedSkip = 'NotSupported' } + ) { + $script:domains = @( + [pscustomobject]@{ DomainName = 'example.com'; IsCoExistenceDomain = $false } + [pscustomobject]@{ DomainName = 'unavailable.example'; IsCoExistenceDomain = $false } + ) + $script:registrableDomains = @{ + 'example.com' = 'example.com' + 'unavailable.example' = 'unavailable.example' + } + $script:dmarcResults = @{ + 'example.com' = $script:parkedDmarcRecord + 'unavailable.example' = 'DNS lookup unavailable' + } + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = $Classification + Reason = 'Mail-use evidence for this test.' + } + + $actual = Test-MtCisDmarcRecordsPublished + + $actual | Should -Be $ExpectedResult + $script:resultDetail.Investigate | Should -Be $ExpectedInvestigation + $script:resultDetail.SkippedBecause | Should -Be $ExpectedSkip + if ($null -eq $ExpectedSkip) { + $script:resultDetail.Result | Should -Match '\| unavailable\.example .* \| Not checked \|' + if ($ExpectedInvestigation) { + $script:resultDetail.Result | Should -Match '\| example\.com \| Unknown .* \| Investigate \|' + } + } + } + It 'looks up the organizational domain after an invalid subdomain record and reports an invalid effective record' { $script:domains = @([pscustomobject]@{ DomainName = 'mail.example.com'; IsCoExistenceDomain = $false }) $script:registrableDomains = @{ 'mail.example.com' = 'example.com' } diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index 2a458d0b83..8e3fc2ab6c 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -92,6 +92,38 @@ $script:resultDetail.Investigate | Should -BeTrue } + It 'preserves when another SPF lookup is unavailable' -ForEach @( + @{ Outcome = 'investigation'; Classification = 'Unknown'; Record = 'v=spf1 ~all'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedSkip = $null } + @{ Outcome = 'failure'; Classification = 'Sending'; Record = 'v=spf1 ?all'; ExpectedResult = $false; ExpectedInvestigation = $false; ExpectedSkip = $null } + @{ Outcome = 'NotSupported without investigation'; Classification = 'Sending'; Record = 'v=spf1 ~all'; ExpectedResult = $null; ExpectedInvestigation = $false; ExpectedSkip = 'NotSupported' } + ) { + $script:domains += [pscustomobject]@{ DomainName = 'unavailable.example'; InitialDomain = $false; IsCoExistenceDomain = $false } + $script:spfResults['example.com'] = [pscustomobject]@{ record = $Record } + $script:spfResults['unavailable.example'] = 'DNS lookup unavailable' + $script:classifications['example.com'] = [pscustomobject]@{ + Classification = $Classification + SpfDeniesAll = $false + Reason = 'Mail-use evidence for this test.' + } + $script:classifications['unavailable.example'] = [pscustomobject]@{ + Classification = 'Unknown' + SpfDeniesAll = $false + Reason = 'DNS lookup unavailable.' + } + + $actual = Test-MtCisSpfRecordsPublished + + $actual | Should -Be $ExpectedResult + $script:resultDetail.Investigate | Should -Be $ExpectedInvestigation + $script:resultDetail.SkippedBecause | Should -Be $ExpectedSkip + if ($null -eq $ExpectedSkip) { + $script:resultDetail.Result | Should -Match '\| unavailable\.example .* \| Not checked \|' + if ($ExpectedInvestigation) { + $script:resultDetail.Result | Should -Match '\| example\.com \| Unknown .* \| Investigate \|' + } + } + } + It 'investigates an indirect all policy when parked status is unknown' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 redirect=_spf.example.net' } $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 -all' } diff --git a/tests/cis/Test.CIS.M365.2.1.10.md b/tests/cis/Test.CIS.M365.2.1.10.md index 5c394abdca..c76c05f0cf 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.md +++ b/tests/cis/Test.CIS.M365.2.1.10.md @@ -8,6 +8,8 @@ Maester identifies a likely non-sending domain when it finds one SPF v1 record w Parked or non-sending domains use the CIS parked-domain requirement: a valid DMARC record with `p=reject`; rua, ruf, and pct are not required for this branch. Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only SPF policies do not receive the parked exception. When only one of the sending and non-sending audit procedures passes, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. +When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. This is not confirmation of compliance for those domains. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. + When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement for a valid DMARC record with `p=reject`. #### Remediation action diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index 6ff9b19556..61dec4c3be 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -125,7 +125,7 @@ $unchecked = @($report | Where-Object { $null -eq $_.Pass -and -not $_.Investigate }) $failed = @($checked | Where-Object { -not $_.Pass }) $investigated = @($report | Where-Object { $_.Investigate }) - if ($failed.Count -eq 0 -and $unchecked.Count -gt 0) { + if ($failed.Count -eq 0 -and $unchecked.Count -gt 0 -and $investigated.Count -eq 0) { Add-MtTestResultDetail -SkippedBecause NotSupported return $null } diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index 5173c0ee4b..7c1ed5b096 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -8,6 +8,8 @@ For a parked or non-sending domain, the SPF record must explicitly use `-all`; a Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only policies do not receive the parked exception. When the record passes the sending-domain rule but could fail the parked-domain rule, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. +When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. This is not confirmation of compliance for those domains. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. + When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement to publish `v=spf1 -all`. #### Remediation action diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 3b2bbf2385..8b2e997847 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -135,7 +135,7 @@ $investigated = @($report | Where-Object { $_.Investigate }) if ($failed.Count -gt 0) { $testResult = $false - } elseif ($unchecked.Count -gt 0) { + } elseif ($unchecked.Count -gt 0 -and $investigated.Count -eq 0) { Add-MtTestResultDetail -SkippedBecause NotSupported return $null } else { From b070ea66f41ceab3ea4265e1b362b5d0595b2153 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Fri, 6 Nov 2026 09:22:07 +1300 Subject: [PATCH 09/20] Avoid compliance banners for CIS investigation results State that SPF and DMARC compliance remains unconfirmed when investigation or unchecked rows exist. Preserve full-compliance wording for confirmed results and retain prior classification, caching and mixed-result behavior, with banner regression assertions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 | 6 ++++++ .../tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 | 6 ++++++ tests/cis/Test.CIS.M365.2.1.10.md | 2 +- tests/cis/Test.CIS.M365.2.1.10.ps1 | 5 ++++- tests/cis/Test.CIS.M365.2.1.8.md | 2 +- tests/cis/Test.CIS.M365.2.1.8.ps1 | 5 ++++- 6 files changed, 22 insertions(+), 4 deletions(-) diff --git a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 index 2da6953aba..e37640a180 100644 --- a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 @@ -120,6 +120,8 @@ $script:resultDetail.Result | Should -Match '\| unavailable\.example .* \| Not checked \|' if ($ExpectedInvestigation) { $script:resultDetail.Result | Should -Match '\| example\.com \| Unknown .* \| Investigate \|' + $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' + $script:resultDetail.Result | Should -Not -Match 'Well done|All accepted domains meet' } } } @@ -170,6 +172,9 @@ $script:resultDetail.Investigate | Should -BeTrue $script:resultDetail.Result | Should -Match '\| unknown\.example \| Unknown .* \| Investigate \|' $script:resultDetail.Result | Should -Not -Match '\| unknown\.example .*✅ Pass \|' + $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' + $script:resultDetail.Result | Should -Match 'Review the domains marked Investigate or Not checked' + $script:resultDetail.Result | Should -Not -Match 'Well done|All accepted domains meet' } It 'applies an explicit parked override and requires reject policy' { @@ -189,5 +194,6 @@ Test-MtCisDmarcRecordsPublished | Should -BeTrue $script:resultDetail.Investigate | Should -BeFalse + $script:resultDetail.Result | Should -Match 'Well done\. All accepted domains meet' } } diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index 8e3fc2ab6c..572381b4c3 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -67,6 +67,7 @@ Test-MtCisSpfRecordsPublished | Should -BeTrue $script:resultDetail.Investigate | Should -BeFalse + $script:resultDetail.Result | Should -Match 'Well done\. All custom domains meet' } It 'requires the all qualifier to be the final sending-domain term' { @@ -90,6 +91,9 @@ Test-MtCisSpfRecordsPublished | Should -BeTrue $script:resultDetail.Investigate | Should -BeTrue + $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' + $script:resultDetail.Result | Should -Match 'Review the domains marked Investigate or Not checked' + $script:resultDetail.Result | Should -Not -Match 'Well done|All custom domains meet' } It 'preserves when another SPF lookup is unavailable' -ForEach @( @@ -120,6 +124,8 @@ $script:resultDetail.Result | Should -Match '\| unavailable\.example .* \| Not checked \|' if ($ExpectedInvestigation) { $script:resultDetail.Result | Should -Match '\| example\.com \| Unknown .* \| Investigate \|' + $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' + $script:resultDetail.Result | Should -Not -Match 'Well done|All custom domains meet' } } } diff --git a/tests/cis/Test.CIS.M365.2.1.10.md b/tests/cis/Test.CIS.M365.2.1.10.md index c76c05f0cf..386254716a 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.md +++ b/tests/cis/Test.CIS.M365.2.1.10.md @@ -8,7 +8,7 @@ Maester identifies a likely non-sending domain when it finds one SPF v1 record w Parked or non-sending domains use the CIS parked-domain requirement: a valid DMARC record with `p=reject`; rua, ruf, and pct are not required for this branch. Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only SPF policies do not receive the parked exception. When only one of the sending and non-sending audit procedures passes, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. -When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. This is not confirmation of compliance for those domains. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. +When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. Investigation results state that compliance remains unconfirmed and direct you to review these domains instead of displaying a full-compliance banner. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement for a valid DMARC record with `p=reject`. diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index 61dec4c3be..b1433b3626 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -141,7 +141,10 @@ $resultMd += "| $($row.Domain) | $($row.Classification) | $($row.Policy) | $($row.Source) | $(if ($row.Failed) { $row.Failed } else { 'None' }) | $resultText |`n" } - if ($testResult) { + if ($testResult -and ($investigated.Count -gt 0 -or $unchecked.Count -gt 0)) { + $testResultMarkdown = "Compliance with the applicable CIS DMARC requirement remains unconfirmed. Review the domains marked Investigate or Not checked.`n`n%TestResult%" + } + elseif ($testResult) { $testResultMarkdown = "Well done. $passText`n`n%TestResult%" } else { $testResultMarkdown = "$failText`n`n%TestResult%" diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index 7c1ed5b096..f0373b623b 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -8,7 +8,7 @@ For a parked or non-sending domain, the SPF record must explicitly use `-all`; a Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only policies do not receive the parked exception. When the record passes the sending-domain rule but could fail the parked-domain rule, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. -When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. This is not confirmation of compliance for those domains. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. +When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. Investigation results state that compliance remains unconfirmed and direct you to review these domains instead of displaying a full-compliance banner. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement to publish `v=spf1 -all`. diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 8b2e997847..b5eb54ac11 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -152,7 +152,10 @@ $resultMd += "| $($row.Domain) | $($row.Classification) | $($row.Record) | $($row.Detail) | $resultText |`n" } - if ($testResult) { + if ($testResult -and ($investigated.Count -gt 0 -or $unchecked.Count -gt 0)) { + $testResultMarkdown = "Compliance with the applicable CIS SPF requirement remains unconfirmed. Review the domains marked Investigate or Not checked.`n`n%TestResult%" + } + elseif ($testResult) { $testResultMarkdown = "Well done. $passText`n`n%TestResult%" } else { From d33e0a585d889241256706d0aa98260dcc74eb88 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Fri, 6 Nov 2026 16:01:00 +1300 Subject: [PATCH 10/20] Fix DKIM investigation banners and verify negative DNS caching Avoid full-compliance wording when DKIM investigation or unavailable lookup rows remain. Test mixed-result precedence, cache negative/error outcomes until explicit clearing, and document shared result objects and the retained CIS SPF termination requirement. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../services/exchange/Resolve-MtDnsRecord.ps1 | 2 + .../functions/Resolve-MtDnsRecord.Tests.ps1 | 88 ++++++++++++++++++- .../tests/functions/Test-MtDkim.Tests.ps1 | 57 ++++++++++++ tests/cis/Test.CIS.M365.2.1.8.md | 2 + tests/cis/Test.CIS.M365.2.1.9.md | 2 + tests/cis/Test.CIS.M365.2.1.9.ps1 | 5 +- 6 files changed, 153 insertions(+), 3 deletions(-) diff --git a/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 index 43b6093625..531b17e518 100644 --- a/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 +++ b/powershell/internal/services/exchange/Resolve-MtDnsRecord.ps1 @@ -6,6 +6,8 @@ .DESCRIPTION Uses Resolve-DnsName on Windows and Resolve-Dns from DnsClient-PS on other platforms. A successful query with no answers has Status Success and an empty Answers array. + All lookup outcomes are cached until Clear-MtDnsCache resets the session snapshot. + Cached results are shared read-only objects and retain the first caller's Name spelling. .PARAMETER Name The DNS name to query. diff --git a/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 index d5f376cc69..072d23b62d 100644 --- a/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 +++ b/powershell/tests/functions/Resolve-MtDnsRecord.Tests.ps1 @@ -67,6 +67,8 @@ $second = Resolve-MtDnsRecord -Name 'example.COM' -Type TXT $second.Answers[0].Value | Should -Be $first.Answers[0].Value + [object]::ReferenceEquals($first, $second) | Should -BeTrue + $second.Name | Should -Be 'Example.com.' Should -Invoke Resolve-DnsName -ModuleName Maester -Exactly 1 -ParameterFilter { $Name -eq 'Example.com.' -and $Type -eq 'TXT' } @@ -79,6 +81,44 @@ } } + It 'caches outcomes until explicitly cleared' -ForEach @( + @{ Status = 'Success'; ErrorId = 'DNS_INFO_NO_RECORDS' } + @{ Status = 'NXDomain'; ErrorId = 'DNS_ERROR_RCODE_NAME_ERROR' } + @{ Status = 'Error'; ErrorId = 'DNS_ERROR_RCODE_SERVER_FAILURE' } + @{ Status = 'NotAvailable'; ErrorId = 'MissingResolver' } + ) { + Mock Resolve-DnsName -ModuleName Maester { + if ($Status -eq 'NotAvailable') { + throw [System.Management.Automation.CommandNotFoundException]::new('Resolver unavailable.') + } + throw [System.Management.Automation.ErrorRecord]::new( + [System.Exception]::new('Negative DNS test result.'), + $ErrorId, + [System.Management.Automation.ErrorCategory]::ResourceUnavailable, + $null + ) + } + + $first = Resolve-MtDnsRecord -Name 'negative.example' -Type MX + Mock Resolve-DnsName -ModuleName Maester { + [pscustomobject]@{ Section = 'Answer'; Type = 'MX'; NameExchange = 'mail.example.com'; Preference = 10 } + } + $cached = Resolve-MtDnsRecord -Name 'negative.example' -Type MX + + $first.Status | Should -Be $Status + $cached.Status | Should -Be $Status + $cached.Error | Should -Be $first.Error + $cached.Answers.Count | Should -Be 0 + Should -Invoke Resolve-DnsName -ModuleName Maester -Exactly 1 + + Clear-MtDnsCache + $refreshed = Resolve-MtDnsRecord -Name 'negative.example' -Type MX + + $refreshed.Status | Should -Be 'Success' + $refreshed.Answers[0].Value | Should -Be 'mail.example.com' + Should -Invoke Resolve-DnsName -ModuleName Maester -Exactly 2 + } + It 'returns success with no answers when the record type is absent' { $result = Resolve-MtDnsRecord -Name 'example.com' -Type MX @@ -98,6 +138,7 @@ $missing = Resolve-MtDnsRecord -Name 'missing.example' -Type MX + Clear-MtDnsCache Mock Resolve-DnsName -ModuleName Maester { throw [System.Management.Automation.ErrorRecord]::new( [System.Exception]::new('The DNS server is unavailable.'), @@ -107,10 +148,11 @@ ) } - $unavailable = Resolve-MtDnsRecord -Name 'example.com' -Type MX + $unavailable = Resolve-MtDnsRecord -Name 'missing.example' -Type MX $missing.Status | Should -Be 'NXDomain' $unavailable.Status | Should -Be 'Error' + Should -Invoke Resolve-DnsName -ModuleName Maester -Exactly 2 } } @@ -212,6 +254,8 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { $second = Resolve-MtDnsRecord -Name 'example.COM' -Type TXT $second.Answers[0].Value | Should -Be $first.Answers[0].Value + [object]::ReferenceEquals($first, $second) | Should -BeTrue + $second.Name | Should -Be 'Example.com.' Should -Invoke Resolve-Dns -ModuleName Maester -Exactly 1 -ParameterFilter { $Query -eq 'Example.com.' -and $QueryType -eq 'TXT' } @@ -224,6 +268,44 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { } } + It 'caches outcomes until explicitly cleared' -ForEach @( + @{ Status = 'Success'; ResponseCode = 'NoError'; HasError = $false } + @{ Status = 'NXDomain'; ResponseCode = 'NotExistentDomain'; HasError = $true } + @{ Status = 'Error'; ResponseCode = 'ServerFailure'; HasError = $true } + ) { + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $HasError + Header = [pscustomobject]@{ ResponseCode = $ResponseCode } + ErrorMessage = 'Negative DNS test result.' + Answers = @() + } + } + + $first = Resolve-MtDnsRecord -Name 'negative.example' -Type MX + Mock Resolve-Dns -ModuleName Maester { + [pscustomobject]@{ + HasError = $false + Header = [pscustomobject]@{ ResponseCode = 'NoError' } + Answers = @([pscustomobject]@{ RecordType = 'MX'; Exchange = 'mail.example.com'; Preference = 10 }) + } + } + $cached = Resolve-MtDnsRecord -Name 'negative.example' -Type MX + + $first.Status | Should -Be $Status + $cached.Status | Should -Be $Status + $cached.Error | Should -Be $first.Error + $cached.Answers.Count | Should -Be 0 + Should -Invoke Resolve-Dns -ModuleName Maester -Exactly 1 + + Clear-MtDnsCache + $refreshed = Resolve-MtDnsRecord -Name 'negative.example' -Type MX + + $refreshed.Status | Should -Be 'Success' + $refreshed.Answers[0].Value | Should -Be 'mail.example.com' + Should -Invoke Resolve-Dns -ModuleName Maester -Exactly 2 + } + It 'distinguishes a missing DNS name from a resolver failure' { Mock Resolve-Dns -ModuleName Maester { [pscustomobject]@{ @@ -236,6 +318,7 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { $missing = Resolve-MtDnsRecord -Name 'missing.example' -Type MX + Clear-MtDnsCache Mock Resolve-Dns -ModuleName Maester { [pscustomobject]@{ HasError = $true @@ -245,10 +328,11 @@ Describe 'Resolve-MtDnsRecord with Resolve-Dns' -Skip:$IsWindows { } } - $unavailable = Resolve-MtDnsRecord -Name 'example.com' -Type MX + $unavailable = Resolve-MtDnsRecord -Name 'missing.example' -Type MX $missing.Status | Should -Be 'NXDomain' $unavailable.Status | Should -Be 'Error' $unavailable.Error | Should -Be 'Server Failure' + Should -Invoke Resolve-Dns -ModuleName Maester -Exactly 2 } } diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index 4fd0a98d70..a1923ec2bf 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -142,6 +142,63 @@ Describe 'CIS DKIM domain classification outcomes' { Test-MtCisDkim | Should -BeTrue $script:detail.Investigate | Should -BeTrue + $script:detail.Result | Should -Match 'Compliance .* remains unconfirmed' + $script:detail.Result | Should -Not -Match 'Well done|Sending domains have DKIM configured' + } + + It 'reports a compliant domain alongside without changing result precedence' -ForEach @( + @{ OtherOutcome = 'Investigate'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedUnconfirmed = $true } + @{ OtherOutcome = 'NotSupported'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $true } + @{ OtherOutcome = 'NotApplicable'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } + @{ OtherOutcome = 'Passed'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } + @{ OtherOutcome = 'Failed'; ExpectedResult = $false; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } + ) { + Mock -ModuleName Maester Get-MtExo { + if ($Request -eq 'AcceptedDomain') { + return @( + [PSCustomObject]@{ DomainName = 'compliant.example'; InitialDomain = $false; IsCoexistenceDomain = $false } + [PSCustomObject]@{ DomainName = 'other.example'; InitialDomain = $false; IsCoexistenceDomain = $false } + ) + } + return @() + } + Mock -ModuleName Maester Get-MtCisParkedDomainClassification { + $classification = 'Parked' + $unavailable = $false + $selectorEvidence = $false + if ($DomainName -eq 'other.example') { + switch ($OtherOutcome) { + 'Investigate' { $classification = 'Unknown' } + 'NotSupported' { $classification = 'Unknown'; $unavailable = $true } + 'NotApplicable' { $classification = 'NotSending' } + 'Failed' { $selectorEvidence = $true } + } + } + [PSCustomObject]@{ + Classification = $classification + DnsResolverUnavailable = $unavailable + DkimSelectorRecordEvidence = $selectorEvidence + DkimSelectorLookupsComplete = $true + Reason = 'Mixed-domain test evidence.' + } + } + + Test-MtCisDkim | Should -Be $ExpectedResult + $script:detail.Investigate | Should -Be $ExpectedInvestigation + $script:detail.SkippedBecause | Should -BeNullOrEmpty + $script:detail.Result | Should -Match '\| compliant\.example .*Pass' + $script:detail.Result | Should -Match '\| other\.example \|' + if ($ExpectedUnconfirmed) { + $script:detail.Result | Should -Match 'Compliance .* remains unconfirmed' + $script:detail.Result | Should -Match 'Review the domains marked Investigate or skipped' + $script:detail.Result | Should -Not -Match 'Well done|Sending domains have DKIM configured' + } + elseif ($ExpectedResult) { + $script:detail.Result | Should -Match 'Well done\. Sending domains have DKIM configured' + } + else { + $script:detail.Result | Should -Match "Your tenant's domains do not have DKIM fully deployed" + } } It 'skips with NotSupported when the DNS resolver is unavailable' { diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index f0373b623b..e589abcbd7 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -6,6 +6,8 @@ Maester identifies a likely non-sending domain when it finds one SPF v1 record w For a parked or non-sending domain, the SPF record must explicitly use `-all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. +An `exp=` modifier does not authorize senders and is ignored when classifying domain use. The audit still requires the compliant all mechanism to be the final term: `v=spf1 -all exp=why.example.com` does not meet that termination requirement. + Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only policies do not receive the parked exception. When the record passes the sending-domain rule but could fail the parked-domain rule, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. Investigation results state that compliance remains unconfirmed and direct you to review these domains instead of displaying a full-compliance banner. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index 123c1c3a27..179caa914e 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -18,6 +18,8 @@ Maester classifies a domain as not sending when its single SPF v1 record has onl For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence are marked for investigation rather than automatically treated as parked. Any known standard selector record fails the parked check even if another selector lookup failed. Incomplete selector lookups report investigation only when no selector record is known; passing requires all four selector1/selector2 CNAME/TXT lookups to return Success or NXDOMAIN with no records found. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. +When any domain requires investigation or has unavailable DNS lookups, a result table states that compliance remains unconfirmed instead of displaying a full-compliance banner. Known failures still take precedence, and domains explicitly excluded from the audit do not prevent confirmed in-scope domains from passing. + When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; any published standard selector record still fails the check. #### Remediation action diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index 73010a02f3..50f7937f89 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -199,7 +199,10 @@ $portalLink = 'https://security.microsoft.com/authentication?viewid=DKIM' - if ($testResult) { + if ($testResult -and ('Investigate' -in $dkimRecords.pass -or 'NotSupported' -in $dkimRecords.pass)) { + $testResultMarkdown = "Compliance with the applicable CIS DKIM requirement remains unconfirmed. Review the domains marked Investigate or skipped because DNS lookups are unavailable.`n`n%TestResult%" + } + elseif ($testResult) { $testResultMarkdown = "Well done. Sending domains have DKIM configured and valid records exist, and parked domains have no known Exchange selector records.`n`n%TestResult%" } else { $testResultMarkdown = "Your tenant's domains do not have DKIM fully deployed. Review [EXO configuration]($portalLink) and DNS records.`n`n%TestResult%" From 26a6220b469de163026538085ddb4a3aaf248e5c Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Mon, 9 Nov 2026 06:35:19 +1300 Subject: [PATCH 11/20] Isolate TXT resolver tests from the shared DNS cache Clear the DNS cache before each Resolve-MtDnsTxtRecord test on both resolver paths, preventing cached successful answers from masking the mocked negative responses. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../tests/functions/Test-MtCisaDmarcRecordExist.Tests.ps1 | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/powershell/tests/functions/Test-MtCisaDmarcRecordExist.Tests.ps1 b/powershell/tests/functions/Test-MtCisaDmarcRecordExist.Tests.ps1 index efcb91bab4..765e37e2b3 100644 --- a/powershell/tests/functions/Test-MtCisaDmarcRecordExist.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisaDmarcRecordExist.Tests.ps1 @@ -347,6 +347,10 @@ Describe 'CISA.MS.EXO.4.1 with DNS mocked' { } Describe 'Resolve-MtDnsTxtRecord' { + BeforeEach { + Clear-MtDnsCache + } + Context 'with Resolve-Dns from DnsClient-PS' -Skip:$IsWindows { BeforeAll { $script:createdStub = $false From 4a3c028ee4196f1dd87d0da694a9cdddf0adc739 Mon Sep 17 00:00:00 2001 From: Merill Fernando Date: Tue, 10 Nov 2026 07:29:09 +1100 Subject: [PATCH 12/20] Use only ParkedDomains to mark parked domains in CIS 2.1.8-2.1.10 CIS v7 says what a parked domain needs (v=spf1 -all, no DKIM records, DMARC p=reject) but leaves it to the auditor to say which domains are parked. Drop the DNS-based detection (Get-MtCisParkedDomainClassification and its MX/A/AAAA/CNAME lookups): a domain is parked only when it is listed in the check's ParkedDomains parameter, and every other domain gets the sending-domain audit. This removes the extra lookups that could fail on a flaky network and the Investigate results that came from them. 2.1.9 still looks up the selector1/selector2 records for listed parked domains and reports Investigate when one of those lookups fails. Co-Authored-By: Claude Opus 5.5 Entire-Checkpoint: 01M710079N2ARHB2Q5VDFEP5D5 --- .../Get-MtCisParkedDomainClassification.ps1 | 143 ----------- .../cis/exchange/Test-MtCisParkedDomain.ps1 | 31 +++ ...-MtCisParkedDomainClassification.Tests.ps1 | 228 ------------------ .../Test-MtCisDmarcRecordsPublished.Tests.ps1 | 79 ++---- .../Test-MtCisSpfRecordsPublished.Tests.ps1 | 129 +++------- .../tests/functions/Test-MtDkim.Tests.ps1 | 201 +++++---------- tests/cis/Test.CIS.M365.2.1.10.md | 12 +- tests/cis/Test.CIS.M365.2.1.10.ps1 | 78 ++---- tests/cis/Test.CIS.M365.2.1.8.md | 16 +- tests/cis/Test.CIS.M365.2.1.8.ps1 | 50 ++-- tests/cis/Test.CIS.M365.2.1.9.md | 10 +- tests/cis/Test.CIS.M365.2.1.9.ps1 | 76 +++--- 12 files changed, 234 insertions(+), 819 deletions(-) delete mode 100644 powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 create mode 100644 powershell/internal/checks/cis/exchange/Test-MtCisParkedDomain.ps1 delete mode 100644 powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 diff --git a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 b/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 deleted file mode 100644 index b70e5504cd..0000000000 --- a/powershell/internal/checks/cis/exchange/Get-MtCisParkedDomainClassification.ps1 +++ /dev/null @@ -1,143 +0,0 @@ -function Get-MtCisParkedDomainClassification { - <# - .SYNOPSIS - Classifies an accepted domain using DNS evidence for the CIS email-authentication checks. - - .DESCRIPTION - Sending requires a positive SPF mechanism, a DKIM selector record, or an Exchange DKIM signing - configuration. NotSending requires a single SPF record with only a non-authorizing all - mechanism and no known DKIM selector records or Exchange signing configuration. Parked - additionally requires no MX record (or a null MX) and no address or CNAME record at the domain - apex. Incomplete or conflicting evidence is Unknown and must not receive the parked-domain - audit exception. - - .PARAMETER DomainName - The accepted domain to classify. - - .PARAMETER DkimSigningConfigs - Exchange DKIM signing configurations already retrieved by the calling test. - #> - [CmdletBinding()] - [OutputType([pscustomobject])] - param( - [Parameter(Mandatory)] - [string]$DomainName, - - [object[]]$DkimSigningConfigs = @(), - - [string[]]$ParkedDomains = @() - ) - - $lookups = [ordered]@{ - SPF = Resolve-MtDnsRecord -Name $DomainName -Type TXT - MX = Resolve-MtDnsRecord -Name $DomainName -Type MX - A = Resolve-MtDnsRecord -Name $DomainName -Type A - AAAA = Resolve-MtDnsRecord -Name $DomainName -Type AAAA - CNAME = Resolve-MtDnsRecord -Name $DomainName -Type CNAME - } - foreach ($selector in 'selector1', 'selector2') { - foreach ($type in 'CNAME', 'TXT') { - $lookupName = "$selector._domainkey.$DomainName" - $lookups["DKIM:$selector`:$type"] = Resolve-MtDnsRecord -Name $lookupName -Type $type - } - } - - $spfAnswers = @($lookups.SPF.Answers | ForEach-Object { $_.Value } | Where-Object { $_ -match '^\s*v=spf1(?:\s|$)' }) - $spfRecord = if ($spfAnswers.Count -eq 1) { [string]$spfAnswers[0] } else { $null } - $spfTerms = if ($spfRecord) { @($spfRecord.Trim() -split '\s+' | Select-Object -Skip 1) } else { @() } - $spfAllTerms = @($spfTerms | Where-Object { $_ -match '^(?i)[+?~-]?all$' }) - $spfRedirectTerms = @($spfTerms | Where-Object { $_ -match '^(?i)redirect=' }) - $spfOtherTerms = @($spfTerms | Where-Object { $_ -notmatch '^(?i)[+?~-]?all$' -and $_ -notmatch '^(?i)exp=' -and $_ -notmatch '^(?i)redirect=' }) - $spfAllQualifier = if ($spfAllTerms.Count -eq 1) { - $qualifier = [regex]::Match($spfAllTerms[0], '^(?[+?~-]?)all$', [System.Text.RegularExpressions.RegexOptions]::IgnoreCase).Groups['qualifier'].Value - if ($qualifier) { $qualifier } else { '+' } - } else { - $null - } - $spfHardFailAtEnd = $spfRecord -match '(?i)(?:^|\s)-all\s*$' - $spfDoesNotAuthorizeSenders = $spfAllTerms.Count -eq 1 -and $spfAllQualifier -in @('-', '~') -and $spfOtherTerms.Count -eq 0 - $spfHasSenderMechanisms = $spfRecord -and -not $spfDoesNotAuthorizeSenders -and ($spfOtherTerms.Count -gt 0 -or $spfAllQualifier -eq '+') - - $domainConfigs = @($DkimSigningConfigs | Where-Object { - $configDomain = $null - if ($_.PSObject.Properties['Domain']) { - $configDomain = $_.Domain - } elseif ($_.PSObject.Properties['Name']) { - $configDomain = $_.Name - } - $configDomain -and [string]::Equals([string]$configDomain, $DomainName, [System.StringComparison]::OrdinalIgnoreCase) - }) - $dkimLookups = @($lookups.GetEnumerator() | Where-Object { $_.Key -like 'DKIM:*' }) - $hasDkimSelectorRecordEvidence = @($dkimLookups | Where-Object { @($_.Value.Answers).Count -gt 0 }).Count -gt 0 - $hasDkimEvidence = $domainConfigs.Count -gt 0 -or $hasDkimSelectorRecordEvidence - $unknownDkimLookups = @($dkimLookups | Where-Object { $_.Value.Status -notin @('Success', 'NXDomain') }) - - $classification = 'Unknown' - $reason = 'The DNS evidence does not establish whether the domain sends email.' - if ($hasDkimEvidence -or $spfHasSenderMechanisms) { - $classification = 'Sending' - $reason = 'An Exchange DKIM configuration, a known DKIM selector record, or an SPF mechanism other than -all indicates email-sending use.' - } elseif ($spfDoesNotAuthorizeSenders -and $unknownDkimLookups.Count -eq 0) { - $classification = 'NotSending' - $reason = 'SPF has only a non-authorizing all mechanism and no Exchange DKIM configuration or selector1/selector2 records were found.' - - $mxRecords = @($lookups.MX.Answers) - $nullMx = $mxRecords.Count -eq 1 -and [string]$mxRecords[0].Value -eq '.' -and [string]$mxRecords[0].Preference -eq '0' - $hasMx = @($mxRecords | Where-Object { [string]$_.Value -and [string]$_.Value -ne '.' }).Count -gt 0 - $hasAddress = @($lookups.A.Answers).Count -gt 0 -or @($lookups.AAAA.Answers).Count -gt 0 - $hasCname = @($lookups.CNAME.Answers).Count -gt 0 - $receivingLookupsKnown = @($lookups.MX, $lookups.A, $lookups.AAAA, $lookups.CNAME | Where-Object { $_.Status -notin @('Success', 'NXDomain') }).Count -eq 0 - $hasNoMx = $mxRecords.Count -eq 0 - - if ($receivingLookupsKnown -and -not $hasMx -and -not $hasAddress -and -not $hasCname -and ($hasNoMx -or $nullMx)) { - $classification = 'Parked' - $reason = if ($nullMx) { - 'SPF has only a non-authorizing all mechanism, no DKIM configuration or known selector records exist, and null MX plus no apex address or CNAME records indicates no email or other DNS use.' - } else { - 'SPF has only a non-authorizing all mechanism, no DKIM configuration or known selector records exist, and no MX, fallback address, or apex CNAME records were found.' - } - } - } - - if ($classification -eq 'Unknown') { - $failedLookups = @($lookups.GetEnumerator() | Where-Object { $_.Value.Status -notin @('Success', 'NXDomain') }) - if ($failedLookups.Count -gt 0) { - $reason = "DNS lookup results are incomplete for $($failedLookups.Key -join ', '); the domain is not classified as parked." - } elseif (-not $spfRecord) { - $reason = 'A single SPF v1 record was not found; the domain is not classified as parked.' - } else { - $reason = 'The SPF and DKIM evidence is conflicting or inconclusive; the domain is not classified as parked.' - } - } elseif ($classification -eq 'NotSending') { - $failedReceivingLookups = @($lookups.MX, $lookups.A, $lookups.AAAA, $lookups.CNAME | Where-Object { $_.Status -notin @('Success', 'NXDomain') }) - if ($failedReceivingLookups.Count -gt 0) { - $classification = 'Unknown' - $reason += ' Receiving or other domain use could not be ruled out because some DNS lookups failed.' - } elseif ($hasMx -or $hasAddress -or $hasCname) { - $reason += ' Receiving or other domain use is present, so the domain is not classified as parked.' - } - } - - $isOverride = @($ParkedDomains | Where-Object { - [string]::Equals($_.TrimEnd('.'), $DomainName.TrimEnd('.'), [System.StringComparison]::OrdinalIgnoreCase) - }).Count -gt 0 - if ($isOverride) { - $automaticClassification = $classification - $classification = 'Parked' - $reason = "The domain was explicitly listed in ParkedDomains. Automatic DNS classification was '$automaticClassification'." - } - - return [pscustomobject]@{ - DomainName = $DomainName - Classification = $classification - IsParked = $classification -eq 'Parked' - IsOverride = $isOverride - SpfRecord = $spfRecord - SpfDeniesAll = $spfDoesNotAuthorizeSenders -and $spfAllQualifier -eq '-' -and $spfRedirectTerms.Count -eq 0 -and $spfHardFailAtEnd - DkimEvidence = $hasDkimEvidence - DkimSelectorRecordEvidence = $hasDkimSelectorRecordEvidence - DkimSelectorLookupsComplete = $unknownDkimLookups.Count -eq 0 - DnsResolverUnavailable = @($lookups.GetEnumerator() | Where-Object { $_.Value.Status -ne 'NotAvailable' }).Count -eq 0 - Reason = $reason - } -} diff --git a/powershell/internal/checks/cis/exchange/Test-MtCisParkedDomain.ps1 b/powershell/internal/checks/cis/exchange/Test-MtCisParkedDomain.ps1 new file mode 100644 index 0000000000..b61d56c513 --- /dev/null +++ b/powershell/internal/checks/cis/exchange/Test-MtCisParkedDomain.ps1 @@ -0,0 +1,31 @@ +function Test-MtCisParkedDomain { + <# + .SYNOPSIS + Returns true when a domain is in the list of parked domains an admin gave a CIS email-authentication check. + + .DESCRIPTION + CIS Microsoft 365 Foundations Benchmark v7.0.0 (2.1.8 to 2.1.10) sets different requirements for domains that + are not used to send email, but leaves it to the auditor to say which domains those are. Maester does not + guess from DNS: a domain is parked only when it is listed in the check's ParkedDomains parameter. The + comparison ignores case and a trailing dot. + + .PARAMETER DomainName + The accepted domain to look up. + + .PARAMETER ParkedDomains + The domains the admin listed as parked. + #> + [CmdletBinding()] + [OutputType([bool])] + param( + [Parameter(Mandatory)] + [string]$DomainName, + + [string[]]$ParkedDomains = @() + ) + + $name = $DomainName.TrimEnd('.') + return @($ParkedDomains | Where-Object { + $_ -and [string]::Equals($_.Trim().TrimEnd('.'), $name, [System.StringComparison]::OrdinalIgnoreCase) + }).Count -gt 0 +} diff --git a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 b/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 deleted file mode 100644 index f71d2438b6..0000000000 --- a/powershell/tests/functions/Get-MtCisParkedDomainClassification.Tests.ps1 +++ /dev/null @@ -1,228 +0,0 @@ -Describe 'Get-MtCisParkedDomainClassification' { - BeforeAll { - Import-Module "$PSScriptRoot/../../Maester.psd1" -Force -WarningAction SilentlyContinue - . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" - Use-MtModuleFunction -Name Get-MtCisParkedDomainClassification - - function ConvertTo-TestDnsResult { - param( - [string]$Name, - [string]$Type, - [object[]]$Answers = @(), - [string]$Status = 'Success' - ) - [pscustomobject]@{ Name = $Name; Type = $Type; Status = $Status; Answers = $Answers; Error = $null } - } - } - - BeforeEach { - $script:dnsResults = @{} - $script:dnsDefaultStatus = 'Success' - Mock Resolve-MtDnsRecord -ModuleName Maester { - $key = "$Type|$Name" - if ($script:dnsResults.ContainsKey($key)) { - return $script:dnsResults[$key] - } - return ConvertTo-TestDnsResult -Name $Name -Type $Type -Status $script:dnsDefaultStatus - } - } - - It 'classifies a deny-all domain with null MX and no other DNS use as parked' { - $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } - ) - $script:dnsResults['MX|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type MX -Answers @( - [pscustomobject]@{ Value = '.'; Preference = 0 } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' - - $result.Classification | Should -Be 'Parked' - $result.IsParked | Should -BeTrue - } - - It 'classifies a deny-all domain without MX or fallback addresses as parked' { - $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' - - $result.Classification | Should -Be 'Parked' - } - - It 'classifies a softfail-only domain as parked so the audit can enforce hard fail' { - $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 ~all'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' - - $result.Classification | Should -Be 'Parked' - $result.SpfDeniesAll | Should -BeFalse - } - - It 'does not treat a neutral SPF policy as proof that the domain is not sending' { - $script:dnsResults['TXT|uncertain.example'] = ConvertTo-TestDnsResult -Name 'uncertain.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 ?all'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'uncertain.example' - - $result.Classification | Should -Be 'Unknown' - $result.IsParked | Should -BeFalse - } - - It 'does not accept a parked hard-fail record with a trailing modifier' { - $script:dnsResults['TXT|parked.example'] = ConvertTo-TestDnsResult -Name 'parked.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 -all exp=explain.example'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' - - $result.Classification | Should -Be 'Parked' - $result.SpfDeniesAll | Should -BeFalse - } - - It 'does not classify a domain with fallback address records as parked' { - $script:dnsResults['TXT|mail.example'] = ConvertTo-TestDnsResult -Name 'mail.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } - ) - $script:dnsResults['A|mail.example'] = ConvertTo-TestDnsResult -Name 'mail.example' -Type A -Answers @( - [pscustomobject]@{ Value = '192.0.2.10'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'mail.example' - - $result.Classification | Should -Be 'NotSending' - $result.IsParked | Should -BeFalse - } - - It 'leaves a domain unknown when a receiving DNS lookup is incomplete' -ForEach @( - @{ Type = 'MX'; Status = 'Error' } - @{ Type = 'MX'; Status = 'NotAvailable' } - @{ Type = 'A'; Status = 'Error' } - @{ Type = 'A'; Status = 'NotAvailable' } - @{ Type = 'AAAA'; Status = 'Error' } - @{ Type = 'AAAA'; Status = 'NotAvailable' } - @{ Type = 'CNAME'; Status = 'Error' } - @{ Type = 'CNAME'; Status = 'NotAvailable' } - ) { - $script:dnsResults['TXT|uncertain.example'] = ConvertTo-TestDnsResult -Name 'uncertain.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } - ) - $script:dnsResults["$Type|uncertain.example"] = ConvertTo-TestDnsResult -Name 'uncertain.example' -Type $Type -Status $Status - - $result = Get-MtCisParkedDomainClassification -DomainName 'uncertain.example' - - $result.Classification | Should -Be 'Unknown' - $result.IsParked | Should -BeFalse - $result.Reason | Should -Match 'Receiving or other domain use could not be ruled out' - } - - It 'classifies a configured DKIM domain as sending' { - $config = [pscustomobject]@{ Domain = 'sender.example'; Enabled = $false } - - $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' -DkimSigningConfigs @($config) - - $result.Classification | Should -Be 'Sending' - } - - It 'separates a signing configuration from published selector evidence for a parked override' { - $config = [pscustomobject]@{ Domain = 'parked.example'; Enabled = $false } - - $result = Get-MtCisParkedDomainClassification -DomainName 'parked.example' -DkimSigningConfigs @($config) -ParkedDomains 'parked.example' - - $result.Classification | Should -Be 'Parked' - $result.DkimEvidence | Should -BeTrue - $result.DkimSelectorRecordEvidence | Should -BeFalse - $result.DkimSelectorLookupsComplete | Should -BeTrue - } - - It 'classifies a domain with a published standard DKIM selector as sending' { - $script:dnsResults['TXT|sender.example'] = ConvertTo-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } - ) - $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = ConvertTo-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( - [pscustomobject]@{ Value = 'selector1-sender._domainkey.example.onmicrosoft.com'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' - - $result.Classification | Should -Be 'Sending' - $result.DkimEvidence | Should -BeTrue - $result.DkimSelectorRecordEvidence | Should -BeTrue - } - - It 'applies an explicit parked override while retaining conflicting DKIM evidence' { - $script:dnsResults['CNAME|selector1._domainkey.sender.example'] = ConvertTo-TestDnsResult -Name 'selector1._domainkey.sender.example' -Type CNAME -Answers @( - [pscustomobject]@{ Value = 'selector1-sender._domainkey.example.onmicrosoft.com'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' -ParkedDomains 'SENDER.EXAMPLE.' - - $result.Classification | Should -Be 'Parked' - $result.IsOverride | Should -BeTrue - $result.DkimEvidence | Should -BeTrue - $result.DkimSelectorRecordEvidence | Should -BeTrue - } - - It 'classifies a domain with SPF mechanisms as sending' { - $script:dnsResults['TXT|sender.example'] = ConvertTo-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 include:spf.example.net -all'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' - - $result.Classification | Should -Be 'Sending' - } - - It 'treats an unqualified all mechanism as a sending signal' { - $script:dnsResults['TXT|sender.example'] = ConvertTo-TestDnsResult -Name 'sender.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 all'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'sender.example' - - $result.Classification | Should -Be 'Sending' - } - - It 'leaves a domain unknown when SPF is missing' { - $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' - - $result.Classification | Should -Be 'Unknown' - $result.IsParked | Should -BeFalse - } - - It 'reports when the DNS resolver is unavailable for every lookup' { - $script:dnsDefaultStatus = 'NotAvailable' - - $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' - - $result.Classification | Should -Be 'Unknown' - $result.DnsResolverUnavailable | Should -BeTrue - } - - It 'leaves redirect-only SPF unknown until the redirect target is evaluated' { - $script:dnsResults['TXT|unknown.example'] = ConvertTo-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 redirect=_spf.example.net'; Preference = $null } - ) - - $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' - - $result.Classification | Should -Be 'Unknown' - $result.SpfDeniesAll | Should -BeFalse - } - - It 'exposes incomplete selector lookup state when a parked override is supplied' { - $script:dnsResults['TXT|unknown.example'] = ConvertTo-TestDnsResult -Name 'unknown.example' -Type TXT -Answers @( - [pscustomobject]@{ Value = 'v=spf1 -all'; Preference = $null } - ) - $script:dnsResults['CNAME|selector1._domainkey.unknown.example'] = ConvertTo-TestDnsResult -Name 'selector1._domainkey.unknown.example' -Type CNAME -Status Error - - $result = Get-MtCisParkedDomainClassification -DomainName 'unknown.example' -ParkedDomains 'unknown.example' - - $result.Classification | Should -Be 'Parked' - $result.DkimSelectorLookupsComplete | Should -BeFalse - } -} diff --git a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 index e37640a180..7a6eb9ce82 100644 --- a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 @@ -32,7 +32,6 @@ $script:domains = @() $script:registrableDomains = @{} $script:dmarcResults = @{} - $script:classifications = @{} $script:dkimSigningConfigs = @() Mock Get-MtExo -ModuleName Maester { @@ -41,17 +40,6 @@ } Mock Get-MtRegistrableDomain -ModuleName Maester { $script:registrableDomains[$DomainName] } Mock ConvertFrom-MailAuthenticationRecordDmarc -ModuleName Maester { $script:dmarcResults[$DomainName] } - Mock Get-MtCisParkedDomainClassification -ModuleName Maester { - $classification = if ($script:classifications.ContainsKey($DomainName)) { - $script:classifications[$DomainName] - } else { - [pscustomobject]@{ Classification = 'Sending'; Reason = 'Sending-domain test default.' } - } - if ($ParkedDomains -contains $DomainName) { - $classification.Classification = 'Parked' - } - return $classification - } Mock Add-MtTestResultDetail -ModuleName Maester { $script:resultDetail = [pscustomobject]@{ Result = $Result; Investigate = [bool]$Investigate; SkippedBecause = $SkippedBecause } } @@ -61,7 +49,6 @@ $script:domains = @() $script:registrableDomains = @{} $script:dmarcResults = @{} - $script:classifications = @{} $script:dkimSigningConfigs = @() $script:resultDetail = $null } @@ -89,10 +76,9 @@ } } - It 'preserves when another DMARC lookup is unavailable' -ForEach @( - @{ Outcome = 'investigation'; Classification = 'Unknown'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedSkip = $null } - @{ Outcome = 'failure'; Classification = 'Sending'; ExpectedResult = $false; ExpectedInvestigation = $false; ExpectedSkip = $null } - @{ Outcome = 'NotSupported without investigation'; Classification = 'Parked'; ExpectedResult = $null; ExpectedInvestigation = $false; ExpectedSkip = 'NotSupported' } + It 'returns when another DMARC lookup is unavailable' -ForEach @( + @{ Outcome = 'a failure'; Parked = @(); ExpectedResult = $false; ExpectedSkip = $null } + @{ Outcome = 'NotSupported'; Parked = @('example.com'); ExpectedResult = $null; ExpectedSkip = 'NotSupported' } ) { $script:domains = @( [pscustomobject]@{ DomainName = 'example.com'; IsCoExistenceDomain = $false } @@ -106,23 +92,11 @@ 'example.com' = $script:parkedDmarcRecord 'unavailable.example' = 'DNS lookup unavailable' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = $Classification - Reason = 'Mail-use evidence for this test.' - } - $actual = Test-MtCisDmarcRecordsPublished - - $actual | Should -Be $ExpectedResult - $script:resultDetail.Investigate | Should -Be $ExpectedInvestigation + Test-MtCisDmarcRecordsPublished -ParkedDomains $Parked | Should -Be $ExpectedResult $script:resultDetail.SkippedBecause | Should -Be $ExpectedSkip if ($null -eq $ExpectedSkip) { $script:resultDetail.Result | Should -Match '\| unavailable\.example .* \| Not checked \|' - if ($ExpectedInvestigation) { - $script:resultDetail.Result | Should -Match '\| example\.com \| Unknown .* \| Investigate \|' - $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' - $script:resultDetail.Result | Should -Not -Match 'Well done|All accepted domains meet' - } } } @@ -147,50 +121,35 @@ $script:domains = @([pscustomobject]@{ DomainName = 'parked.example'; IsCoExistenceDomain = $false }) $script:registrableDomains = @{ 'parked.example' = 'parked.example' } $script:dmarcResults = @{ 'parked.example' = $script:parkedDmarcRecord } - $script:classifications = @{ 'parked.example' = [pscustomobject]@{ Classification = 'Parked'; Reason = 'No mail-use signals were found.' } } - Test-MtCisDmarcRecordsPublished | Should -BeTrue + Test-MtCisDmarcRecordsPublished -ParkedDomains 'parked.example' | Should -BeTrue $script:resultDetail.Investigate | Should -BeFalse + $script:resultDetail.Result | Should -Match '\| parked\.example \| Parked \|' } It 'fails a parked domain whose DMARC policy is quarantine' { $script:domains = @([pscustomobject]@{ DomainName = 'parked.example'; IsCoExistenceDomain = $false }) $script:registrableDomains = @{ 'parked.example' = 'parked.example' } $script:dmarcResults = @{ 'parked.example' = $script:quarantineDmarcRecord } - $script:classifications = @{ 'parked.example' = [pscustomobject]@{ Classification = 'Parked'; Reason = 'No mail-use signals were found.' } } - Test-MtCisDmarcRecordsPublished | Should -BeFalse + Test-MtCisDmarcRecordsPublished -ParkedDomains 'parked.example' | Should -BeFalse + $script:resultDetail.Result | Should -Match 'Parked-domain policy is reject' } - It 'investigates an unknown domain when only the parked-domain policy passes' { - $script:domains = @([pscustomobject]@{ DomainName = 'unknown.example'; IsCoExistenceDomain = $false }) - $script:registrableDomains = @{ 'unknown.example' = 'unknown.example' } - $script:dmarcResults = @{ 'unknown.example' = $script:parkedDmarcRecord } - $script:classifications = @{ 'unknown.example' = [pscustomobject]@{ Classification = 'Unknown'; Reason = 'DNS evidence is incomplete.' } } - - Test-MtCisDmarcRecordsPublished | Should -BeTrue - $script:resultDetail.Investigate | Should -BeTrue - $script:resultDetail.Result | Should -Match '\| unknown\.example \| Unknown .* \| Investigate \|' - $script:resultDetail.Result | Should -Not -Match '\| unknown\.example .*✅ Pass \|' - $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' - $script:resultDetail.Result | Should -Match 'Review the domains marked Investigate or Not checked' - $script:resultDetail.Result | Should -Not -Match 'Well done|All accepted domains meet' - } - - It 'applies an explicit parked override and requires reject policy' { - $script:domains = @([pscustomobject]@{ DomainName = 'unknown.example'; IsCoExistenceDomain = $false }) - $script:registrableDomains = @{ 'unknown.example' = 'unknown.example' } - $script:dmarcResults = @{ 'unknown.example' = $script:quarantineDmarcRecord } - $script:classifications = @{ 'unknown.example' = [pscustomobject]@{ Classification = 'Unknown'; Reason = 'DNS evidence is incomplete.' } } + It 'applies the sending-domain audit to a domain that is not listed' { + $script:domains = @([pscustomobject]@{ DomainName = 'parked.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'parked.example' = 'parked.example' } + $script:dmarcResults = @{ 'parked.example' = $script:parkedDmarcRecord } - Test-MtCisDmarcRecordsPublished -ParkedDomains 'unknown.example' | Should -BeFalse + Test-MtCisDmarcRecordsPublished | Should -BeFalse + $script:resultDetail.Result | Should -Match '\| parked\.example \| Sending \|' + $script:resultDetail.Result | Should -Match 'Aggregate reports \(rua\)' } - It 'accepts a fully compliant DMARC record when both procedures pass' { - $script:domains = @([pscustomobject]@{ DomainName = 'unknown.example'; IsCoExistenceDomain = $false }) - $script:registrableDomains = @{ 'unknown.example' = 'unknown.example' } - $script:dmarcResults = @{ 'unknown.example' = $script:fullyCompliantDmarcRecord } - $script:classifications = @{ 'unknown.example' = [pscustomobject]@{ Classification = 'Unknown'; Reason = 'DNS evidence is incomplete.' } } + It 'accepts a fully compliant DMARC record for a sending domain' { + $script:domains = @([pscustomobject]@{ DomainName = 'sending.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'sending.example' = 'sending.example' } + $script:dmarcResults = @{ 'sending.example' = $script:fullyCompliantDmarcRecord } Test-MtCisDmarcRecordsPublished | Should -BeTrue $script:resultDetail.Investigate | Should -BeFalse diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index 572381b4c3..bd1d826af6 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -6,16 +6,9 @@ Mock Get-MtExo -ModuleName Maester { if ($Request -eq 'AcceptedDomain') { return $script:domains } - return $script:dkimSigningConfigs + return @() } Mock ConvertFrom-MailAuthenticationRecordSpf -ModuleName Maester { $script:spfResults[$DomainName] } - Mock Get-MtCisParkedDomainClassification -ModuleName Maester { - $classification = $script:classifications[$DomainName] - if ($ParkedDomains -contains $DomainName) { - $classification.Classification = 'Parked' - } - return $classification - } Mock Add-MtTestResultDetail -ModuleName Maester { $script:resultDetail = [pscustomobject]@{ Result = $Result @@ -27,130 +20,80 @@ BeforeEach { $script:domains = @([pscustomobject]@{ DomainName = 'example.com'; InitialDomain = $false; IsCoExistenceDomain = $false }) - $script:dkimSigningConfigs = @() $script:spfResults = @{} - $script:classifications = @{} $script:resultDetail = $null } It 'requires a hard-fail SPF record for a parked domain' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = 'Parked' - SpfDeniesAll = $false - Reason = 'No sending or receiving signals were found.' - } - Test-MtCisSpfRecordsPublished | Should -BeFalse - $script:resultDetail.Result | Should -Match 'parked/non-sending audit requires an SPF record' + Test-MtCisSpfRecordsPublished -ParkedDomains 'example.com' | Should -BeFalse + $script:resultDetail.Result | Should -Match 'CIS requires v=spf1 -all' + $script:resultDetail.Result | Should -Match '\| example\.com \| Parked \|' } - It 'accepts a hard-fail SPF record for a parked domain' { - $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 -all' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = 'Parked' - SpfDeniesAll = $true - Reason = 'No sending or receiving signals were found.' - } + It 'accepts for a parked domain' -ForEach @( + @{ Record = 'v=spf1 -all' } + @{ Record = 'V=SPF1 -ALL ' } + @{ Record = 'v=spf1 exp=why.example.com -all' } + ) { + $script:spfResults['example.com'] = [pscustomobject]@{ record = $Record } + + Test-MtCisSpfRecordsPublished -ParkedDomains 'Example.com.' | Should -BeTrue + $script:resultDetail.Investigate | Should -BeFalse + } + + It 'rejects for a parked domain' -ForEach @( + @{ Record = 'v=spf1 include:spf.protection.outlook.com -all' } + @{ Record = 'v=spf1 redirect=_spf.example.net' } + @{ Record = 'v=spf1 -all exp=why.example.com' } + ) { + $script:spfResults['example.com'] = [pscustomobject]@{ record = $Record } + $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 -all' } + + Test-MtCisSpfRecordsPublished -ParkedDomains 'example.com' | Should -BeFalse + } + + It 'applies the sending-domain rule to a domain that is not listed' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } Test-MtCisSpfRecordsPublished | Should -BeTrue $script:resultDetail.Investigate | Should -BeFalse + $script:resultDetail.Result | Should -Match '\| example\.com \| Sending \|' } It 'keeps the soft-fail rule for sending domains' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 include:spf.example.net ~all' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = 'Sending' - SpfDeniesAll = $false - Reason = 'An SPF sending mechanism was found.' - } Test-MtCisSpfRecordsPublished | Should -BeTrue - $script:resultDetail.Investigate | Should -BeFalse $script:resultDetail.Result | Should -Match 'Well done\. All custom domains meet' } It 'requires the all qualifier to be the final sending-domain term' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 include:spf.example.net -all include:vendor.example' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = 'Sending' - SpfDeniesAll = $false - Reason = 'An SPF sending mechanism was found.' - } Test-MtCisSpfRecordsPublished | Should -BeFalse } - It 'investigates when a soft-fail record passes only the sending-domain rule' { - $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = 'Unknown' - SpfDeniesAll = $false - Reason = 'Mail use is inconclusive.' - } + It 'follows a redirect for a sending domain' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 redirect=_spf.example.net' } + $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 include:spf.protection.outlook.com -all' } Test-MtCisSpfRecordsPublished | Should -BeTrue - $script:resultDetail.Investigate | Should -BeTrue - $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' - $script:resultDetail.Result | Should -Match 'Review the domains marked Investigate or Not checked' - $script:resultDetail.Result | Should -Not -Match 'Well done|All custom domains meet' } - It 'preserves when another SPF lookup is unavailable' -ForEach @( - @{ Outcome = 'investigation'; Classification = 'Unknown'; Record = 'v=spf1 ~all'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedSkip = $null } - @{ Outcome = 'failure'; Classification = 'Sending'; Record = 'v=spf1 ?all'; ExpectedResult = $false; ExpectedInvestigation = $false; ExpectedSkip = $null } - @{ Outcome = 'NotSupported without investigation'; Classification = 'Sending'; Record = 'v=spf1 ~all'; ExpectedResult = $null; ExpectedInvestigation = $false; ExpectedSkip = 'NotSupported' } + It 'returns when another SPF lookup is unavailable' -ForEach @( + @{ Outcome = 'a failure'; Record = 'v=spf1 ?all'; ExpectedResult = $false; ExpectedSkip = $null } + @{ Outcome = 'NotSupported'; Record = 'v=spf1 ~all'; ExpectedResult = $null; ExpectedSkip = 'NotSupported' } ) { $script:domains += [pscustomobject]@{ DomainName = 'unavailable.example'; InitialDomain = $false; IsCoExistenceDomain = $false } $script:spfResults['example.com'] = [pscustomobject]@{ record = $Record } $script:spfResults['unavailable.example'] = 'DNS lookup unavailable' - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = $Classification - SpfDeniesAll = $false - Reason = 'Mail-use evidence for this test.' - } - $script:classifications['unavailable.example'] = [pscustomobject]@{ - Classification = 'Unknown' - SpfDeniesAll = $false - Reason = 'DNS lookup unavailable.' - } - $actual = Test-MtCisSpfRecordsPublished - - $actual | Should -Be $ExpectedResult - $script:resultDetail.Investigate | Should -Be $ExpectedInvestigation + Test-MtCisSpfRecordsPublished | Should -Be $ExpectedResult $script:resultDetail.SkippedBecause | Should -Be $ExpectedSkip if ($null -eq $ExpectedSkip) { $script:resultDetail.Result | Should -Match '\| unavailable\.example .* \| Not checked \|' - if ($ExpectedInvestigation) { - $script:resultDetail.Result | Should -Match '\| example\.com \| Unknown .* \| Investigate \|' - $script:resultDetail.Result | Should -Match 'Compliance .* remains unconfirmed' - $script:resultDetail.Result | Should -Not -Match 'Well done|All custom domains meet' - } } } - - It 'investigates an indirect all policy when parked status is unknown' { - $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 redirect=_spf.example.net' } - $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 -all' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = 'Unknown' - SpfDeniesAll = $false - Reason = 'The SPF redirect target is inconclusive.' - } - - Test-MtCisSpfRecordsPublished | Should -BeTrue - $script:resultDetail.Investigate | Should -BeTrue - } - - It 'applies a parked override but still requires hard fail' { - $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } - $script:classifications['example.com'] = [pscustomobject]@{ - Classification = 'Unknown' - SpfDeniesAll = $false - Reason = 'Mail use is inconclusive.' - } - - Test-MtCisSpfRecordsPublished -ParkedDomains 'example.com' | Should -BeFalse - } } diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index a1923ec2bf..ab9dc31be7 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -12,20 +12,9 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( BeforeEach { Mock -ModuleName Maester Test-MtConnection { return $true } Mock -ModuleName Maester Add-MtTestResultDetail { } - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - $classification = if ($DomainName -eq 'parked.example') { 'Parked' } else { 'Sending' } - [PSCustomObject]@{ - DomainName = $DomainName - Classification = $classification - IsParked = $classification -eq 'Parked' - SpfRecord = $null - SpfDeniesAll = $false - DkimEvidence = $false - DkimSelectorRecordEvidence = $false - DkimSelectorLookupsComplete = $true - Reason = 'Mock domain classification' - } - } + Mock -ModuleName Maester Resolve-MtDnsRecord { + [PSCustomObject]@{ Name = $Name; Type = $Type; Status = 'NXDomain'; Answers = [object[]]@() } + } Mock -ModuleName Maester Get-MailAuthenticationRecord { throw 'DNS lookup should not be attempted without a DKIM signing configuration' } @@ -111,7 +100,8 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( $expectedResult = $ExpectedResultByCommand[$CommandName] - $result = & $CommandName + $parameters = if ($CommandName -eq 'Test-MtCisDkim' -and $DomainName -eq 'parked.example') { @{ ParkedDomains = 'parked.example' } } else { @{} } + $result = & $CommandName @parameters if ($null -eq $expectedResult) { $result | Should -BeNullOrEmpty } else { @@ -121,158 +111,95 @@ Describe 'DKIM checks with no signing configuration' -ForEach @( } } -Describe 'CIS DKIM domain classification outcomes' { +Describe 'CIS DKIM with ParkedDomains' { BeforeEach { + $script:acceptedDomains = @([PSCustomObject]@{ DomainName = 'parked.example'; InitialDomain = $false; IsCoexistenceDomain = $false }) + # Name -> status for the selector lookups; anything not listed is NXDomain. + $script:selectorStatus = @{} + $script:selectorRecords = @{} Mock -ModuleName Maester Add-MtTestResultDetail { $script:detail = [PSCustomObject]@{ Result = $Result; Investigate = [bool]$Investigate; SkippedBecause = $SkippedBecause } } Mock -ModuleName Maester Get-MtExo { - if ($Request -eq 'AcceptedDomain') { - return @([PSCustomObject]@{ DomainName = 'unknown.example'; InitialDomain = $false; IsCoexistenceDomain = $false }) - } + if ($Request -eq 'AcceptedDomain') { return $script:acceptedDomains } return @() } - Mock -ModuleName Maester Get-MailAuthenticationRecord { throw 'No DKIM lookup should be needed for this classification.' } - } - - It 'investigates domains whose sending use cannot be established' { - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - [PSCustomObject]@{ Classification = 'Unknown'; IsParked = $false; Reason = 'DNS evidence is incomplete.' } + Mock -ModuleName Maester Get-MailAuthenticationRecord { throw 'No Exchange DKIM lookup should be needed for a parked domain.' } + Mock -ModuleName Maester Resolve-MtDnsRecord { + $key = "$Type|$Name" + $status = if ($script:selectorStatus.ContainsKey($key)) { $script:selectorStatus[$key] } elseif ($script:selectorRecords.ContainsKey($key)) { 'Success' } else { 'NXDomain' } + $answers = if ($script:selectorRecords.ContainsKey($key)) { [object[]]@([PSCustomObject]@{ Value = $script:selectorRecords[$key] }) } else { [object[]]@() } + [PSCustomObject]@{ Name = $Name; Type = $Type; Status = $status; Answers = $answers } } - - Test-MtCisDkim | Should -BeTrue - $script:detail.Investigate | Should -BeTrue - $script:detail.Result | Should -Match 'Compliance .* remains unconfirmed' - $script:detail.Result | Should -Not -Match 'Well done|Sending domains have DKIM configured' } - It 'reports a compliant domain alongside without changing result precedence' -ForEach @( - @{ OtherOutcome = 'Investigate'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedUnconfirmed = $true } - @{ OtherOutcome = 'NotSupported'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $true } - @{ OtherOutcome = 'NotApplicable'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } - @{ OtherOutcome = 'Passed'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } - @{ OtherOutcome = 'Failed'; ExpectedResult = $false; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } - ) { - Mock -ModuleName Maester Get-MtExo { - if ($Request -eq 'AcceptedDomain') { - return @( - [PSCustomObject]@{ DomainName = 'compliant.example'; InitialDomain = $false; IsCoexistenceDomain = $false } - [PSCustomObject]@{ DomainName = 'other.example'; InitialDomain = $false; IsCoexistenceDomain = $false } - ) - } - return @() - } - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - $classification = 'Parked' - $unavailable = $false - $selectorEvidence = $false - if ($DomainName -eq 'other.example') { - switch ($OtherOutcome) { - 'Investigate' { $classification = 'Unknown' } - 'NotSupported' { $classification = 'Unknown'; $unavailable = $true } - 'NotApplicable' { $classification = 'NotSending' } - 'Failed' { $selectorEvidence = $true } - } - } - [PSCustomObject]@{ - Classification = $classification - DnsResolverUnavailable = $unavailable - DkimSelectorRecordEvidence = $selectorEvidence - DkimSelectorLookupsComplete = $true - Reason = 'Mixed-domain test evidence.' - } - } - - Test-MtCisDkim | Should -Be $ExpectedResult - $script:detail.Investigate | Should -Be $ExpectedInvestigation - $script:detail.SkippedBecause | Should -BeNullOrEmpty - $script:detail.Result | Should -Match '\| compliant\.example .*Pass' - $script:detail.Result | Should -Match '\| other\.example \|' - if ($ExpectedUnconfirmed) { - $script:detail.Result | Should -Match 'Compliance .* remains unconfirmed' - $script:detail.Result | Should -Match 'Review the domains marked Investigate or skipped' - $script:detail.Result | Should -Not -Match 'Well done|Sending domains have DKIM configured' - } - elseif ($ExpectedResult) { - $script:detail.Result | Should -Match 'Well done\. Sending domains have DKIM configured' - } - else { - $script:detail.Result | Should -Match "Your tenant's domains do not have DKIM fully deployed" - } + It 'checks a domain against the sending-domain audit unless it is listed' { + Test-MtCisDkim | Should -BeFalse + $script:detail.Result | Should -Match '\| parked\.example \| Sending \|' + Should -Invoke Resolve-MtDnsRecord -ModuleName Maester -Exactly 0 } - It 'skips with NotSupported when the DNS resolver is unavailable' { - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - [PSCustomObject]@{ - Classification = 'Unknown' - DnsResolverUnavailable = $true - Reason = 'DNS resolver is unavailable.' - } - } - - Test-MtCisDkim | Should -BeNullOrEmpty - $script:detail.SkippedBecause | Should -Be 'NotSupported' + It 'passes a listed domain with no selector records' { + Test-MtCisDkim -ParkedDomains 'PARKED.example.' | Should -BeTrue + $script:detail.Result | Should -Match '\| parked\.example \| Parked \|' + $script:detail.Result | Should -Match 'Well done' + Should -Invoke Resolve-MtDnsRecord -ModuleName Maester -Exactly 4 } - It 'fails a parked override when DKIM evidence remains' { - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - $classification = if ($ParkedDomains -contains $DomainName) { 'Parked' } else { 'Sending' } - [PSCustomObject]@{ Classification = $classification; DkimEvidence = $true; DkimSelectorRecordEvidence = $true; DkimSelectorLookupsComplete = $true; Reason = 'Explicit parked override.' } - } + It 'fails a listed domain that publishes a selector record' { + $script:selectorRecords['CNAME|selector1._domainkey.parked.example'] = 'selector1-parked-example._domainkey.contoso.onmicrosoft.com' - Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeFalse + Test-MtCisDkim -ParkedDomains 'parked.example' | Should -BeFalse + $script:detail.Result | Should -Match 'a selector1 or selector2 DKIM record is published' } - It 'passes a parked override with a signing configuration but no published selector records' { - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - [PSCustomObject]@{ - Classification = 'Parked' - DkimEvidence = $true - DkimSelectorRecordEvidence = $false - DkimSelectorLookupsComplete = $true - Reason = 'An Exchange signing configuration exists, but no selector records are published.' - } - } + It 'fails a listed domain with a selector record even when another lookup failed' { + $script:selectorRecords['TXT|selector2._domainkey.parked.example'] = 'v=DKIM1; p=abc' + $script:selectorStatus['CNAME|selector1._domainkey.parked.example'] = 'Error' - Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeTrue + Test-MtCisDkim -ParkedDomains 'parked.example' | Should -BeFalse + $script:detail.Investigate | Should -BeFalse } - It 'investigates a parked override when selector DNS lookups are incomplete' { - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - [PSCustomObject]@{ - Classification = 'Parked' - DkimSelectorRecordEvidence = $false - DkimSelectorLookupsComplete = $false - Reason = 'A selector DNS lookup failed.' - } - } + It 'investigates a listed domain when a selector lookup fails' { + $script:selectorStatus['CNAME|selector1._domainkey.parked.example'] = 'Error' - Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeTrue + Test-MtCisDkim -ParkedDomains 'parked.example' | Should -BeTrue $script:detail.Investigate | Should -BeTrue + $script:detail.Result | Should -Match 'Compliance .* remains unconfirmed' } - It 'fails a parked override when a selector record exists and another lookup is incomplete' { - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - [PSCustomObject]@{ - Classification = 'Parked' - DkimSelectorRecordEvidence = $true - DkimSelectorLookupsComplete = $false - Reason = 'A selector record exists and another lookup failed.' - } + It 'skips with NotSupported when DNS lookups are not available' { + foreach ($selector in 'selector1', 'selector2') { + foreach ($type in 'CNAME', 'TXT') { $script:selectorStatus["$type|$selector._domainkey.parked.example"] = 'NotAvailable' } } - Test-MtCisDkim -ParkedDomains 'unknown.example' | Should -BeFalse - $script:detail.Investigate | Should -BeFalse - $script:detail.Result | Should -Match 'published standard DKIM selector record that must be removed' + Test-MtCisDkim -ParkedDomains 'parked.example' | Should -BeNullOrEmpty + $script:detail.SkippedBecause | Should -Be 'NotSupported' } - It 'marks a non-sending receive domain out of scope for DKIM' { - Mock -ModuleName Maester Get-MtCisParkedDomainClassification { - [PSCustomObject]@{ Classification = 'NotSending'; IsParked = $false; Reason = 'The domain has receive-only DNS records.' } + It 'reports a compliant parked domain alongside one that ' -ForEach @( + @{ OtherOutcome = 'needs investigation'; Status = 'Error'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedUnconfirmed = $true } + @{ OtherOutcome = 'cannot be checked'; Status = 'NotAvailable'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $true } + @{ OtherOutcome = 'passes'; Status = $null; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } + ) { + $script:acceptedDomains += [PSCustomObject]@{ DomainName = 'other.example'; InitialDomain = $false; IsCoexistenceDomain = $false } + if ($Status) { + foreach ($selector in 'selector1', 'selector2') { + foreach ($type in 'CNAME', 'TXT') { $script:selectorStatus["$type|$selector._domainkey.other.example"] = $Status } + } } - Test-MtCisDkim | Should -BeNullOrEmpty - $script:detail.SkippedBecause | Should -Be 'NotApplicable' + Test-MtCisDkim -ParkedDomains 'parked.example', 'other.example' | Should -Be $ExpectedResult + $script:detail.Investigate | Should -Be $ExpectedInvestigation + $script:detail.SkippedBecause | Should -BeNullOrEmpty + $script:detail.Result | Should -Match '\| parked\.example .*Pass' + if ($ExpectedUnconfirmed) { + $script:detail.Result | Should -Match 'Compliance .* remains unconfirmed' + $script:detail.Result | Should -Not -Match 'Well done' + } else { + $script:detail.Result | Should -Match 'Well done' + } } } diff --git a/tests/cis/Test.CIS.M365.2.1.10.md b/tests/cis/Test.CIS.M365.2.1.10.md index 35518547a7..a3e41ab766 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.md +++ b/tests/cis/Test.CIS.M365.2.1.10.md @@ -1,21 +1,17 @@ -Every accepted domain, including the initial onmicrosoft.com domain, must meet the applicable DMARC audit. Sending domains require a quarantine or reject policy that covers all mail and names addresses for aggregate and forensic reports. Parked or otherwise non-sending domains require a valid DMARC record with `p=reject`. +Every accepted domain, including the initial onmicrosoft.com domain, must meet the applicable DMARC audit. Sending domains require a quarantine or reject policy that covers all mail and names addresses for aggregate and forensic reports. Parked domains, which don't send email, require a valid DMARC record with `p=reject`. DMARC tells receiving servers what to do with mail that fails SPF and DKIM alignment, and sends you reports about who is sending mail in your name. With a policy of none, spoofed mail is still delivered. Quarantine or reject stops it, and the reports show abuse and legitimate senders that you forgot. The test uses the record at the domain, or at its organisational domain (for example contoso.com for mail.contoso.com) when the domain has no valid record, including a malformed record, applying the subdomain policy where one exists. For sending domains, the policy must apply to 100 percent of mail (no pct tag, or pct=100), and both rua and ruf addresses must be mailto addresses. -Maester identifies a likely non-sending domain when it finds one SPF v1 record with only a non-authorizing `-all` or `~all` mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. An SPF record ending in `?all` is inconclusive and does not establish that the domain is unused. It classifies the domain as parked only when the non-sending signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. +Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so list your parked domains, the ones that never send email, in this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. Every other domain gets the sending-domain audit. -Parked or non-sending domains use the CIS parked-domain requirement: a valid DMARC record with `p=reject`; rua, ruf, and pct are not required for this branch. Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only SPF policies do not receive the parked exception. When only one of the sending and non-sending audit procedures passes, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. - -When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. Investigation results state that compliance remains unconfirmed and direct you to review these domains instead of displaying a full-compliance banner. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. - -When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement for a valid DMARC record with `p=reject`. +Parked domains use the CIS parked-domain requirement: a valid DMARC record with `p=reject`; rua, ruf and pct are not required. When the DNS lookup is not available for a domain, it is listed as Not checked. #### Remediation action 1. Open the DNS zone of each custom domain at your DNS host. For the initial `*.onmicrosoft.com` domain, use the Microsoft 365 admin center instead: go to **Settings** > **Domains**, select the `*.onmicrosoft.com` domain, open the **DNS records** tab and select **Add record**. -2. Create or edit the TXT record `_dmarc.` (in the admin center, the host name is `_dmarc`). For a sending domain, use a value such as `v=DMARC1; p=reject; pct=100; rua=mailto:dmarc-reports@; ruf=mailto:dmarc-forensic@`. For a parked or non-sending domain, `v=DMARC1; p=reject` meets the parked-domain requirement. +2. Create or edit the TXT record `_dmarc.` (in the admin center, the host name is `_dmarc`). For a sending domain, use a value such as `v=DMARC1; p=reject; pct=100; rua=mailto:dmarc-reports@; ruf=mailto:dmarc-forensic@`. For a parked domain, `v=DMARC1; p=reject` meets the parked-domain requirement; add the domain to `ParkedDomains`. 3. Start with `p=none` or `p=quarantine` if you are not sure that all your senders are aligned, review the reports and then move to `p=reject`. 4. Check the record with `Resolve-DnsName -Name _dmarc. -Type TXT`. diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index b1433b3626..141a804e1d 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -4,7 +4,7 @@ Checks the applicable CIS DMARC requirement for each accepted domain. .DESCRIPTION - Looks up the DMARC record that applies to each accepted domain, falling back to the organisational domain when the domain has no valid record, including a malformed record. Sending domains require quarantine or reject, 100 percent coverage, and mailto aggregate (rua) and forensic (ruf) report addresses. Parked or otherwise non-sending domains require a valid record with p=reject. Ambiguous domain-use evidence is reported for investigation when the two procedures produce different results. + Looks up the DMARC record that applies to each accepted domain, falling back to the organisational domain when the domain has no valid record, including a malformed record. Sending domains require quarantine or reject, 100 percent coverage, and mailto aggregate (rua) and forensic (ruf) report addresses. Domains listed in the ParkedDomains parameter require a valid record with p=reject. Every other domain gets the sending-domain audit. CIS Microsoft 365 Foundations Benchmark v7.0.0 (2.1.10, L1) .EXAMPLE @@ -33,17 +33,17 @@ [CmdletBinding()] [OutputType([bool])] param( - # Domains explicitly confirmed as parked; the parked DMARC audit still applies. + # Domains that are not used to send email. They need a valid DMARC record with p=reject. [string[]]$ParkedDomains = @() ) Write-Verbose 'Getting accepted domains...' $domains = @(Get-MtExo -Request AcceptedDomain | Where-Object { $_.IsCoExistenceDomain -eq $false }) - $dkimSigningConfigs = @(Get-MtExo -Request DkimSigningConfig) $report = foreach ($domain in $domains) { $name = $domain.DomainName - $classification = Get-MtCisParkedDomainClassification -DomainName $name -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains + $isParked = Test-MtCisParkedDomain -DomainName $name -ParkedDomains $ParkedDomains + $classification = if ($isParked) { 'Parked' } else { 'Sending' } $dmarc = $null $source = $null $unavailable = $false @@ -64,68 +64,41 @@ } } if ($unavailable) { - [pscustomobject]@{ Domain = $name; Classification = $classification.Classification; Policy = 'Not checked'; Source = 'None'; Failed = 'DNS lookup not available'; Pass = $null; Investigate = $false } + [pscustomobject]@{ Domain = $name; Classification = $classification; Policy = 'Not checked'; Source = 'None'; Failed = 'DNS lookup not available'; Pass = $null } continue } $policy = $null if ($dmarc) { $policy = if ($source -ne $name -and $dmarc.policySubdomain) { $dmarc.policySubdomain } else { $dmarc.policy } } - $sendingChecks = [ordered]@{ - 'Record is valid' = $null -ne $dmarc -and $dmarc.valid - 'Policy is quarantine or reject' = $policy -in @('quarantine', 'reject') - 'Applies to 100 percent' = $null -eq $dmarc -or $dmarc.percentage -eq 100 -or $null -eq $dmarc.percentage - 'Aggregate reports (rua)' = @($dmarc.reportAggregate | Where-Object { $_.mailAddress }).Count -gt 0 - 'Forensic reports (ruf)' = @($dmarc.reportForensic | Where-Object { $_.mailAddress }).Count -gt 0 - } - $nonSendingChecks = [ordered]@{ - 'Record is valid' = $null -ne $dmarc -and $dmarc.valid - 'Parked-domain policy is reject' = $policy -eq 'reject' - } - $sendingFailures = @($sendingChecks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) - $nonSendingFailures = @($nonSendingChecks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) - $failedChecks = @() - $investigate = $false - if ($classification.Classification -in @('Parked', 'NotSending')) { - $failedChecks = $nonSendingFailures - $pass = $failedChecks.Count -eq 0 - } elseif ($classification.Classification -eq 'Unknown') { - if ($sendingFailures.Count -eq 0 -and $nonSendingFailures.Count -eq 0) { - $pass = $true - } elseif ($sendingFailures.Count -eq 0 -or $nonSendingFailures.Count -eq 0) { - $pass = $true - $investigate = $true - $failedChecks = if ($sendingFailures.Count -eq 0) { - @("If parked or non-sending: $($nonSendingFailures -join ', ')") - } else { - @("If sending: $($sendingFailures -join ', ')") - } - } else { - $pass = $false - $failedChecks = @( - @($sendingFailures | ForEach-Object { "If sending: $_" }) + - @($nonSendingFailures | ForEach-Object { "If parked or non-sending: $_" }) - ) + $checks = if ($isParked) { + [ordered]@{ + 'Record is valid' = $null -ne $dmarc -and $dmarc.valid + 'Parked-domain policy is reject' = $policy -eq 'reject' } } else { - $failedChecks = $sendingFailures - $pass = $failedChecks.Count -eq 0 + [ordered]@{ + 'Record is valid' = $null -ne $dmarc -and $dmarc.valid + 'Policy is quarantine or reject' = $policy -in @('quarantine', 'reject') + 'Applies to 100 percent' = $null -eq $dmarc -or $dmarc.percentage -eq 100 -or $null -eq $dmarc.percentage + 'Aggregate reports (rua)' = @($dmarc.reportAggregate | Where-Object { $_.mailAddress }).Count -gt 0 + 'Forensic reports (ruf)' = @($dmarc.reportForensic | Where-Object { $_.mailAddress }).Count -gt 0 + } } + $failedChecks = @($checks.GetEnumerator() | Where-Object { -not $_.Value } | ForEach-Object { $_.Key }) [pscustomobject]@{ Domain = $name - Classification = $classification.Classification + Classification = $classification Policy = if ($policy) { $policy } elseif ($invalidCandidate) { 'Invalid DMARC record' } else { 'No valid record' } Source = if ($source) { $source } elseif ($invalidCandidate) { $invalidCandidate } else { 'None' } Failed = $failedChecks -join ', ' - Pass = $pass - Investigate = $investigate + Pass = $failedChecks.Count -eq 0 } } $checked = @($report | Where-Object { $null -ne $_.Pass }) - $unchecked = @($report | Where-Object { $null -eq $_.Pass -and -not $_.Investigate }) + $unchecked = @($report | Where-Object { $null -eq $_.Pass }) $failed = @($checked | Where-Object { -not $_.Pass }) - $investigated = @($report | Where-Object { $_.Investigate }) - if ($failed.Count -eq 0 -and $unchecked.Count -gt 0 -and $investigated.Count -eq 0) { + if ($failed.Count -eq 0 -and $unchecked.Count -gt 0) { Add-MtTestResultDetail -SkippedBecause NotSupported return $null } @@ -137,20 +110,17 @@ $resultMd = "| Domain | Classification | Applied policy | Record found at | Failed checks | Result |`n" $resultMd += "| --- | --- | --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultText = if ($row.Investigate) { 'Investigate' } elseif ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } + $resultText = if ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } $resultMd += "| $($row.Domain) | $($row.Classification) | $($row.Policy) | $($row.Source) | $(if ($row.Failed) { $row.Failed } else { 'None' }) | $resultText |`n" } - if ($testResult -and ($investigated.Count -gt 0 -or $unchecked.Count -gt 0)) { - $testResultMarkdown = "Compliance with the applicable CIS DMARC requirement remains unconfirmed. Review the domains marked Investigate or Not checked.`n`n%TestResult%" - } - elseif ($testResult) { + if ($testResult) { $testResultMarkdown = "Well done. $passText`n`n%TestResult%" } else { $testResultMarkdown = "$failText`n`n%TestResult%" } $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd - Add-MtTestResultDetail -Result $testResultMarkdown -Investigate:($investigated.Count -gt 0 -and $failed.Count -eq 0) + Add-MtTestResultDetail -Result $testResultMarkdown return $testResult } diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index e0705c9aca..c2a8ad7221 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -1,23 +1,17 @@ -Sending domains must publish an SPF record that ends in a hard fail (-all) or soft fail (~all). Parked or otherwise non-sending domains must publish an SPF policy that denies all senders with -all. +Sending domains must publish an SPF record that ends in a hard fail (-all) or soft fail (~all). Parked domains, which don't send email, must publish `v=spf1 -all`, which denies all senders. SPF lists the servers that may send mail for a domain. Receiving servers use it to reject, or to mark as suspicious, mail that pretends to come from your domain. Without an SPF record, or with one that ends in a neutral or permissive qualifier, anyone can send mail that looks like it comes from you without raising a flag. -Maester identifies a likely non-sending domain when it finds one SPF v1 record with only a non-authorizing `-all` or `~all` mechanism, no Exchange DKIM signing configuration, and no selector1 or selector2 DKIM CNAME/TXT record. An SPF record ending in `?all` is inconclusive and does not establish that the domain is unused. It classifies the domain as parked only when the non-sending signals are also accompanied by no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This conservative DNS assessment does not use `AcceptedDomain.SendingFromDomainDisabled`. +Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so list your parked domains, the ones that never send email, in this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. Every other domain gets the sending-domain audit. -For a parked or non-sending domain, the SPF record must explicitly use `-all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. +For a parked domain the record must be `v=spf1 -all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. -An `exp=` modifier does not authorize senders and is ignored when classifying domain use. The audit still requires the compliant all mechanism to be the final term: `v=spf1 -all exp=why.example.com` does not meet that termination requirement. - -Missing SPF, conflicting signals, DNS errors, and unresolved redirect-only policies do not receive the parked exception. When the record passes the sending-domain rule but could fail the parked-domain rule, the result requires investigation. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. - -When some lookups are unavailable and another domain requires investigation, the result remains Investigate and lists the unavailable domains as Not checked. Investigation results state that compliance remains unconfirmed and direct you to review these domains instead of displaying a full-compliance banner. Known failures still take precedence; unavailable lookups without failures or investigation produce NotSupported. - -When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; it does not waive the requirement to publish `v=spf1 -all`. +An `exp=` modifier does not authorize senders. The audit still requires the compliant all mechanism to be the final term: `v=spf1 -all exp=why.example.com` does not meet that termination requirement. #### Remediation action 1. Open the DNS zone of each custom domain at your DNS host. -2. Create or edit the TXT record at the domain root. For a sending domain, list its sending services and end with `-all` or `~all`; for a parked or non-sending domain, publish `v=spf1 -all`. For Exchange Online only, use `v=spf1 include:spf.protection.outlook.com -all`. +2. Create or edit the TXT record at the domain root. For a sending domain, list its sending services and end with `-all` or `~all`; for a parked domain, publish `v=spf1 -all` and add the domain to `ParkedDomains`. For Exchange Online only, use `v=spf1 include:spf.protection.outlook.com -all`. 3. Wait for the change to propagate and check the record with `Resolve-DnsName -Name -Type TXT`. #### Related links diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index b5eb54ac11..fc840aadd2 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -4,7 +4,7 @@ Checks the applicable CIS SPF requirement for each custom accepted domain. .DESCRIPTION - Sending domains must publish an SPF record that ends with -all or ~all, directly or through a redirect. Parked or otherwise non-sending domains must publish an SPF policy that denies all senders with -all. Domains in the onmicrosoft.com namespace are excluded because Microsoft manages their SPF. Ambiguous domain-use evidence is reported for investigation rather than receiving the parked-domain exception. + Sending domains must publish an SPF record that ends with -all or ~all, directly or through a redirect. Domains listed in the ParkedDomains parameter must publish v=spf1 -all, which denies all senders. Every other domain gets the sending-domain audit. Domains in the onmicrosoft.com namespace are excluded because Microsoft manages their SPF. CIS Microsoft 365 Foundations Benchmark v7.0.0 (2.1.8, L1) .EXAMPLE @@ -33,21 +33,21 @@ [CmdletBinding()] [OutputType([bool])] param( - # Domains explicitly confirmed as parked; the parked SPF audit still applies. + # Domains that are not used to send email. They must publish v=spf1 -all. [string[]]$ParkedDomains = @() ) Write-Verbose 'Getting accepted domains...' $domains = @(Get-MtExo -Request AcceptedDomain | Where-Object { $_.InitialDomain -eq $false -and $_.IsCoExistenceDomain -eq $false }) - $dkimSigningConfigs = @(Get-MtExo -Request DkimSigningConfig) $report = foreach ($domain in $domains) { $name = $domain.DomainName - $classification = Get-MtCisParkedDomainClassification -DomainName $name -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains + $isParked = Test-MtCisParkedDomain -DomainName $name -ParkedDomains $ParkedDomains + $classification = if ($isParked) { 'Parked' } else { 'Sending' } $detail = '' $spf = ConvertFrom-MailAuthenticationRecordSpf -DomainName $name if ($spf -is [string] -and ($spf -like '*not available' -or $spf -eq 'DNS lookup unavailable')) { - [pscustomobject]@{ Domain = $name; Record = $null; Classification = $classification.Classification; Pass = $null; Investigate = $false; Detail = 'DNS lookup not available' } + [pscustomobject]@{ Domain = $name; Record = $null; Classification = $classification; Pass = $null; Detail = 'DNS lookup not available' } continue } $record = if ($spf -and $spf.PSObject.Properties['record']) { $spf.record } else { $null } @@ -90,13 +90,11 @@ } if ($redirectUnavailable) { - [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification.Classification; Pass = $null; Investigate = $false; Detail = "DNS lookup not available for $($redirectTargets[-1])" } + [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification; Pass = $null; Detail = "DNS lookup not available for $($redirectTargets[-1])" } continue } $effectiveAll = [regex]::Match([string]$effective, '(?i)(^|\s)(?[+?~-]?)all\s*$') - $sendingDomainPass = $effectiveAll.Success -and $effectiveAll.Groups['q'].Value -in '-', '~' - $pass = $sendingDomainPass - $investigate = $false + $pass = $effectiveAll.Success -and $effectiveAll.Groups['q'].Value -in '-', '~' if (-not $record) { $detail = 'No SPF record found' } elseif ($redirectError) { @@ -110,32 +108,25 @@ $detail = 'The record does not end with -all or ~all' } - if ($classification.Classification -in @('Parked', 'NotSending')) { - $pass = $classification.SpfDeniesAll + if ($isParked) { + # CIS asks parked domains for v=spf1 -all: no sender mechanisms, no redirect, hard fail last. + # An exp= modifier authorizes no one, so it is allowed before -all. + $pass = [string]$record -match '(?i)^\s*v=spf1(\s+exp=\S+)*\s+-all\s*$' $detail = if ($pass) { - 'The parked/non-sending audit requires an SPF record that explicitly denies all senders; this record uses -all.' + 'Listed as parked; the record denies all senders with -all.' } else { - 'The parked/non-sending audit requires an SPF record that explicitly denies all senders with -all.' + 'Listed as parked; CIS requires v=spf1 -all, which denies all senders.' } - } elseif ($classification.Classification -eq 'Unknown' -and $sendingDomainPass -and -not $classification.SpfDeniesAll) { - $pass = $null - $investigate = $true - $detail = 'The sending-domain SPF audit passes, but the available evidence cannot rule out the parked-domain requirement for -all.' - } elseif ($classification.Classification -eq 'Unknown' -and $sendingDomainPass) { - $pass = $true - $detail = 'The record meets both the sending-domain and parked-domain SPF requirements.' } - $detail = "$($classification.Reason) $detail" - [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification.Classification; Pass = $pass; Investigate = $investigate; Detail = $detail } + [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification; Pass = $pass; Detail = $detail } } - $unchecked = @($report | Where-Object { $null -eq $_.Pass -and -not $_.Investigate }) + $unchecked = @($report | Where-Object { $null -eq $_.Pass }) $failed = @($report | Where-Object { $_.Pass -eq $false }) - $investigated = @($report | Where-Object { $_.Investigate }) if ($failed.Count -gt 0) { $testResult = $false - } elseif ($unchecked.Count -gt 0 -and $investigated.Count -eq 0) { + } elseif ($unchecked.Count -gt 0) { Add-MtTestResultDetail -SkippedBecause NotSupported return $null } else { @@ -148,14 +139,11 @@ $resultMd = "| Domain | Classification | SPF record | Detail | Result |`n" $resultMd += "| --- | --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultText = if ($null -eq $row.Pass -and $row.Investigate) { 'Investigate' } elseif ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } + $resultText = if ($null -eq $row.Pass) { 'Not checked' } elseif ($row.Pass) { '✅ Pass' } else { '❌ Fail' } $resultMd += "| $($row.Domain) | $($row.Classification) | $($row.Record) | $($row.Detail) | $resultText |`n" } - if ($testResult -and ($investigated.Count -gt 0 -or $unchecked.Count -gt 0)) { - $testResultMarkdown = "Compliance with the applicable CIS SPF requirement remains unconfirmed. Review the domains marked Investigate or Not checked.`n`n%TestResult%" - } - elseif ($testResult) { + if ($testResult) { $testResultMarkdown = "Well done. $passText`n`n%TestResult%" } else { @@ -163,6 +151,6 @@ } $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd - Add-MtTestResultDetail -Result $testResultMarkdown -Investigate:($investigated.Count -gt 0 -and $failed.Count -eq 0) + Add-MtTestResultDetail -Result $testResultMarkdown return $testResult } diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index b8e465d1f3..5f2f02f787 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -12,15 +12,13 @@ There should be no impact of setting up DKIM however, organizations should ensur >Note: Initial (MOERA, e.g. `contoso.onmicrosoft.com`) and coexistence (`*.mail.onmicrosoft.com`) domains are excluded from this check, as Microsoft automatically signs outbound mail for those domains. -For domains classified as sending, the check requires Exchange DKIM to be enabled and its status to be **Valid**. A likely sending domain has an SPF sender-authorizing mechanism, an Exchange DKIM signing configuration, or a selector1/selector2 DKIM CNAME/TXT record. +The check requires Exchange DKIM to be enabled and its status to be **Valid** for every domain except the parked domains you list. -Maester classifies a domain as not sending when its single SPF v1 record has only a non-authorizing `-all` or `~all` mechanism and no Exchange DKIM signing configuration or selector1/selector2 records are found. An SPF record ending in `?all` is inconclusive and does not establish that the domain is unused. A domain is classified as parked only when it also has no usable MX route (or a null MX) and no A, AAAA, or CNAME record at the domain apex. This classification does not use `AcceptedDomain.SendingFromDomainDisabled`. +Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so list your parked domains, the ones that never send email, in this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. Every other domain gets the sending-domain audit. -For a confirmed parked domain, CIS requires that DKIM records are not published; the check passes only when no standard selector1/selector2 CNAME or TXT records are found. An Exchange DKIM signing configuration without a published selector record does not fail this parked-domain criterion. A domain with no sending signals but with receiving or other apex DNS records is outside the sending-domain audit scope. Domains with missing or conflicting evidence are marked for investigation rather than automatically treated as parked. Any known standard selector record fails the parked check even if another selector lookup failed. Incomplete selector lookups report investigation only when no selector record is known; passing requires all four selector1/selector2 CNAME/TXT lookups to return Success or NXDOMAIN with no records found. Selector discovery is limited to the standard Exchange Online selectors, so nonstandard DKIM selector names cannot be ruled out automatically. +For a parked domain, CIS asks that DKIM records are not published. The check passes when none of the selector1/selector2 CNAME or TXT records exist, and fails when one does. If some of those lookups fail, the domain is marked for investigation; if DNS lookups are not available at all, it is skipped. Only the standard Exchange Online selectors are checked. -When any domain requires investigation or has unavailable DNS lookups, a result table states that compliance remains unconfirmed instead of displaying a full-compliance banner. Known failures still take precedence, and domains explicitly excluded from the audit do not prevent confirmed in-scope domains from passing. - -When DNS evidence is inconclusive but a domain is known to be parked, add its name to this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. This selects the parked audit branch; any published standard selector record still fails the check. +When a parked domain needs investigation or was skipped because DNS lookups are unavailable, the result says compliance is unconfirmed instead of showing a full-compliance banner. Known failures still take precedence. #### Remediation action diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index 50f7937f89..dc38472fbd 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -4,13 +4,13 @@ Checks DKIM for domains that send email and verifies parked domains have no DKIM records. .DESCRIPTION - Sending domains require DKIM to be enabled with a valid Exchange status. Parked domains must not publish DKIM records. Initial (MOERA) and coexistence domains are excluded, as Microsoft automatically signs outbound mail for those domains. Ambiguous domain-use evidence is reported for investigation. + Domains require DKIM to be enabled with a valid Exchange status. Domains listed in the ParkedDomains parameter must not publish DKIM records instead. Initial (MOERA) and coexistence domains are excluded, as Microsoft automatically signs outbound mail for those domains. CIS Microsoft 365 Foundations Benchmark v7.0.0 (2.1.9, L1) .EXAMPLE Test-MtCisDkim - Returns true if every sending domain has DKIM enabled with Exchange status Valid and every parked domain has no known Exchange selector records. Initial and coexistence domains are excluded. Domains classified as not sending are out of scope; ambiguous domains require investigation. + Returns true if every domain has DKIM enabled with Exchange status Valid, and every domain listed in ParkedDomains has no selector1 or selector2 DKIM record. Initial and coexistence domains are excluded. .LINK https://maester.dev/docs/commands/Test-MtCisDkim @@ -38,7 +38,7 @@ # Selector-name for the DKIM record to test.. [string]$Selector = 'selector1', - # Domains explicitly confirmed as parked; any published selector record still fails the audit. + # Domains that are not used to send email. They must not publish DKIM records. [string[]]$ParkedDomains = @() ) @@ -60,52 +60,32 @@ continue } - $classification = Get-MtCisParkedDomainClassification -DomainName $domain.DomainName -DkimSigningConfigs $dkimSigningConfigs -ParkedDomains $ParkedDomains - if ($classification.Classification -eq 'Parked') { - $hasDkimSelectorRecord = $classification.DkimSelectorRecordEvidence - $selectorLookupsComplete = $classification.DkimSelectorLookupsComplete - $dkimRecords += [PSCustomObject]@{ - domain = $domain.DomainName - classification = $classification.Classification - pass = if ($hasDkimSelectorRecord) { 'Failed' } elseif (-not $selectorLookupsComplete) { 'Investigate' } else { 'Passed' } - reason = if ($hasDkimSelectorRecord) { "Parked domain has a published standard DKIM selector record that must be removed. $($classification.Reason)" } elseif (-not $selectorLookupsComplete) { "Standard DKIM selector DNS lookups did not complete, so record absence could not be confirmed. $($classification.Reason)" } else { "Parked domain has no published standard DKIM selector records. $($classification.Reason)" } - exchangeStatus = if ($selectorLookupsComplete) { 'Not applicable' } else { 'Not determined' } - dkimRecord = $null - } - continue - } - - if ($classification.Classification -eq 'NotSending') { - $dkimRecords += [PSCustomObject]@{ - domain = $domain.DomainName - classification = $classification.Classification - pass = 'Skipped' - reason = "The CIS DKIM audit applies to domains configured to send email. $($classification.Reason)" - exchangeStatus = 'Not applicable' - dkimRecord = $null - } - continue - } - - if ($classification.Classification -eq 'Unknown') { - if ($classification.DnsResolverUnavailable) { - $dkimRecords += [PSCustomObject]@{ - domain = $domain.DomainName - classification = $classification.Classification - pass = 'NotSupported' - reason = "DNS resolver is unavailable, so sending use and selector records cannot be evaluated. $($classification.Reason)" - exchangeStatus = 'Not determined' - dkimRecord = $null + if (Test-MtCisParkedDomain -DomainName $domain.DomainName -ParkedDomains $ParkedDomains) { + # CIS: don't publish DKIM records for a parked domain. Exchange Online uses selector1 and selector2. + $selectorLookups = foreach ($selectorName in 'selector1', 'selector2') { + foreach ($recordType in 'CNAME', 'TXT') { + Resolve-MtDnsRecord -Name "$selectorName._domainkey.$($domain.DomainName)" -Type $recordType } - continue } - + $hasSelectorRecord = @($selectorLookups | Where-Object { @($_.Answers).Count -gt 0 }).Count -gt 0 + $incompleteLookups = @($selectorLookups | Where-Object { $_.Status -notin @('Success', 'NXDomain') }) + $resolverUnavailable = @($selectorLookups | Where-Object { $_.Status -ne 'NotAvailable' }).Count -eq 0 + + $pass, $reason = if ($hasSelectorRecord) { + 'Failed', 'Listed as parked, but a selector1 or selector2 DKIM record is published. Remove it.' + } elseif ($resolverUnavailable) { + 'NotSupported', 'Listed as parked, but DNS lookups are not available here, so the DKIM records could not be checked.' + } elseif ($incompleteLookups.Count -gt 0) { + 'Investigate', 'Listed as parked, but some DKIM selector lookups failed, so it could not be confirmed that no record is published.' + } else { + 'Passed', 'Listed as parked, and no selector1 or selector2 DKIM record is published.' + } $dkimRecords += [PSCustomObject]@{ domain = $domain.DomainName - classification = $classification.Classification - pass = 'Investigate' - reason = "Sending use could not be established; the domain was not classified as parked. $($classification.Reason)" - exchangeStatus = 'Not determined' + classification = 'Parked' + pass = $pass + reason = $reason + exchangeStatus = 'Not applicable' dkimRecord = $null } continue @@ -118,9 +98,9 @@ if (-not $dkimSigningConfig) { $dkimRecord = [PSCustomObject]@{ domain = $domain.DomainName - classification = $classification.Classification + classification = 'Sending' pass = 'Failed' - reason = 'No DkimSigningConfig found for a domain classified as sending' + reason = 'No DkimSigningConfig found. Add the domain to ParkedDomains if it does not send email.' exchangeStatus = 'Not configured' dkimRecord = $null } @@ -153,7 +133,7 @@ $dkimRecord | Add-Member -MemberType NoteProperty -Name 'pass' -Value 'Failed' $dkimRecord | Add-Member -MemberType NoteProperty -Name 'reason' -Value '' $dkimRecord | Add-Member -MemberType NoteProperty -Name 'exchangeStatus' -Value $dkimSigningConfig.Status - $dkimRecord | Add-Member -MemberType NoteProperty -Name 'classification' -Value $classification.Classification + $dkimRecord | Add-Member -MemberType NoteProperty -Name 'classification' -Value 'Sending' if (-not $dkimSigningConfig.enabled) { $dkimRecord.pass = 'Failed' From c3bc71078876d245e55fb054c8d976fcd25e9da8 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 08:16:41 +1300 Subject: [PATCH 13/20] fix(cis): reject earlier SPF all mechanism --- .../tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 | 6 ++++++ tests/cis/Test.CIS.M365.2.1.8.ps1 | 4 +++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index bd1d826af6..4ccb25a480 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -75,6 +75,12 @@ Test-MtCisSpfRecordsPublished | Should -BeFalse } + It 'rejects a sending-domain record with an earlier all mechanism' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 all include:vendor.example -all' } + + Test-MtCisSpfRecordsPublished | Should -BeFalse + } + It 'follows a redirect for a sending domain' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 redirect=_spf.example.net' } $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 include:spf.protection.outlook.com -all' } diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index fc840aadd2..95f6b2a47c 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -93,8 +93,10 @@ [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification; Pass = $null; Detail = "DNS lookup not available for $($redirectTargets[-1])" } continue } + $effectiveTerms = [string]$effective -split '\s+' + $allMechanisms = @($effectiveTerms | Where-Object { $_ -match '(?i)^[+?~-]?all$' }) $effectiveAll = [regex]::Match([string]$effective, '(?i)(^|\s)(?[+?~-]?)all\s*$') - $pass = $effectiveAll.Success -and $effectiveAll.Groups['q'].Value -in '-', '~' + $pass = $effectiveAll.Success -and $effectiveAll.Groups['q'].Value -in '-', '~' -and $allMechanisms.Count -eq 1 if (-not $record) { $detail = 'No SPF record found' } elseif ($redirectError) { From 62d257614b398a794dd0735dac6ba08a60cf1258 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 08:18:05 +1300 Subject: [PATCH 14/20] docs(cis): explain SPF all evaluation order --- tests/cis/Test.CIS.M365.2.1.8.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index c2a8ad7221..a10a83dc6e 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -6,7 +6,7 @@ Maester does not guess which domains are parked. CIS leaves that to the person r For a parked domain the record must be `v=spf1 -all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. -An `exp=` modifier does not authorize senders. The audit still requires the compliant all mechanism to be the final term: `v=spf1 -all exp=why.example.com` does not meet that termination requirement. +An `exp=` modifier does not authorize senders. The audit still requires the compliant all mechanism to be the final term: `v=spf1 -all exp=why.example.com` does not meet that termination requirement. An earlier `all` mechanism ends SPF evaluation before a later qualifier, so a record such as `v=spf1 all include:vendor.example -all` does not meet the audit. #### Remediation action From 8ac3c92d6adc935c9ce1b8ccdf06ed443f478a53 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 08:25:42 +1300 Subject: [PATCH 15/20] fix(cis): fail parked redirects without target lookup --- .../Test-MtCisSpfRecordsPublished.Tests.ps1 | 8 +++++++ tests/cis/Test.CIS.M365.2.1.8.ps1 | 23 ++++++++++--------- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index 4ccb25a480..700828c261 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -54,6 +54,14 @@ Test-MtCisSpfRecordsPublished -ParkedDomains 'example.com' | Should -BeFalse } + It 'fails a parked redirect without resolving an unavailable target' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 redirect=_spf.example.net' } + $script:spfResults['_spf.example.net'] = 'DNS lookup unavailable' + + Test-MtCisSpfRecordsPublished -ParkedDomains 'example.com' | Should -BeFalse + Should -Invoke ConvertFrom-MailAuthenticationRecordSpf -ModuleName Maester -Times 1 -Exactly + } + It 'applies the sending-domain rule to a domain that is not listed' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 ~all' } diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 95f6b2a47c..1182ce11e4 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -51,6 +51,18 @@ continue } $record = if ($spf -and $spf.PSObject.Properties['record']) { $spf.record } else { $null } + if ($isParked) { + # CIS asks parked domains for v=spf1 -all: no sender mechanisms, no redirect, hard fail last. + # An exp= modifier authorizes no one, so it is allowed before -all. + $pass = [string]$record -match '(?i)^\s*v=spf1(\s+exp=\S+)*\s+-all\s*$' + $detail = if ($pass) { + 'Listed as parked; the record denies all senders with -all.' + } else { + 'Listed as parked; CIS requires v=spf1 -all, which denies all senders.' + } + [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification; Pass = $pass; Detail = $detail } + continue + } $effective = $record $redirectTargets = @() $redirectError = $null @@ -110,17 +122,6 @@ $detail = 'The record does not end with -all or ~all' } - if ($isParked) { - # CIS asks parked domains for v=spf1 -all: no sender mechanisms, no redirect, hard fail last. - # An exp= modifier authorizes no one, so it is allowed before -all. - $pass = [string]$record -match '(?i)^\s*v=spf1(\s+exp=\S+)*\s+-all\s*$' - $detail = if ($pass) { - 'Listed as parked; the record denies all senders with -all.' - } else { - 'Listed as parked; CIS requires v=spf1 -all, which denies all senders.' - } - } - [pscustomobject]@{ Domain = $name; Record = $record; Classification = $classification; Pass = $pass; Detail = $detail } } From 9725d1d74b154a97d5ad012bd5febc4e096a9171 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 08:25:46 +1300 Subject: [PATCH 16/20] fix(cis): investigate unavailable parked DKIM checks --- powershell/tests/functions/Test-MtDkim.Tests.ps1 | 2 +- tests/cis/Test.CIS.M365.2.1.9.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index ab9dc31be7..18eeb33906 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -180,7 +180,7 @@ Describe 'CIS DKIM with ParkedDomains' { It 'reports a compliant parked domain alongside one that ' -ForEach @( @{ OtherOutcome = 'needs investigation'; Status = 'Error'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedUnconfirmed = $true } - @{ OtherOutcome = 'cannot be checked'; Status = 'NotAvailable'; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $true } + @{ OtherOutcome = 'cannot be checked'; Status = 'NotAvailable'; ExpectedResult = $true; ExpectedInvestigation = $true; ExpectedUnconfirmed = $true } @{ OtherOutcome = 'passes'; Status = $null; ExpectedResult = $true; ExpectedInvestigation = $false; ExpectedUnconfirmed = $false } ) { $script:acceptedDomains += [PSCustomObject]@{ DomainName = 'other.example'; InitialDomain = $false; IsCoexistenceDomain = $false } diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index dc38472fbd..eefdd37036 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -206,6 +206,6 @@ $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $result - Add-MtTestResultDetail -Result $testResultMarkdown -Investigate:('Investigate' -in $dkimRecords.pass -and 'Failed' -notin $dkimRecords.pass) + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate:(('Investigate' -in $dkimRecords.pass -or 'NotSupported' -in $dkimRecords.pass) -and 'Failed' -notin $dkimRecords.pass) return $testResult } From 1a14e391ee9d5d7b7a15987850cfe6ea94c8b51b Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 08:40:08 +1300 Subject: [PATCH 17/20] Support shared parked domains setting --- powershell/assets/MaesterSettings.psd1 | 1 + .../Test-MtCisDmarcRecordsPublished.Tests.ps1 | 10 ++++++++++ .../functions/Test-MtCisSpfRecordsPublished.Tests.ps1 | 8 ++++++++ powershell/tests/functions/Test-MtDkim.Tests.ps1 | 7 +++++++ tests/cis/Test.CIS.M365.2.1.10.md | 2 +- tests/cis/Test.CIS.M365.2.1.10.ps1 | 4 ++++ tests/cis/Test.CIS.M365.2.1.8.md | 2 +- tests/cis/Test.CIS.M365.2.1.8.ps1 | 4 ++++ tests/cis/Test.CIS.M365.2.1.9.md | 2 +- tests/cis/Test.CIS.M365.2.1.9.ps1 | 4 ++++ 10 files changed, 41 insertions(+), 3 deletions(-) diff --git a/powershell/assets/MaesterSettings.psd1 b/powershell/assets/MaesterSettings.psd1 index da232935bd..a465116a45 100644 --- a/powershell/assets/MaesterSettings.psd1 +++ b/powershell/assets/MaesterSettings.psd1 @@ -10,5 +10,6 @@ GitHubOrganization = @{ Type = 'string'; Default = ''; Sensitive = $false; Description = 'GitHub organization that the GitHub checks read.' } GitHubApiBaseUri = @{ Type = 'string'; Default = 'https://api.github.com'; Sensitive = $false; Description = 'Base URI of the GitHub REST API.' } GitHubApiVersion = @{ Type = 'string'; Default = '2022-11-28'; Sensitive = $false; Description = 'GitHub REST API version.' } + ParkedDomains = @{ Type = 'string[]'; Default = @(); Sensitive = $false; Description = 'Domains that do not send email and use the parked-domain audit in CIS 2.1.8-2.1.10 checks.' } } } diff --git a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 index 7a6eb9ce82..c41c4b087e 100644 --- a/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDmarcRecordsPublished.Tests.ps1 @@ -127,6 +127,16 @@ $script:resultDetail.Result | Should -Match '\| parked\.example \| Parked \|' } + It 'uses the shared ParkedDomains setting when no test override is supplied' { + $script:domains = @([pscustomobject]@{ DomainName = 'parked.example'; IsCoExistenceDomain = $false }) + $script:registrableDomains = @{ 'parked.example' = 'parked.example' } + $script:dmarcResults = @{ 'parked.example' = $script:parkedDmarcRecord } + Mock Get-MtSetting -ModuleName Maester { @('parked.example') } + + Test-MtCisDmarcRecordsPublished | Should -BeTrue + $script:resultDetail.Result | Should -Match '\| parked\.example \| Parked \|' + } + It 'fails a parked domain whose DMARC policy is quarantine' { $script:domains = @([pscustomobject]@{ DomainName = 'parked.example'; IsCoExistenceDomain = $false }) $script:registrableDomains = @{ 'parked.example' = 'parked.example' } diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index 700828c261..da5ce65df8 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -70,6 +70,14 @@ $script:resultDetail.Result | Should -Match '\| example\.com \| Sending \|' } + It 'uses the shared ParkedDomains setting when no test override is supplied' { + $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 -all' } + Mock Get-MtSetting -ModuleName Maester { @('example.com') } + + Test-MtCisSpfRecordsPublished | Should -BeTrue + $script:resultDetail.Result | Should -Match '\| example\.com \| Parked \|' + } + It 'keeps the soft-fail rule for sending domains' { $script:spfResults['example.com'] = [pscustomobject]@{ record = 'v=spf1 include:spf.example.net ~all' } diff --git a/powershell/tests/functions/Test-MtDkim.Tests.ps1 b/powershell/tests/functions/Test-MtDkim.Tests.ps1 index 18eeb33906..7907510330 100644 --- a/powershell/tests/functions/Test-MtDkim.Tests.ps1 +++ b/powershell/tests/functions/Test-MtDkim.Tests.ps1 @@ -139,6 +139,13 @@ Describe 'CIS DKIM with ParkedDomains' { Should -Invoke Resolve-MtDnsRecord -ModuleName Maester -Exactly 0 } + It 'uses the shared ParkedDomains setting when no test override is supplied' { + Mock Get-MtSetting -ModuleName Maester { @('parked.example') } + + Test-MtCisDkim | Should -BeTrue + $script:detail.Result | Should -Match '\| parked\.example \| Parked \|' + } + It 'passes a listed domain with no selector records' { Test-MtCisDkim -ParkedDomains 'PARKED.example.' | Should -BeTrue $script:detail.Result | Should -Match '\| parked\.example \| Parked \|' diff --git a/tests/cis/Test.CIS.M365.2.1.10.md b/tests/cis/Test.CIS.M365.2.1.10.md index a3e41ab766..f380d95428 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.md +++ b/tests/cis/Test.CIS.M365.2.1.10.md @@ -4,7 +4,7 @@ DMARC tells receiving servers what to do with mail that fails SPF and DKIM align The test uses the record at the domain, or at its organisational domain (for example contoso.com for mail.contoso.com) when the domain has no valid record, including a malformed record, applying the subdomain policy where one exists. For sending domains, the policy must apply to 100 percent of mail (no pct tag, or pct=100), and both rua and ruf addresses must be mailto addresses. -Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so list your parked domains, the ones that never send email, in this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. Every other domain gets the sending-domain audit. +Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so set the shared `GlobalSettings.ParkedDomains` list in the Maester config for all three checks. A per-test `ParkedDomains` value in `TestSettings[].Parameters` overrides the shared list for that check. Every other domain gets the sending-domain audit. Parked domains use the CIS parked-domain requirement: a valid DMARC record with `p=reject`; rua, ruf and pct are not required. When the DNS lookup is not available for a domain, it is listed as Not checked. diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index 141a804e1d..a11ed3a237 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -37,6 +37,10 @@ [string[]]$ParkedDomains = @() ) + if (-not $PSBoundParameters.ContainsKey('ParkedDomains')) { + $ParkedDomains = Get-MtSetting -Name 'ParkedDomains' + } + Write-Verbose 'Getting accepted domains...' $domains = @(Get-MtExo -Request AcceptedDomain | Where-Object { $_.IsCoExistenceDomain -eq $false }) diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index a10a83dc6e..fd84529e77 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -2,7 +2,7 @@ Sending domains must publish an SPF record that ends in a hard fail (-all) or so SPF lists the servers that may send mail for a domain. Receiving servers use it to reject, or to mark as suspicious, mail that pretends to come from your domain. Without an SPF record, or with one that ends in a neutral or permissive qualifier, anyone can send mail that looks like it comes from you without raising a flag. -Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so list your parked domains, the ones that never send email, in this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. Every other domain gets the sending-domain audit. +Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so set the shared `GlobalSettings.ParkedDomains` list in the Maester config for all three checks. A per-test `ParkedDomains` value in `TestSettings[].Parameters` overrides the shared list for that check. Every other domain gets the sending-domain audit. For a parked domain the record must be `v=spf1 -all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 1182ce11e4..4d79e063d0 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -37,6 +37,10 @@ [string[]]$ParkedDomains = @() ) + if (-not $PSBoundParameters.ContainsKey('ParkedDomains')) { + $ParkedDomains = Get-MtSetting -Name 'ParkedDomains' + } + Write-Verbose 'Getting accepted domains...' $domains = @(Get-MtExo -Request AcceptedDomain | Where-Object { $_.InitialDomain -eq $false -and $_.IsCoExistenceDomain -eq $false }) diff --git a/tests/cis/Test.CIS.M365.2.1.9.md b/tests/cis/Test.CIS.M365.2.1.9.md index 5f2f02f787..fc3c4cdcd3 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.md +++ b/tests/cis/Test.CIS.M365.2.1.9.md @@ -14,7 +14,7 @@ There should be no impact of setting up DKIM however, organizations should ensur The check requires Exchange DKIM to be enabled and its status to be **Valid** for every domain except the parked domains you list. -Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so list your parked domains, the ones that never send email, in this test's `ParkedDomains` parameter in `TestSettings[].Parameters`. Every other domain gets the sending-domain audit. +Maester does not guess which domains are parked. CIS leaves that to the person running the audit, so set the shared `GlobalSettings.ParkedDomains` list in the Maester config for all three checks. A per-test `ParkedDomains` value in `TestSettings[].Parameters` overrides the shared list for that check. Every other domain gets the sending-domain audit. For a parked domain, CIS asks that DKIM records are not published. The check passes when none of the selector1/selector2 CNAME or TXT records exist, and fails when one does. If some of those lookups fail, the domain is marked for investigation; if DNS lookups are not available at all, it is skipped. Only the standard Exchange Online selectors are checked. diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index eefdd37036..47a96b8e8b 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -42,6 +42,10 @@ [string[]]$ParkedDomains = @() ) + if (-not $PSBoundParameters.ContainsKey('ParkedDomains')) { + $ParkedDomains = Get-MtSetting -Name 'ParkedDomains' + } + $dkimSigningConfigs = Get-MtExo -Request DkimSigningConfig $acceptedDomains = Get-MtExo -Request AcceptedDomain From 8a658d6151e6a60aee6fa03091019cbc2fbf12b7 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 08:50:14 +1300 Subject: [PATCH 18/20] Reject repeated SPF exp modifiers --- .../tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 | 1 + tests/cis/Test.CIS.M365.2.1.8.ps1 | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index da5ce65df8..b66b54d5c6 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -47,6 +47,7 @@ @{ Record = 'v=spf1 include:spf.protection.outlook.com -all' } @{ Record = 'v=spf1 redirect=_spf.example.net' } @{ Record = 'v=spf1 -all exp=why.example.com' } + @{ Record = 'v=spf1 exp=a.example exp=b.example -all' } ) { $script:spfResults['example.com'] = [pscustomobject]@{ record = $Record } $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 -all' } diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 4d79e063d0..cbf230f86a 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -58,7 +58,7 @@ if ($isParked) { # CIS asks parked domains for v=spf1 -all: no sender mechanisms, no redirect, hard fail last. # An exp= modifier authorizes no one, so it is allowed before -all. - $pass = [string]$record -match '(?i)^\s*v=spf1(\s+exp=\S+)*\s+-all\s*$' + $pass = [string]$record -match '(?i)^\s*v=spf1(?:\s+exp=\S+)?\s+-all\s*$' $detail = if ($pass) { 'Listed as parked; the record denies all senders with -all.' } else { From a6ff0dbd1ef69f43a784ee2c2d7837ea5151ba0a Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 09:19:57 +1300 Subject: [PATCH 19/20] fix(cis): validate parked SPF explanation domain syntax Reject malformed exp domain-spec macros without expanding them, preserving valid macros and the terminal hard-fail policy. Add regression coverage and clarify the guide. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Test-MtCisSpfRecordsPublished.Tests.ps1 | 17 +++++++++++++++++ tests/cis/Test.CIS.M365.2.1.8.md | 3 ++- tests/cis/Test.CIS.M365.2.1.8.ps1 | 7 +++++-- 3 files changed, 24 insertions(+), 3 deletions(-) diff --git a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 index b66b54d5c6..6689abda11 100644 --- a/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisSpfRecordsPublished.Tests.ps1 @@ -36,6 +36,11 @@ @{ Record = 'v=spf1 -all' } @{ Record = 'V=SPF1 -ALL ' } @{ Record = 'v=spf1 exp=why.example.com -all' } + @{ Record = 'v=spf1 exp=explain._spf.%{d} -all' } + @{ Record = 'v=spf1 exp=%{ir}.%{v}.%{d2r-}.example.com -all' } + @{ Record = 'V=SPF1 EXP=%{S}.%{L1R+}.example.com. -ALL' } + @{ Record = 'v=spf1 exp=why%%.%_.%-.example.com -all' } + @{ Record = 'v=spf1 exp=why.example.xn--p1ai -all' } ) { $script:spfResults['example.com'] = [pscustomobject]@{ record = $Record } @@ -48,6 +53,18 @@ @{ Record = 'v=spf1 redirect=_spf.example.net' } @{ Record = 'v=spf1 -all exp=why.example.com' } @{ Record = 'v=spf1 exp=a.example exp=b.example -all' } + @{ Record = 'v=spf1 exp=%(d).example.com -all' } + @{ Record = 'v=spf1 exp=%{d.example.com -all' } + @{ Record = 'v=spf1 exp=%{x}.example.com -all' } + @{ Record = 'v=spf1 exp=%{d2rr}.example.com -all' } + @{ Record = 'v=spf1 exp=%{d:}.example.com -all' } + @{ Record = 'v=spf1 exp=why%.example.com -all' } + @{ Record = 'v=spf1 exp=%{c}.example.com -all' } + @{ Record = 'v=spf1 exp=why.example.123 -all' } + @{ Record = 'v=spf1 exp=why.example.com- -all' } + @{ Record = 'v=spf1 exp= -all' } + @{ Record = 'v=spf10 exp=%{d} -all' } + @{ Record = 'v=spf1 exp=%{d} ~all' } ) { $script:spfResults['example.com'] = [pscustomobject]@{ record = $Record } $script:spfResults['_spf.example.net'] = [pscustomobject]@{ record = 'v=spf1 -all' } diff --git a/tests/cis/Test.CIS.M365.2.1.8.md b/tests/cis/Test.CIS.M365.2.1.8.md index fd84529e77..3e1758ac3d 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.md +++ b/tests/cis/Test.CIS.M365.2.1.8.md @@ -6,7 +6,7 @@ Maester does not guess which domains are parked. CIS leaves that to the person r For a parked domain the record must be `v=spf1 -all`; a `~all` policy does not meet the parked-domain audit. For sending domains, the test follows a redirect modifier only when the record has no all mechanism, since receivers ignore the redirect in that case. Domains in the onmicrosoft.com namespace are skipped. -An `exp=` modifier does not authorize senders. The audit still requires the compliant all mechanism to be the final term: `v=spf1 -all exp=why.example.com` does not meet that termination requirement. An earlier `all` mechanism ends SPF evaluation before a later qualifier, so a record such as `v=spf1 all include:vendor.example -all` does not meet the audit. +An `exp=` modifier does not authorize senders. A parked-domain record may include one before `-all`, but its domain-spec must have valid RFC 7208 syntax: `exp=explain._spf.%{d}` is valid, while `exp=%(d).example.com` is not. The check validates syntax without expanding macros or looking up the explanation text. The audit still requires the compliant all mechanism to be the final term: `v=spf1 -all exp=why.example.com` does not meet that termination requirement. An earlier `all` mechanism ends SPF evaluation before a later qualifier, so a record such as `v=spf1 all include:vendor.example -all` does not meet the audit. #### Remediation action @@ -19,6 +19,7 @@ An `exp=` modifier does not authorize senders. The audit still requires the comp * [Set up SPF to help prevent spoofing](https://learn.microsoft.com/defender-office-365/email-authentication-spf-configure) * [Email authentication in Microsoft 365](https://learn.microsoft.com/defender-office-365/email-authentication-about) * [CIS Microsoft 365 Foundations Benchmark v7.0.0 - 2.1.8](https://www.cisecurity.org/benchmark/microsoft_365) +* [RFC 7208 - SPF macro syntax](https://www.rfc-editor.org/rfc/rfc7208.html#section-7) %TestResult% diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index cbf230f86a..43ad9cd022 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -57,8 +57,11 @@ $record = if ($spf -and $spf.PSObject.Properties['record']) { $spf.record } else { $null } if ($isParked) { # CIS asks parked domains for v=spf1 -all: no sender mechanisms, no redirect, hard fail last. - # An exp= modifier authorizes no one, so it is allowed before -all. - $pass = [string]$record -match '(?i)^\s*v=spf1(?:\s+exp=\S+)?\s+-all\s*$' + # RFC 7208 sections 7.1-7.2: validate exp's domain-spec, not the fetched explanation text. + $macroExpand = '%(?:\{[slodiphv][0-9]*r?[.\-+,/_=]*\}|[%_-])' + $macroString = "(?:$macroExpand|[\x21-\x24\x26-\x7E])*" + $domainEnd = "(?:\.(?:[a-z0-9]*[a-z][a-z0-9]*|[a-z0-9]+-[a-z0-9-]*[a-z0-9])\.?|$macroExpand)" + $pass = [string]$record -match "(?i)^\s*v=spf1(?:\s+exp=$macroString$domainEnd)?\s+-all\s*$" $detail = if ($pass) { 'Listed as parked; the record denies all senders with -all.' } else { From cdc79f68b9d93d804601a97a2075285d509c7de3 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Fri, 13 Nov 2026 08:10:17 +1300 Subject: [PATCH 20/20] chore: credit reviewers for parked-domain findings Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/cis/Test.CIS.M365.2.1.10.ps1 | 3 ++- tests/cis/Test.CIS.M365.2.1.8.ps1 | 3 ++- tests/cis/Test.CIS.M365.2.1.9.ps1 | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/cis/Test.CIS.M365.2.1.10.ps1 b/tests/cis/Test.CIS.M365.2.1.10.ps1 index a11ed3a237..7a3f03f7ec 100644 --- a/tests/cis/Test.CIS.M365.2.1.10.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.10.ps1 @@ -28,7 +28,8 @@ Mitre = ('T1566', 'T1684.002'), Control = ('cis-m365:2.1.10', 'nist-800-53-r5:SI-8'), Service = 'ExchangeOnline', - Author = 'JeremyFinney-lgtm' + Author = 'JeremyFinney-lgtm', + Contributor = ('earbona23', 'merill') )] [CmdletBinding()] [OutputType([bool])] diff --git a/tests/cis/Test.CIS.M365.2.1.8.ps1 b/tests/cis/Test.CIS.M365.2.1.8.ps1 index 43ad9cd022..01c4ca871a 100644 --- a/tests/cis/Test.CIS.M365.2.1.8.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.8.ps1 @@ -28,7 +28,8 @@ Mitre = ('T1566', 'T1684.002'), Control = ('cis-m365:2.1.8', 'nist-800-53-r5:SI-8'), Service = 'ExchangeOnline', - Author = 'JeremyFinney-lgtm' + Author = 'JeremyFinney-lgtm', + Contributor = ('earbona23', 'merill') )] [CmdletBinding()] [OutputType([bool])] diff --git a/tests/cis/Test.CIS.M365.2.1.9.ps1 b/tests/cis/Test.CIS.M365.2.1.9.ps1 index 47a96b8e8b..f23265f7e2 100644 --- a/tests/cis/Test.CIS.M365.2.1.9.ps1 +++ b/tests/cis/Test.CIS.M365.2.1.9.ps1 @@ -30,7 +30,7 @@ Control = ('cis-m365:2.1.9', 'nist-800-53-r5:SC-8'), Service = 'ExchangeOnline', Author = 'NZLostboy', - Contributor = ('JeanPhilippeGeorge', 'brianreidc7', 'amlhive-tech', 'JeremyFinney-lgtm') + Contributor = ('JeanPhilippeGeorge', 'brianreidc7', 'amlhive-tech', 'JeremyFinney-lgtm', 'earbona23', 'merill') )] [CmdletBinding()] [OutputType([bool])]