From 15cb469c1db0e30ceed3457ee6954d52056958d8 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 20 Nov 2026 15:02:39 +0100 Subject: [PATCH 1/2] fix(cis): CIS.M365.5.2.2.14 ignores private ranges in trusted locations Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of a device on the intranet, so a trusted named location with only private or other non-routable ranges never matches a sign-in. The check now requires a public range, shows how many ranges are private, and has unit tests. --- .../Test-MtCisTrustedNamedLocation.Tests.ps1 | 91 +++++++++++++++++++ tests/cis/Test.CIS.M365.5.2.2.14.md | 4 +- tests/cis/Test.CIS.M365.5.2.2.14.ps1 | 71 ++++++++++++--- 3 files changed, 150 insertions(+), 16 deletions(-) create mode 100644 powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 diff --git a/powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 b/powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 new file mode 100644 index 0000000000..b5a0403072 --- /dev/null +++ b/powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 @@ -0,0 +1,91 @@ +Describe 'Test-MtCisTrustedNamedLocation' { + BeforeAll { + Import-Module "$PSScriptRoot\..\..\Maester.psd1" -Force + . "$PSScriptRoot\..\helpers\Use-MtModuleFunction.ps1" + # Check functions that became native tests are not exported. + Use-MtModuleFunction -Name Test-MtCisTrustedNamedLocation + + function Get-TestIpLocation { + param( + [string] $DisplayName, + [string[]] $CidrAddress, + [switch] $Trusted + ) + [pscustomobject]@{ + '@odata.type' = '#microsoft.graph.ipNamedLocation' + displayName = $DisplayName + isTrusted = [bool]$Trusted + ipRanges = @( + foreach ($cidr in $CidrAddress) { + [pscustomobject]@{ + '@odata.type' = if ($cidr -like '*:*') { '#microsoft.graph.iPv6CidrRange' } else { '#microsoft.graph.iPv4CidrRange' } + cidrAddress = $cidr + } + } + ) + } + } + } + + BeforeEach { + Mock Add-MtTestResultDetail -ModuleName Maester { } + } + + It 'Passes for a trusted location with a public range' { + $locations = @(Get-TestIpLocation -DisplayName 'Head office' -CidrAddress '203.0.113.0/24' -Trusted) + Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } + + Test-MtCisTrustedNamedLocation | Should -BeTrue + } + + It 'Fails for a trusted location that has only private ranges, and says why' { + $locations = @(Get-TestIpLocation -DisplayName 'RFC 1918' -CidrAddress '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16' -Trusted) + Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } + + Test-MtCisTrustedNamedLocation | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like 'No trusted IP named location has a public IP range*' -and + $Result -like '*| RFC 1918 | 3 | 3 | True |*' + } + } + + It 'Fails for a trusted location in IPv6 unique local space' { + $locations = @(Get-TestIpLocation -DisplayName 'IPv6 lab' -CidrAddress 'fd00::/8' -Trusted) + Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } + + Test-MtCisTrustedNamedLocation | Should -BeFalse + } + + It 'Passes for a trusted location that mixes private and public ranges' { + $locations = @(Get-TestIpLocation -DisplayName 'Offices' -CidrAddress '192.168.0.0/16', '2001:db8::/32' -Trusted) + Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } + + Test-MtCisTrustedNamedLocation | Should -BeTrue + } + + It 'Fails for a public range that is not trusted' { + $locations = @(Get-TestIpLocation -DisplayName 'Partner' -CidrAddress '198.51.100.0/24') + Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } + + Test-MtCisTrustedNamedLocation | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like 'No IP named location is both trusted and has IP ranges*' + } + } + + It 'Fails when only country locations exist' { + $locations = @( + [pscustomobject]@{ + '@odata.type' = '#microsoft.graph.countryNamedLocation' + displayName = 'Allowed countries' + countriesAndRegions = @('FR') + } + ) + Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } + + Test-MtCisTrustedNamedLocation | Should -BeFalse + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like 'No IP named locations are defined*' + } + } +} diff --git a/tests/cis/Test.CIS.M365.5.2.2.14.md b/tests/cis/Test.CIS.M365.5.2.2.14.md index 057007b4d5..70bf5a74b7 100644 --- a/tests/cis/Test.CIS.M365.5.2.2.14.md +++ b/tests/cis/Test.CIS.M365.5.2.2.14.md @@ -1,8 +1,8 @@ -At least one IP-based named location with address ranges exists and is marked as trusted. +At least one IP-based named location with a public address range exists and is marked as trusted. Named locations give Conditional Access a way to tell your offices and known egress addresses from the rest of the internet. Marked as trusted, they feed Microsoft Entra ID Protection and let policies relax or tighten requirements by network. -The test passes when at least one IP named location has ranges and is trusted. Country-based locations are not counted. Only mark a network as trusted when it is under your control. +The test passes when at least one IP named location has a public range and is trusted. A range in private or other non-routable address space, such as 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16, doesn't count: Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of a device on the intranet, so these ranges never match a sign-in. Country-based locations are not counted. Only mark a network as trusted when it is under your control. #### Remediation action diff --git a/tests/cis/Test.CIS.M365.5.2.2.14.ps1 b/tests/cis/Test.CIS.M365.5.2.2.14.ps1 index a2eeb9d9c8..1ed7e0086a 100644 --- a/tests/cis/Test.CIS.M365.5.2.2.14.ps1 +++ b/tests/cis/Test.CIS.M365.5.2.2.14.ps1 @@ -1,16 +1,17 @@ function Test-MtCisTrustedNamedLocation { <# .SYNOPSIS - Checks that at least one trusted IP named location with ranges is defined. + Checks that at least one trusted IP named location with a public IP range is defined. .DESCRIPTION - Checks that at least one IP-based named location in Conditional Access has IP ranges and is marked as trusted, so that policies can treat sign-ins from your known networks differently. + Checks that at least one IP-based named location in Conditional Access has a public IP range and is marked as trusted, so that policies can treat sign-ins from your known networks differently. + A range in private or other non-routable address space doesn't count: Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of a device on the intranet. CIS Microsoft 365 Foundations Benchmark v7.0.0 (5.2.2.14, L2) .EXAMPLE Test-MtCisTrustedNamedLocation - Returns true if at least one trusted IP named location with ranges exists. + Returns true if at least one trusted IP named location with a public IP range exists. .LINK https://maester.dev/docs/tests/CIS.M365.5.2.2.14 @@ -29,7 +30,8 @@ Control = ('cis-m365:5.2.2.14', 'nist-800-53-r5:AC-3'), Service = 'Graph', License = 'AAD_PREMIUM', - Author = 'JeremyFinney-lgtm' + Author = 'JeremyFinney-lgtm', + Contributor = 'julien-ly' )] [CmdletBinding()] [OutputType([bool])] @@ -39,24 +41,65 @@ $locations = Invoke-MtGraphRequest -RelativeUri 'identity/conditionalAccess/namedLocations' $ipLocations = @($locations | Where-Object { $_.'@odata.type' -eq '#microsoft.graph.ipNamedLocation' }) + # Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of + # a device on the intranet, so a range in private or other non-routable address space can't match a sign-in. + $nonPublicNetworks = @( + '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', # Private (RFC 1918) + '100.64.0.0/10', # Shared address space (RFC 6598) + '127.0.0.0/8', '169.254.0.0/16', # Loopback and link-local + 'fc00::/7', 'fe80::/10', '::1/128' # IPv6 unique local, link-local and loopback + ) + $isNonPublicRange = { + param([string] $Cidr) + $address, $prefix = $Cidr.Split('/') + $ip = $null + if (-not [System.Net.IPAddress]::TryParse($address, [ref]$ip)) { return $false } + $bytes = $ip.GetAddressBytes() + $prefixLength = if ($prefix) { [int]$prefix } else { $bytes.Count * 8 } + foreach ($network in $nonPublicNetworks) { + $networkAddress, $networkPrefix = $network.Split('/') + $networkBytes = [System.Net.IPAddress]::Parse($networkAddress).GetAddressBytes() + # The range lies inside the network when it is at least as narrow and shares the network's prefix bits. + if ($networkBytes.Count -ne $bytes.Count -or $prefixLength -lt [int]$networkPrefix) { continue } + $inNetwork = $true + for ($bit = 0; $bit -lt [int]$networkPrefix; $bit++) { + $mask = 0x80 -shr ($bit % 8) + if (($bytes[$bit -shr 3] -band $mask) -ne ($networkBytes[$bit -shr 3] -band $mask)) { + $inNetwork = $false + break + } + } + if ($inNetwork) { return $true } + } + return $false + } + $report = foreach ($location in $ipLocations) { - $rangeCount = @($location.ipRanges).Count + $ranges = @($location.ipRanges | ForEach-Object { [string]$_.cidrAddress } | Where-Object { $_ }) + $privateRangeCount = @($ranges | Where-Object { & $isNonPublicRange $_ }).Count [pscustomobject]@{ - Name = $location.displayName - Ranges = $rangeCount - Trusted = [bool]$location.isTrusted - Pass = $rangeCount -gt 0 -and $location.isTrusted -eq $true + Name = $location.displayName + Ranges = $ranges.Count + PrivateRanges = $privateRangeCount + Trusted = [bool]$location.isTrusted + Pass = $ranges.Count -gt $privateRangeCount -and $location.isTrusted -eq $true } } $testResult = @($report | Where-Object { $_.Pass }).Count -gt 0 - $passText = 'At least one trusted IP named location with IP ranges is defined.' - $failText = if ($ipLocations.Count -eq 0) { 'No IP named locations are defined.' } else { 'No IP named location is both trusted and has IP ranges.' } + $passText = 'At least one trusted IP named location with a public IP range is defined.' + $failText = if ($ipLocations.Count -eq 0) { + 'No IP named locations are defined.' + } elseif (@($report | Where-Object { $_.Trusted -and $_.Ranges -gt 0 -and $_.PrivateRanges -eq $_.Ranges }).Count -gt 0) { + 'No trusted IP named location has a public IP range. Microsoft Entra ID evaluates the public address that a network uses to reach the internet, so private ranges never match a sign-in.' + } else { + 'No IP named location is both trusted and has IP ranges.' + } - $resultMd = "| Named location | IP ranges | Trusted | Result |`n" - $resultMd += "| --- | --- | --- | --- |`n" + $resultMd = "| Named location | IP ranges | Private ranges | Trusted | Result |`n" + $resultMd += "| --- | --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultMd += "| $($row.Name) | $($row.Ranges) | $($row.Trusted) | $(if ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" + $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $($row.Ranges) | $($row.PrivateRanges) | $($row.Trusted) | $(if ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" } if ($testResult) { From f08b045e3fc7f5e56fb8c5c75f5ce5427e09efe3 Mon Sep 17 00:00:00 2001 From: Julien Ly Date: Fri, 20 Nov 2026 15:21:53 +0100 Subject: [PATCH 2/2] fix(cis): keep the CIS 5.2.2.14 verdict, list unmatchable trusted locations The verdict follows the CIS audit again: a trusted IP named location with at least one range. The result now lists the trusted locations whose ranges are all private, special-purpose or otherwise non-routable, which never match a sign-in. Documentation, benchmarking, multicast and reserved ranges count as non-public, and the positive cases use routable ranges. --- .../Test-MtCisTrustedNamedLocation.Tests.ps1 | 38 ++++++------ tests/cis/Test.CIS.M365.5.2.2.14.md | 4 +- tests/cis/Test.CIS.M365.5.2.2.14.ps1 | 58 +++++++++++-------- 3 files changed, 56 insertions(+), 44 deletions(-) diff --git a/powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 b/powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 index b5a0403072..8760716b39 100644 --- a/powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisTrustedNamedLocation.Tests.ps1 @@ -31,40 +31,44 @@ Mock Add-MtTestResultDetail -ModuleName Maester { } } - It 'Passes for a trusted location with a public range' { - $locations = @(Get-TestIpLocation -DisplayName 'Head office' -CidrAddress '203.0.113.0/24' -Trusted) + It 'Passes for a trusted location with a public range, without a note' { + $locations = @(Get-TestIpLocation -DisplayName 'Head office' -CidrAddress '8.8.8.0/24' -Trusted) Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } Test-MtCisTrustedNamedLocation | Should -BeTrue - } - - It 'Fails for a trusted location that has only private ranges, and says why' { - $locations = @(Get-TestIpLocation -DisplayName 'RFC 1918' -CidrAddress '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16' -Trusted) - Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } - - Test-MtCisTrustedNamedLocation | Should -BeFalse Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { - $Result -like 'No trusted IP named location has a public IP range*' -and - $Result -like '*| RFC 1918 | 3 | 3 | True |*' + $Result -like 'Well done.*' -and $Result -notlike '*never match a sign-in*' } } - It 'Fails for a trusted location in IPv6 unique local space' { - $locations = @(Get-TestIpLocation -DisplayName 'IPv6 lab' -CidrAddress 'fd00::/8' -Trusted) + It 'Passes for a trusted location whose ranges are all , and lists it' -ForEach @( + @{ Kind = 'private (RFC 1918)'; Cidr = @('10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16') } + @{ Kind = 'documentation ranges'; Cidr = @('203.0.113.0/24', '2001:db8::/32') } + @{ Kind = 'IPv6 unique local'; Cidr = @('fd00::/8') } + ) { + $locations = @(Get-TestIpLocation -DisplayName 'Internal networks' -CidrAddress $Cidr -Trusted) Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } - Test-MtCisTrustedNamedLocation | Should -BeFalse + Test-MtCisTrustedNamedLocation | Should -BeTrue + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like 'Well done.*' -and + $Result -like "*| Internal networks | $($Cidr.Count) | $($Cidr.Count) | True |*" -and + $Result -like '*never match a sign-in*- Internal networks*' + } } - It 'Passes for a trusted location that mixes private and public ranges' { - $locations = @(Get-TestIpLocation -DisplayName 'Offices' -CidrAddress '192.168.0.0/16', '2001:db8::/32' -Trusted) + It 'Passes for a trusted location that mixes private and public ranges, without a note' { + $locations = @(Get-TestIpLocation -DisplayName 'Offices' -CidrAddress '192.168.0.0/16', '2001:4860::/32' -Trusted) Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } Test-MtCisTrustedNamedLocation | Should -BeTrue + Should -Invoke Add-MtTestResultDetail -ModuleName Maester -Times 1 -Exactly -ParameterFilter { + $Result -like '*| Offices | 2 | 1 | True |*' -and $Result -notlike '*never match a sign-in*' + } } It 'Fails for a public range that is not trusted' { - $locations = @(Get-TestIpLocation -DisplayName 'Partner' -CidrAddress '198.51.100.0/24') + $locations = @(Get-TestIpLocation -DisplayName 'Partner' -CidrAddress '8.8.4.0/24') Mock Invoke-MtGraphRequest -ModuleName Maester { $locations } Test-MtCisTrustedNamedLocation | Should -BeFalse diff --git a/tests/cis/Test.CIS.M365.5.2.2.14.md b/tests/cis/Test.CIS.M365.5.2.2.14.md index 70bf5a74b7..f0f2f3a7d7 100644 --- a/tests/cis/Test.CIS.M365.5.2.2.14.md +++ b/tests/cis/Test.CIS.M365.5.2.2.14.md @@ -1,8 +1,8 @@ -At least one IP-based named location with a public address range exists and is marked as trusted. +At least one IP-based named location with address ranges exists and is marked as trusted. Named locations give Conditional Access a way to tell your offices and known egress addresses from the rest of the internet. Marked as trusted, they feed Microsoft Entra ID Protection and let policies relax or tighten requirements by network. -The test passes when at least one IP named location has a public range and is trusted. A range in private or other non-routable address space, such as 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16, doesn't count: Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of a device on the intranet, so these ranges never match a sign-in. Country-based locations are not counted. Only mark a network as trusted when it is under your control. +The test passes when at least one IP named location has ranges and is trusted, as the benchmark asks. The result also lists the trusted locations whose ranges are all private or otherwise non-routable, such as 10.0.0.0/8, 172.16.0.0/12 or 192.168.0.0/16. They meet the benchmark, but they never match a sign-in: Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of a device on the intranet. Country-based locations are not counted. Only mark a network as trusted when it is under your control. #### Remediation action diff --git a/tests/cis/Test.CIS.M365.5.2.2.14.ps1 b/tests/cis/Test.CIS.M365.5.2.2.14.ps1 index 1ed7e0086a..2dba901b98 100644 --- a/tests/cis/Test.CIS.M365.5.2.2.14.ps1 +++ b/tests/cis/Test.CIS.M365.5.2.2.14.ps1 @@ -1,17 +1,17 @@ function Test-MtCisTrustedNamedLocation { <# .SYNOPSIS - Checks that at least one trusted IP named location with a public IP range is defined. + Checks that at least one trusted IP named location with ranges is defined. .DESCRIPTION - Checks that at least one IP-based named location in Conditional Access has a public IP range and is marked as trusted, so that policies can treat sign-ins from your known networks differently. - A range in private or other non-routable address space doesn't count: Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of a device on the intranet. + Checks that at least one IP-based named location in Conditional Access has IP ranges and is marked as trusted, so that policies can treat sign-ins from your known networks differently. + The result also lists the trusted locations whose ranges are all private or otherwise non-routable. They meet the benchmark, but they never match a sign-in: Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of a device on the intranet. CIS Microsoft 365 Foundations Benchmark v7.0.0 (5.2.2.14, L2) .EXAMPLE Test-MtCisTrustedNamedLocation - Returns true if at least one trusted IP named location with a public IP range exists. + Returns true if at least one trusted IP named location with ranges exists. .LINK https://maester.dev/docs/tests/CIS.M365.5.2.2.14 @@ -42,12 +42,17 @@ $ipLocations = @($locations | Where-Object { $_.'@odata.type' -eq '#microsoft.graph.ipNamedLocation' }) # Microsoft Entra ID evaluates the public address that a network uses to reach the internet, never the address of - # a device on the intranet, so a range in private or other non-routable address space can't match a sign-in. + # a device on the intranet, so a range in private, special-purpose or otherwise non-routable space can't match a sign-in. $nonPublicNetworks = @( - '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', # Private (RFC 1918) - '100.64.0.0/10', # Shared address space (RFC 6598) - '127.0.0.0/8', '169.254.0.0/16', # Loopback and link-local - 'fc00::/7', 'fe80::/10', '::1/128' # IPv6 unique local, link-local and loopback + '10.0.0.0/8', '172.16.0.0/12', '192.168.0.0/16', # Private (RFC 1918) + '100.64.0.0/10', # Shared address space (RFC 6598) + '0.0.0.0/8', '127.0.0.0/8', '169.254.0.0/16', # This network, loopback and link-local + '192.0.2.0/24', '198.51.100.0/24', '203.0.113.0/24', # Documentation (RFC 5737) + '198.18.0.0/15', # Benchmarking (RFC 2544) + '224.0.0.0/4', '240.0.0.0/4', # Multicast and reserved + 'fc00::/7', 'fe80::/10', '::1/128', '::/128', # IPv6 unique local, link-local, loopback and unspecified + '2001:db8::/32', '3fff::/20', # IPv6 documentation (RFC 3849, RFC 9637) + 'ff00::/8' # IPv6 multicast ) $isNonPublicRange = { param([string] $Cidr) @@ -76,30 +81,26 @@ $report = foreach ($location in $ipLocations) { $ranges = @($location.ipRanges | ForEach-Object { [string]$_.cidrAddress } | Where-Object { $_ }) - $privateRangeCount = @($ranges | Where-Object { & $isNonPublicRange $_ }).Count + $nonPublicRangeCount = @($ranges | Where-Object { & $isNonPublicRange $_ }).Count [pscustomobject]@{ - Name = $location.displayName - Ranges = $ranges.Count - PrivateRanges = $privateRangeCount - Trusted = [bool]$location.isTrusted - Pass = $ranges.Count -gt $privateRangeCount -and $location.isTrusted -eq $true + Name = $location.displayName + Ranges = $ranges.Count + NonPublicRanges = $nonPublicRangeCount + Trusted = [bool]$location.isTrusted + Pass = $ranges.Count -gt 0 -and $location.isTrusted -eq $true } } $testResult = @($report | Where-Object { $_.Pass }).Count -gt 0 + # Trusted locations that meet the benchmark but can't match any sign-in. + $unmatchable = @($report | Where-Object { $_.Pass -and $_.NonPublicRanges -eq $_.Ranges }) - $passText = 'At least one trusted IP named location with a public IP range is defined.' - $failText = if ($ipLocations.Count -eq 0) { - 'No IP named locations are defined.' - } elseif (@($report | Where-Object { $_.Trusted -and $_.Ranges -gt 0 -and $_.PrivateRanges -eq $_.Ranges }).Count -gt 0) { - 'No trusted IP named location has a public IP range. Microsoft Entra ID evaluates the public address that a network uses to reach the internet, so private ranges never match a sign-in.' - } else { - 'No IP named location is both trusted and has IP ranges.' - } + $passText = 'At least one trusted IP named location with IP ranges is defined.' + $failText = if ($ipLocations.Count -eq 0) { 'No IP named locations are defined.' } else { 'No IP named location is both trusted and has IP ranges.' } - $resultMd = "| Named location | IP ranges | Private ranges | Trusted | Result |`n" + $resultMd = "| Named location | IP ranges | Non-public ranges | Trusted | Result |`n" $resultMd += "| --- | --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $($row.Ranges) | $($row.PrivateRanges) | $($row.Trusted) | $(if ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" + $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $($row.Ranges) | $($row.NonPublicRanges) | $($row.Trusted) | $(if ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" } if ($testResult) { @@ -109,6 +110,13 @@ } $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd + if ($unmatchable.Count -gt 0) { + $unmatchableList = ($unmatchable | ForEach-Object { "- $(Get-MtSafeMarkdown $_.Name)" }) -join "`n" + $testResultMarkdown += "`n`nThe following trusted locations meet the benchmark, but all their ranges are private or otherwise " + + 'non-routable, so they never match a sign-in: Microsoft Entra ID evaluates the public address that a network uses ' + + "to reach the internet. Add the public ranges of your egress points.`n`n$unmatchableList" + } + Add-MtTestResultDetail -Result $testResultMarkdown return $testResult }