From 030523f629fd700c5e89c5e4649d43bc2d30a59a Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Tue, 3 Nov 2026 08:28:20 -0700
Subject: [PATCH 01/16] feat(defender): add MT.1264 - one result per Microsoft
Secure Score improvement action (#2511)
---
powershell/assets/MaesterTaxonomy.psd1 | 1 +
.../public/connect/Get-MtGraphScope.ps1 | 2 +
.../functions/Get-MtGraphScope.Tests.ps1 | 2 +
.../Test-MtSecureScoreControl.Tests.ps1 | 278 ++++++++++++++++++
tests/maester/defender/Test.MT.1264.md | 24 ++
tests/maester/defender/Test.MT.1264.ps1 | 208 +++++++++++++
website/docs/sections/permissions.md | 3 +-
7 files changed, 517 insertions(+), 1 deletion(-)
create mode 100644 powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
create mode 100644 tests/maester/defender/Test.MT.1264.md
create mode 100644 tests/maester/defender/Test.MT.1264.ps1
diff --git a/powershell/assets/MaesterTaxonomy.psd1 b/powershell/assets/MaesterTaxonomy.psd1
index 19098a2fed..d899947120 100644
--- a/powershell/assets/MaesterTaxonomy.psd1
+++ b/powershell/assets/MaesterTaxonomy.psd1
@@ -83,6 +83,7 @@
@{ Key = 'endpoint-antivirus'; Name = 'Endpoint antivirus' }
@{ Key = 'exposure-management'; Name = 'Exposure Management' }
@{ Key = 'defender-for-identity'; Name = 'Defender for Identity' }
+ @{ Key = 'secure-score'; Name = 'Secure Score' }
)
}
@{
diff --git a/powershell/public/connect/Get-MtGraphScope.ps1 b/powershell/public/connect/Get-MtGraphScope.ps1
index e51d5c9990..75142e66a5 100644
--- a/powershell/public/connect/Get-MtGraphScope.ps1
+++ b/powershell/public/connect/Get-MtGraphScope.ps1
@@ -99,6 +99,8 @@
'AgentIdentityBlueprint.Read.All'
'AgentIdentityBlueprintPrincipal.Read.All'
'Application.Read.All'
+ 'Application.Read.All'
+ 'SecurityEvents.Read.All'
)
if ($IncludePreview) {
diff --git a/powershell/tests/functions/Get-MtGraphScope.Tests.ps1 b/powershell/tests/functions/Get-MtGraphScope.Tests.ps1
index 3651e681ed..b279ad0f59 100644
--- a/powershell/tests/functions/Get-MtGraphScope.Tests.ps1
+++ b/powershell/tests/functions/Get-MtGraphScope.Tests.ps1
@@ -30,6 +30,7 @@ Describe 'Get-MtGraphScope' {
$scopes | Should -Not -Contain 'AgentIdentityBlueprint.Read.All'
$scopes | Should -Not -Contain 'AgentIdentityBlueprintPrincipal.Read.All'
$scopes | Should -Not -Contain 'Application.Read.All'
+ $scopes | Should -Not -Contain 'SecurityEvents.Read.All'
$scopes | Should -Contain 'Directory.Read.All'
$scopes | Should -Not -Contain 'User.ReadBasic.All'
}
@@ -40,6 +41,7 @@ Describe 'Get-MtGraphScope' {
$scopes | Should -Contain 'AgentIdentity.Read.All'
$scopes | Should -Contain 'AgentIdentityBlueprint.Read.All'
$scopes | Should -Contain 'AgentIdentityBlueprintPrincipal.Read.All'
+ $scopes | Should -Contain 'SecurityEvents.Read.All'
$scopes | Should -Contain 'Application.Read.All'
$scopes | Should -Contain 'AuditLog.Read.All'
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
new file mode 100644
index 0000000000..8a09317124
--- /dev/null
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -0,0 +1,278 @@
+Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
+ BeforeAll {
+ Import-Module $PSScriptRoot/../../Maester.psd1 -Force
+ . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1"
+ # The native-test functions are not exported; reach them the same way the agent tests do.
+ Use-MtModuleFunction -Name Get-MtSecureScoreControlInstance
+ Use-MtModuleFunction -Name Get-MtSecureScoreControlSeverity
+ Use-MtModuleFunction -Name ConvertFrom-MtSecureScoreHtml
+ Use-MtModuleFunction -Name Test-MtSecureScoreControl
+
+ function New-ControlProfile {
+ param([string] $Id, [double] $MaxScore = 5, [string] $Service = 'MDO', [object[]] $StateUpdates = @(), [bool] $Deprecated = $false)
+ [pscustomobject]@{
+ id = $Id
+ title = "Title of $Id"
+ maxScore = $MaxScore
+ service = $Service
+ controlCategory = 'Apps'
+ deprecated = $Deprecated
+ remediation = "Fix $Id"
+ remediationImpact = 'Low'
+ actionUrl = "https://security.microsoft.com/$Id"
+ controlStateUpdates = @($StateUpdates)
+ }
+ }
+ function New-ControlScore {
+ param([string] $Name, [double] $Score)
+ [pscustomobject]@{ controlName = $Name; score = $Score; description = "About $Name"; implementationStatus = 'Status text'; controlCategory = 'Apps' }
+ }
+ }
+
+ BeforeEach {
+ $script:TestResult = $null
+ $script:Description = $null
+ $script:SkippedBecause = $null
+ $script:SkippedCustomReason = $null
+ $script:Severity = $null
+
+ Mock -ModuleName Maester Add-MtTestResultDetail {
+ param($Result, $Description, $Severity, $SkippedBecause, $SkippedCustomReason)
+ $script:TestResult = $Result
+ $script:Description = $Description
+ $script:Severity = $Severity
+ $script:SkippedBecause = $SkippedBecause
+ $script:SkippedCustomReason = $SkippedCustomReason
+ }
+
+ # Default tenant: three scored controls; the catalog also holds a control the tenant is not scored on.
+ $script:Snapshot = [pscustomobject]@{
+ value = @([pscustomobject]@{
+ controlScores = @(
+ (New-ControlScore -Name 'mdo_safelinks' -Score 9),
+ (New-ControlScore -Name 'AdminMFAV2' -Score 0.15),
+ (New-ControlScore -Name 'exo_mailboxaudit' -Score 0)
+ )
+ })
+ }
+ $script:Profiles = @(
+ (New-ControlProfile -Id 'mdo_safelinks' -MaxScore 9),
+ (New-ControlProfile -Id 'AdminMFAV2' -MaxScore 10 -Service 'AzureAD'),
+ (New-ControlProfile -Id 'exo_mailboxaudit' -MaxScore 3 -Service 'EXO'),
+ (New-ControlProfile -Id 'mda_okta_unscored' -MaxScore 5 -Service 'MDA_Okta')
+ )
+ $script:Recommendations = @{ value = @(@{ recommendationType = 'adminMFAV2' }) }
+
+ Mock -ModuleName Maester Invoke-MtGraphRequest { $script:Snapshot } -ParameterFilter { $RelativeUri -eq 'security/secureScores' }
+ Mock -ModuleName Maester Invoke-MtGraphRequest { $script:Profiles } -ParameterFilter { $RelativeUri -eq 'security/secureScoreControlProfiles' }
+ Mock -ModuleName Maester Invoke-MtGraphRequest { $script:Recommendations } -ParameterFilter { $RelativeUri -like 'directory/recommendations*' }
+ }
+
+ AfterEach {
+ # Result text must not contain backtick-wrapped code spans (repo result-text lint).
+ if ($null -ne $script:TestResult) {
+ $script:TestResult | Should -Not -Match '`[^`]+`'
+ }
+ }
+
+ Context 'Instance source' {
+ It 'returns one instance per scored control, not per catalog profile' {
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ $instances.Count | Should -Be 3
+ $instances.Id | Should -Not -Contain 'mda_okta_unscored'
+ ($instances | Where-Object Id -EQ 'mdo_safelinks').Title | Should -Be 'Title of mdo_safelinks.'
+ }
+
+ It 'reads only the latest snapshot, without paging through the history' {
+ $null = @(Get-MtSecureScoreControlInstance)
+
+ Should -Invoke Invoke-MtGraphRequest -ModuleName Maester -Exactly -Times 1 -ParameterFilter {
+ $RelativeUri -eq 'security/secureScores' -and $DisablePaging -and $QueryParameters['$top'] -eq 1
+ }
+ }
+
+ It 'sets the severity from the maximum points' {
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ ($instances | Where-Object Id -EQ 'AdminMFAV2').Severity | Should -Be 'High'
+ ($instances | Where-Object Id -EQ 'mdo_safelinks').Severity | Should -Be 'High'
+ ($instances | Where-Object Id -EQ 'exo_mailboxaudit').Severity | Should -Be 'Low'
+ }
+
+ It 'tags each instance with the control service and category' {
+ $instance = @(Get-MtSecureScoreControlInstance) | Where-Object Id -EQ 'AdminMFAV2'
+
+ $instance.Tag | Should -Contain 'AzureAD'
+ $instance.Tag | Should -Contain 'Apps'
+ }
+
+ It 'marks a control that is also an Entra recommendation, matching the name without regard to case' {
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ ($instances | Where-Object Id -EQ 'AdminMFAV2').Data.InMt1024 | Should -BeTrue
+ ($instances | Where-Object Id -EQ 'exo_mailboxaudit').Data.InMt1024 | Should -BeFalse
+ }
+
+ It 'does not mark an AzureAD control that is not an Entra recommendation' {
+ $script:Snapshot.value[0].controlScores = @(New-ControlScore -Name 'AATP_AccountWithLeakedCredentials' -Score 5)
+ $script:Profiles = @(New-ControlProfile -Id 'AATP_AccountWithLeakedCredentials' -Service 'AzureAD')
+
+ $instance = @(Get-MtSecureScoreControlInstance)[0]
+
+ $instance.Data.InMt1024 | Should -BeFalse
+ }
+
+ It 'still returns instances when the Entra recommendations cannot be read' {
+ Mock -ModuleName Maester Invoke-MtGraphRequest { throw 'Forbidden' } -ParameterFilter { $RelativeUri -like 'directory/recommendations*' }
+
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ $instances.Count | Should -Be 3
+ $instances.Data.InMt1024 | Should -Not -Contain $true
+ }
+
+ It 'skips a scored control that has no profile' {
+ $script:Profiles = @($script:Profiles | Where-Object id -NE 'exo_mailboxaudit')
+
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ $instances.Id | Should -Not -Contain 'exo_mailboxaudit'
+ $instances.Count | Should -Be 2
+ }
+
+ It 'skips a deprecated control' {
+ $script:Profiles = @($script:Profiles | Where-Object id -NE 'exo_mailboxaudit') + @(New-ControlProfile -Id 'exo_mailboxaudit' -MaxScore 3 -Deprecated $true)
+
+ @(Get-MtSecureScoreControlInstance).Id | Should -Not -Contain 'exo_mailboxaudit'
+ }
+
+ It 'returns no instances when the tenant has no snapshot yet' {
+ $script:Snapshot = [pscustomobject]@{ value = @() }
+
+ @(Get-MtSecureScoreControlInstance).Count | Should -Be 0
+ }
+
+ It 'skips the family as NotAuthorized on a 403 from Graph' {
+ Mock -ModuleName Maester Invoke-MtGraphRequest { throw '403 Forbidden: Authorization_RequestDenied' } -ParameterFilter { $RelativeUri -eq 'security/secureScores' }
+
+ @(Get-MtSecureScoreControlInstance).Count | Should -Be 0
+ $script:SkippedBecause | Should -Be 'NotAuthorized'
+ }
+
+ It 'lets an unexpected failure throw so the engine records it as Error' {
+ Mock -ModuleName Maester Invoke-MtGraphRequest { throw 'Service unavailable' } -ParameterFilter { $RelativeUri -eq 'security/secureScores' }
+
+ { Get-MtSecureScoreControlInstance } | Should -Throw '*Service unavailable*'
+ }
+ }
+
+ Context 'Severity' {
+ It 'maps points to ' -ForEach @(
+ @{ MaxScore = 10; Expected = 'High' }
+ @{ MaxScore = 8; Expected = 'High' }
+ @{ MaxScore = 7; Expected = 'Medium' }
+ @{ MaxScore = 4; Expected = 'Medium' }
+ @{ MaxScore = 3; Expected = 'Low' }
+ @{ MaxScore = 1; Expected = 'Low' }
+ ) {
+ Get-MtSecureScoreControlSeverity -MaxScore $MaxScore | Should -Be $Expected
+ }
+ }
+
+ Context 'HTML conversion' {
+ It 'turns links, list items and line breaks into markdown and drops other tags' {
+ $html = 'Turn it on.
Then check it.
'
+
+ $md = ConvertFrom-MtSecureScoreHtml -Html $html
+
+ $md | Should -Match '\[check it\]\(https://contoso.com/x\)'
+ $md | Should -Match '(?m)^- One$'
+ $md | Should -Match '(?m)^- Two$'
+ $md | Should -Not -Match '<[^>]+>'
+ $md | Should -Not -Match ' '
+ }
+
+ It 'returns an empty string for empty input' {
+ ConvertFrom-MtSecureScoreHtml -Html '' | Should -Be ''
+ ConvertFrom-MtSecureScoreHtml -Html $null | Should -Be ''
+ }
+ }
+
+ Context 'Test' {
+ BeforeEach {
+ function New-Instance {
+ param([double] $Score, [double] $MaxScore, [object[]] $StateUpdates = @(), [bool] $InMt1024 = $false)
+ [pscustomobject]@{
+ Id = 'ctrl'
+ Severity = 'Medium'
+ Data = [pscustomobject]@{
+ ControlScore = (New-ControlScore -Name 'ctrl' -Score $Score)
+ Profile = (New-ControlProfile -Id 'ctrl' -MaxScore $MaxScore -StateUpdates $StateUpdates)
+ InMt1024 = $InMt1024
+ }
+ }
+ }
+ }
+
+ It 'passes when the control has all of its points' {
+ Test-MtSecureScoreControl -Instance (New-Instance -Score 9 -MaxScore 9) | Should -BeTrue
+ $script:TestResult | Should -Match '9 of 9 points'
+ $script:TestResult | Should -Not -Match 'Open this improvement action'
+ $script:Severity | Should -Be 'Medium'
+ }
+
+ It 'fails with the points earned and a link when the control has fewer points' {
+ Test-MtSecureScoreControl -Instance (New-Instance -Score 0.15 -MaxScore 10) | Should -BeFalse
+ $script:TestResult | Should -Match '0.15 of 10 points'
+ $script:TestResult | Should -Match 'Open this improvement action\]\(https://security.microsoft.com/ctrl\)'
+ }
+
+ It 'skips a control marked and reports who set it and their comment' -ForEach @(
+ @{ State = 'Ignored'; Label = 'risk accepted' }
+ @{ State = 'ThirdParty'; Label = 'resolved through third party' }
+ @{ State = 'AlternateMitigation'; Label = 'resolved through alternate mitigation' }
+ @{ State = 'Reviewed'; Label = 'reviewed' }
+ ) {
+ $update = [pscustomobject]@{ state = $State; updatedBy = 'admin@contoso.com'; comment = 'Handled elsewhere'; updatedDateTime = '2026-10-01T00:00:00Z' }
+
+ Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeNullOrEmpty
+ $script:SkippedBecause | Should -Be 'Custom'
+ $script:SkippedCustomReason | Should -Match $Label
+ $script:SkippedCustomReason | Should -Match 'admin@contoso.com'
+ $script:SkippedCustomReason | Should -Match 'Handled elsewhere'
+ }
+
+ It 'does not skip a Planned control, since the work is not done yet' {
+ $update = [pscustomobject]@{ state = 'Planned'; updatedBy = 'admin@contoso.com'; comment = $null; updatedDateTime = '2026-10-01T00:00:00Z' }
+
+ Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeFalse
+ $script:SkippedBecause | Should -BeNullOrEmpty
+ }
+
+ It 'does not skip a control left in the Default state' {
+ $update = [pscustomobject]@{ state = 'Default'; updatedBy = $null; comment = $null; updatedDateTime = $null }
+
+ Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeFalse
+ $script:SkippedBecause | Should -BeNullOrEmpty
+ }
+
+ It 'uses the latest state when the control was set back to Default after being ignored' {
+ $updates = @(
+ [pscustomobject]@{ state = 'Ignored'; updatedBy = 'admin@contoso.com'; comment = $null; updatedDateTime = '2026-09-01T00:00:00Z' },
+ [pscustomobject]@{ state = 'Default'; updatedBy = 'admin@contoso.com'; comment = $null; updatedDateTime = '2026-10-01T00:00:00Z' }
+ )
+
+ Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates $updates) | Should -BeFalse
+ $script:SkippedBecause | Should -BeNullOrEmpty
+ }
+
+ It 'notes the overlap with MT.1024 only for controls that are Entra recommendations' {
+ $null = Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -InMt1024 $true)
+ $script:Description | Should -Match 'MT.1024'
+
+ $null = Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -InMt1024 $false)
+ $script:Description | Should -Not -Match 'MT.1024'
+ }
+ }
+}
diff --git a/tests/maester/defender/Test.MT.1264.md b/tests/maester/defender/Test.MT.1264.md
new file mode 100644
index 0000000000..b974a11c76
--- /dev/null
+++ b/tests/maester/defender/Test.MT.1264.md
@@ -0,0 +1,24 @@
+Microsoft Secure Score improvement actions should be completed.
+
+Microsoft Secure Score measures a tenant's security posture as points earned across a list of recommended improvement actions, such as requiring multifactor authentication for administrators or turning on Safe Links. Maester reads the tenant's latest Secure Score and creates one result per improvement action the tenant is scored on (MT.1264.<control name>). Improvement actions that are not part of the tenant's score are not reported.
+
+These results are not native Maester checks. The improvement actions, their points and the status details come from Microsoft Secure Score. A change made in the tenant usually takes 24 to 48 hours to show in Secure Score, and some Microsoft Teams and Microsoft Entra improvement actions refresh less often.
+
+An improvement action passes when it has all of its points and fails when it has fewer, showing the points earned. The severity of each result comes from the action's maximum points: 8 or more is High, 4 to 7 is Medium, and below 4 is Low. Improvement actions that an administrator has set to **Risk accepted**, **Resolved through third party** or **Resolved through alternate mitigation** in the Microsoft Defender portal are skipped, with the status, who set it and their note, so decisions already made in the portal are respected. Improvement actions set to **Planned** are still checked, since the work is not done yet.
+
+Some improvement actions, such as multifactor authentication for administrators, are also Entra recommendations reported by MT.1024. Maester matches them by name against the tenant's Entra recommendations, and those results note the overlap.
+
+The check needs the Microsoft Graph permission `SecurityEvents.Read.All`, which Maester does not request by default. Without it the check is skipped. Connect with `Connect-Maester -IncludePreview`, or grant the permission to the app registration that runs Maester.
+
+#### Remediation action
+
+Open each failed improvement action in the [Microsoft Secure Score](https://security.microsoft.com/securescore) page of the Microsoft Defender portal and follow its implementation steps. If an improvement action does not apply to your tenant, or is already covered by another product, set its status to **Risk accepted**, **Resolved through third party** or **Resolved through alternate mitigation** in the Defender portal; Maester then skips it on the next run.
+
+#### Related links
+
+- [Microsoft Secure Score](https://learn.microsoft.com/defender-xdr/microsoft-secure-score)
+- [Assess your security posture with Microsoft Secure Score](https://learn.microsoft.com/defender-xdr/microsoft-secure-score-improvement-actions)
+- [Microsoft Secure Score - Microsoft Defender portal](https://security.microsoft.com/securescore)
+
+
+%TestResult%
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
new file mode 100644
index 0000000000..0dabceea83
--- /dev/null
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -0,0 +1,208 @@
+function Get-MtSecureScoreControlInstance {
+ <#
+ .SYNOPSIS
+ Returns one MT.1264 instance per Microsoft Secure Score control the tenant is scored on.
+
+ .DESCRIPTION
+ Instance source of the MT.1264 family. The instances come from controlScores in the latest Secure
+ Score snapshot, not from the full secureScoreControlProfiles catalog: the catalog lists every control
+ Microsoft has (including ones for products the tenant does not use), while the snapshot lists only the
+ controls the tenant is actually scored on. Each control is joined to its profile for the title, the
+ maximum points and the remediation. The suffix is the control name (MT.1264.) and the
+ severity comes from the control's maximum points.
+ #>
+ [CmdletBinding()]
+ [OutputType([pscustomobject])]
+ param()
+
+ try {
+ # Only the latest daily snapshot. Without -DisablePaging the helper would follow nextLink through
+ # up to 90 days of history.
+ $snapshotResponse = Invoke-MtGraphRequest -RelativeUri 'security/secureScores' -QueryParameters @{ '$top' = 1 } -DisablePaging
+ $snapshot = @($snapshotResponse.value) | Select-Object -First 1
+ $profiles = @(Invoke-MtGraphRequest -RelativeUri 'security/secureScoreControlProfiles')
+ } catch {
+ if ($_.Exception.Message -match '(?i)403|forbidden|authorization') {
+ Add-MtTestResultDetail -SkippedBecause NotAuthorized
+ return
+ }
+ throw
+ }
+
+ # No snapshot yet (for example a brand new tenant): no instances, so the engine skips the family.
+ if ($null -eq $snapshot) { return }
+
+ $profileLookup = @{}
+ foreach ($controlProfile in $profiles) { $profileLookup[[string]$controlProfile.id] = $controlProfile }
+
+ # Entra recommendations MT.1024 already reports. Some Secure Score controls are the same recommendation
+ # under the same name (AdminMFAV2 and adminMFAV2), so those results say so. Matched by name, not by the
+ # control's service: not every AzureAD control is an Entra recommendation. Same request as MT.1024, so
+ # it comes from the Graph cache when MT.1024 has run. If it fails, the results just carry no note.
+ $entraRecommendationTypes = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
+ try {
+ $recommendations = Invoke-MtGraphRequest -ApiVersion beta -RelativeUri 'directory/recommendations?$expand=impactedResources' -OutputType Hashtable
+ foreach ($recommendation in @($recommendations.value)) {
+ if ($recommendation -and $recommendation.recommendationType) { [void]$entraRecommendationTypes.Add([string]$recommendation.recommendationType) }
+ }
+ } catch {
+ Write-Verbose "MT.1264: could not read Entra recommendations, so no result notes the overlap with MT.1024. $($_.Exception.Message)"
+ }
+
+ foreach ($controlScore in @($snapshot.controlScores)) {
+ $controlName = [string]$controlScore.controlName
+ $controlProfile = $profileLookup[$controlName]
+ # Without the profile there is no maximum to compare the score against.
+ if ($null -eq $controlProfile -or $controlProfile.deprecated) { continue }
+
+ [pscustomobject]@{
+ Id = $controlName
+ Title = "$($controlProfile.title)."
+ Severity = Get-MtSecureScoreControlSeverity -MaxScore ([double]$controlProfile.maxScore)
+ # The service (MDO, AzureAD, EXO...) and category (Apps, Identity...) as tags, so -Tag can pick
+ # out one product's actions. The engine does not take a Product per instance.
+ Tag = @(@($controlProfile.service, $controlProfile.controlCategory) | Where-Object { $_ } | Select-Object -Unique)
+ Data = [pscustomobject]@{
+ ControlScore = $controlScore
+ Profile = $controlProfile
+ InMt1024 = $entraRecommendationTypes.Contains($controlName)
+ }
+ }
+ }
+}
+
+function Get-MtSecureScoreControlSeverity {
+ <#
+ .SYNOPSIS
+ Maps a Secure Score control's maximum points to a Maester severity.
+
+ .DESCRIPTION
+ 8 or more points is High, 4 to 7 is Medium, below 4 is Low. Based on points only: the control rank is
+ not used because some controls return rank 0, which does not mean top-ranked.
+ #>
+ [CmdletBinding()]
+ [OutputType([string])]
+ param(
+ [Parameter(Mandatory)] [double] $MaxScore
+ )
+
+ if ($MaxScore -ge 8) { return 'High' }
+ if ($MaxScore -ge 4) { return 'Medium' }
+ return 'Low'
+}
+
+function ConvertFrom-MtSecureScoreHtml {
+ <#
+ .SYNOPSIS
+ Turns the HTML in Secure Score descriptions into plain markdown.
+ #>
+ [CmdletBinding()]
+ [OutputType([string])]
+ param(
+ [Parameter()] [AllowNull()] [AllowEmptyString()] [string] $Html
+ )
+
+ if ([string]::IsNullOrWhiteSpace($Html)) { return '' }
+ $text = $Html -replace "]+href=[`"']([^`"']+)[`"'][^>]*>(.*?)", '[$2]($1)'
+ $text = $text -replace '(?i)]*>', "`n- " -replace '(?i)
', "`n" -replace '(?i)
|', "`n`n"
+ $text = $text -replace '<[^>]+>', ''
+ $text = [System.Net.WebUtility]::HtmlDecode($text)
+ # Collapse runs of blank lines and trim each line.
+ $lines = $text -split "`r?`n" | ForEach-Object { $_.Trim() }
+ return (($lines -join "`n") -replace "`n{3,}", "`n`n").Trim()
+}
+
+function Test-MtSecureScoreControl {
+ <#
+ .SYNOPSIS
+ Checks that a Microsoft Secure Score control has its full points.
+
+ .DESCRIPTION
+ Runs once per Microsoft Secure Score control the tenant is scored on. Passes when the control's score
+ equals its maximum points and fails when it is lower, showing the points attained. Controls an admin has
+ marked in the Defender portal as risk accepted (Ignored), resolved through third party (ThirdParty),
+ resolved through alternate mitigation (AlternateMitigation) or reviewed (Reviewed) are skipped with the
+ reason and who set it, so decisions already made in the portal are respected. Planned controls are
+ still checked, since the work is not done yet.
+
+ .LINK
+ https://maester.dev/docs/tests/MT.1264
+ #>
+ [MaesterTest(
+ Id = 'MT.1264',
+ Title = 'Microsoft Secure Score improvement actions should be completed.',
+ Product = 'defender',
+ Feature = 'secure-score',
+ Area = 'infrastructure',
+ ResourceType = 'Tenant',
+ Severity = 'Medium',
+ UserImpact = 'Low',
+ ImplementationCost = 'Medium',
+ Mitre = 'None',
+ Service = 'Graph',
+ Permission = 'Graph:Scope:SecurityEvents.Read.All',
+ Lifecycle = 'Preview',
+ InstanceSource = 'Get-MtSecureScoreControlInstance',
+ Author = 'Dfrank77'
+ )]
+ [CmdletBinding()]
+ [OutputType([bool])]
+ param(
+ # The Secure Score control to check, supplied by the engine.
+ $Instance
+ )
+
+ $controlScore = $Instance.Data.ControlScore
+ $controlProfile = $Instance.Data.Profile
+ $score = [double]$controlScore.score
+ $maxScore = [double]$controlProfile.maxScore
+ $severity = $Instance.Severity
+
+ #region Build test description markdown
+ $descriptionMd = ConvertFrom-MtSecureScoreHtml -Html ([string]$controlScore.description)
+ $remediation = ConvertFrom-MtSecureScoreHtml -Html ([string]$controlProfile.remediation)
+ if ($remediation) { $descriptionMd += "`n`n#### Remediation action:`n`n$remediation" }
+ $impact = ConvertFrom-MtSecureScoreHtml -Html ([string]$controlProfile.remediationImpact)
+ if ($impact) { $descriptionMd += "`n`n**User impact:** $impact" }
+ if ($Instance.Data.InMt1024) {
+ $descriptionMd += "`n`nThis improvement action is also an Entra recommendation, reported by MT.1024 (Entra recommendations)."
+ }
+ $actionLinkMd = ''
+ if ($controlProfile.actionUrl) {
+ $actionLinkMd = "`n`n➡️ [Open this improvement action]($($controlProfile.actionUrl))"
+ $descriptionMd += $actionLinkMd
+ }
+ #endregion Build test description markdown
+
+ # Decisions made in the Defender portal. The latest dated update is the current state; 'Default'
+ # means nobody has set one. Portal status -> state: Risk accepted -> Ignored, Resolved through third
+ # party -> ThirdParty, Resolved through alternate mitigation -> AlternateMitigation, Planned -> Planned.
+ # Planned and AlternateMitigation are returned by the API but not listed in the Graph docs. Planned
+ # is not skipped: the work is not done yet. Reviewed is a documented state and is skipped as well.
+ $stateUpdates = @($controlProfile.controlStateUpdates | Where-Object { $_ })
+ $latestState = $stateUpdates | Sort-Object -Property @{ Expression = { $_.updatedDateTime -as [datetime] } } -Descending | Select-Object -First 1
+ $stateNames = @{
+ Ignored = 'risk accepted'
+ ThirdParty = 'resolved through third party'
+ AlternateMitigation = 'resolved through alternate mitigation'
+ Reviewed = 'reviewed'
+ }
+ if ($latestState -and $stateNames.ContainsKey([string]$latestState.state)) {
+ $reason = "This improvement action is marked as **$($stateNames[[string]$latestState.state])** ($($latestState.state)) in the Microsoft Defender portal"
+ if ($latestState.updatedBy) { $reason += " by $($latestState.updatedBy)" }
+ $reason += '.'
+ if ($latestState.comment) { $reason += "`n`nComment: $(Get-MtSafeMarkdown ([string]$latestState.comment))" }
+ $reason += "`n`nIf it applies to this tenant, change its status back to **To address** to have Maester check it again.$actionLinkMd"
+ Add-MtTestResultDetail -Description $descriptionMd -Severity $severity -SkippedBecause Custom -SkippedCustomReason $reason
+ return $null
+ }
+
+ $passed = $score -ge $maxScore
+ $resultMd = "**$score of $maxScore points** for this improvement action."
+ $status = ConvertFrom-MtSecureScoreHtml -Html ([string]$controlScore.implementationStatus)
+ if ($status) { $resultMd += "`n`n$status" }
+ if (-not $passed) { $resultMd += $actionLinkMd }
+
+ Add-MtTestResultDetail -Description $descriptionMd -Severity $severity -Result $resultMd
+ return $passed
+}
diff --git a/website/docs/sections/permissions.md b/website/docs/sections/permissions.md
index 22b62f8f5f..eb785cedcf 100644
--- a/website/docs/sections/permissions.md
+++ b/website/docs/sections/permissions.md
@@ -31,9 +31,10 @@ title: Microsoft Graph permissions Maester uses
- **ThreatHunting.Read.All**
- **UserAuthenticationMethod.Read.All**
-To run preview Agent ID tests, also grant these application permissions:
+To run preview tests, also grant these application permissions:
- **AgentIdentity.Read.All**
- **AgentIdentityBlueprint.Read.All**
- **AgentIdentityBlueprintPrincipal.Read.All**
- **Application.Read.All**
+- **SecurityEvents.Read.All**
From df3ead8dff9f42ff9c1089c171b097974562d7b8 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Tue, 3 Nov 2026 08:47:00 -0700
Subject: [PATCH 02/16] chore: regenerate golden fixtures and test builder data
for MT.1264
---
powershell/tests/fixtures/golden/selection.json | 9 ++++++---
website/src/data/test-builder.json | 4 ++++
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json
index 6d76efe2d5..181be49318 100644
--- a/powershell/tests/fixtures/golden/selection.json
+++ b/powershell/tests/fixtures/golden/selection.json
@@ -1915,7 +1915,7 @@
"AD"
]
},
- "SelectedCount": 586,
+ "SelectedCount": 587,
"SelectedFamilies": [
"MT.1024",
"MT.1059",
@@ -2441,6 +2441,7 @@
"MT.1250",
"MT.1251",
"MT.1252",
+ "MT.1264",
"ORCA.100",
"ORCA.101",
"ORCA.102",
@@ -2522,7 +2523,7 @@
"AD"
]
},
- "SelectedCount": 616,
+ "SelectedCount": 617,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
@@ -3080,6 +3081,7 @@
"MT.1250",
"MT.1251",
"MT.1252",
+ "MT.1264",
"ORCA.100",
"ORCA.101",
"ORCA.102",
@@ -3912,7 +3914,7 @@
"AD"
]
},
- "SelectedCount": 572,
+ "SelectedCount": 573,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
@@ -4426,6 +4428,7 @@
"MT.1250",
"MT.1251",
"MT.1252",
+ "MT.1264",
"ORCA.100",
"ORCA.101",
"ORCA.102",
diff --git a/website/src/data/test-builder.json b/website/src/data/test-builder.json
index e3398d1a59..0fb8c59d07 100644
--- a/website/src/data/test-builder.json
+++ b/website/src/data/test-builder.json
@@ -439,6 +439,10 @@
{
"key": "defender-for-identity",
"name": "Defender for Identity"
+ },
+ {
+ "key": "secure-score",
+ "name": "Secure Score"
}
]
},
From b8ce82603ca849894019251d43b64af23f62b959 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Tue, 3 Nov 2026 09:11:26 -0700
Subject: [PATCH 03/16] fix(defender): MT.1264 review fixes -
exposure-management feature, Medium user impact, Reviewed in docs, rename
test helpers
---
powershell/assets/MaesterTaxonomy.psd1 | 1 -
.../Test-MtSecureScoreControl.Tests.ps1 | 46 +++++++++----------
tests/maester/defender/Test.MT.1264.md | 2 +-
tests/maester/defender/Test.MT.1264.ps1 | 4 +-
website/src/data/test-builder.json | 4 --
5 files changed, 26 insertions(+), 31 deletions(-)
diff --git a/powershell/assets/MaesterTaxonomy.psd1 b/powershell/assets/MaesterTaxonomy.psd1
index d899947120..19098a2fed 100644
--- a/powershell/assets/MaesterTaxonomy.psd1
+++ b/powershell/assets/MaesterTaxonomy.psd1
@@ -83,7 +83,6 @@
@{ Key = 'endpoint-antivirus'; Name = 'Endpoint antivirus' }
@{ Key = 'exposure-management'; Name = 'Exposure Management' }
@{ Key = 'defender-for-identity'; Name = 'Defender for Identity' }
- @{ Key = 'secure-score'; Name = 'Secure Score' }
)
}
@{
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index 8a09317124..c885d2cbc4 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -8,7 +8,7 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
Use-MtModuleFunction -Name ConvertFrom-MtSecureScoreHtml
Use-MtModuleFunction -Name Test-MtSecureScoreControl
- function New-ControlProfile {
+ function Get-FakeControlProfile {
param([string] $Id, [double] $MaxScore = 5, [string] $Service = 'MDO', [object[]] $StateUpdates = @(), [bool] $Deprecated = $false)
[pscustomobject]@{
id = $Id
@@ -23,7 +23,7 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
controlStateUpdates = @($StateUpdates)
}
}
- function New-ControlScore {
+ function Get-FakeControlScore {
param([string] $Name, [double] $Score)
[pscustomobject]@{ controlName = $Name; score = $Score; description = "About $Name"; implementationStatus = 'Status text'; controlCategory = 'Apps' }
}
@@ -49,17 +49,17 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
$script:Snapshot = [pscustomobject]@{
value = @([pscustomobject]@{
controlScores = @(
- (New-ControlScore -Name 'mdo_safelinks' -Score 9),
- (New-ControlScore -Name 'AdminMFAV2' -Score 0.15),
- (New-ControlScore -Name 'exo_mailboxaudit' -Score 0)
+ (Get-FakeControlScore -Name 'mdo_safelinks' -Score 9),
+ (Get-FakeControlScore -Name 'AdminMFAV2' -Score 0.15),
+ (Get-FakeControlScore -Name 'exo_mailboxaudit' -Score 0)
)
})
}
$script:Profiles = @(
- (New-ControlProfile -Id 'mdo_safelinks' -MaxScore 9),
- (New-ControlProfile -Id 'AdminMFAV2' -MaxScore 10 -Service 'AzureAD'),
- (New-ControlProfile -Id 'exo_mailboxaudit' -MaxScore 3 -Service 'EXO'),
- (New-ControlProfile -Id 'mda_okta_unscored' -MaxScore 5 -Service 'MDA_Okta')
+ (Get-FakeControlProfile -Id 'mdo_safelinks' -MaxScore 9),
+ (Get-FakeControlProfile -Id 'AdminMFAV2' -MaxScore 10 -Service 'AzureAD'),
+ (Get-FakeControlProfile -Id 'exo_mailboxaudit' -MaxScore 3 -Service 'EXO'),
+ (Get-FakeControlProfile -Id 'mda_okta_unscored' -MaxScore 5 -Service 'MDA_Okta')
)
$script:Recommendations = @{ value = @(@{ recommendationType = 'adminMFAV2' }) }
@@ -115,8 +115,8 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
}
It 'does not mark an AzureAD control that is not an Entra recommendation' {
- $script:Snapshot.value[0].controlScores = @(New-ControlScore -Name 'AATP_AccountWithLeakedCredentials' -Score 5)
- $script:Profiles = @(New-ControlProfile -Id 'AATP_AccountWithLeakedCredentials' -Service 'AzureAD')
+ $script:Snapshot.value[0].controlScores = @(Get-FakeControlScore -Name 'AATP_AccountWithLeakedCredentials' -Score 5)
+ $script:Profiles = @(Get-FakeControlProfile -Id 'AATP_AccountWithLeakedCredentials' -Service 'AzureAD')
$instance = @(Get-MtSecureScoreControlInstance)[0]
@@ -142,7 +142,7 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
}
It 'skips a deprecated control' {
- $script:Profiles = @($script:Profiles | Where-Object id -NE 'exo_mailboxaudit') + @(New-ControlProfile -Id 'exo_mailboxaudit' -MaxScore 3 -Deprecated $true)
+ $script:Profiles = @($script:Profiles | Where-Object id -NE 'exo_mailboxaudit') + @(Get-FakeControlProfile -Id 'exo_mailboxaudit' -MaxScore 3 -Deprecated $true)
@(Get-MtSecureScoreControlInstance).Id | Should -Not -Contain 'exo_mailboxaudit'
}
@@ -201,14 +201,14 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
Context 'Test' {
BeforeEach {
- function New-Instance {
+ function Get-FakeInstance {
param([double] $Score, [double] $MaxScore, [object[]] $StateUpdates = @(), [bool] $InMt1024 = $false)
[pscustomobject]@{
Id = 'ctrl'
Severity = 'Medium'
Data = [pscustomobject]@{
- ControlScore = (New-ControlScore -Name 'ctrl' -Score $Score)
- Profile = (New-ControlProfile -Id 'ctrl' -MaxScore $MaxScore -StateUpdates $StateUpdates)
+ ControlScore = (Get-FakeControlScore -Name 'ctrl' -Score $Score)
+ Profile = (Get-FakeControlProfile -Id 'ctrl' -MaxScore $MaxScore -StateUpdates $StateUpdates)
InMt1024 = $InMt1024
}
}
@@ -216,14 +216,14 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
}
It 'passes when the control has all of its points' {
- Test-MtSecureScoreControl -Instance (New-Instance -Score 9 -MaxScore 9) | Should -BeTrue
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 9 -MaxScore 9) | Should -BeTrue
$script:TestResult | Should -Match '9 of 9 points'
$script:TestResult | Should -Not -Match 'Open this improvement action'
$script:Severity | Should -Be 'Medium'
}
It 'fails with the points earned and a link when the control has fewer points' {
- Test-MtSecureScoreControl -Instance (New-Instance -Score 0.15 -MaxScore 10) | Should -BeFalse
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0.15 -MaxScore 10) | Should -BeFalse
$script:TestResult | Should -Match '0.15 of 10 points'
$script:TestResult | Should -Match 'Open this improvement action\]\(https://security.microsoft.com/ctrl\)'
}
@@ -236,7 +236,7 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
) {
$update = [pscustomobject]@{ state = $State; updatedBy = 'admin@contoso.com'; comment = 'Handled elsewhere'; updatedDateTime = '2026-10-01T00:00:00Z' }
- Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeNullOrEmpty
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeNullOrEmpty
$script:SkippedBecause | Should -Be 'Custom'
$script:SkippedCustomReason | Should -Match $Label
$script:SkippedCustomReason | Should -Match 'admin@contoso.com'
@@ -246,14 +246,14 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
It 'does not skip a Planned control, since the work is not done yet' {
$update = [pscustomobject]@{ state = 'Planned'; updatedBy = 'admin@contoso.com'; comment = $null; updatedDateTime = '2026-10-01T00:00:00Z' }
- Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeFalse
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeFalse
$script:SkippedBecause | Should -BeNullOrEmpty
}
It 'does not skip a control left in the Default state' {
$update = [pscustomobject]@{ state = 'Default'; updatedBy = $null; comment = $null; updatedDateTime = $null }
- Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeFalse
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeFalse
$script:SkippedBecause | Should -BeNullOrEmpty
}
@@ -263,15 +263,15 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
[pscustomobject]@{ state = 'Default'; updatedBy = 'admin@contoso.com'; comment = $null; updatedDateTime = '2026-10-01T00:00:00Z' }
)
- Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -StateUpdates $updates) | Should -BeFalse
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 5 -StateUpdates $updates) | Should -BeFalse
$script:SkippedBecause | Should -BeNullOrEmpty
}
It 'notes the overlap with MT.1024 only for controls that are Entra recommendations' {
- $null = Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -InMt1024 $true)
+ $null = Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 5 -InMt1024 $true)
$script:Description | Should -Match 'MT.1024'
- $null = Test-MtSecureScoreControl -Instance (New-Instance -Score 0 -MaxScore 5 -InMt1024 $false)
+ $null = Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 5 -InMt1024 $false)
$script:Description | Should -Not -Match 'MT.1024'
}
}
diff --git a/tests/maester/defender/Test.MT.1264.md b/tests/maester/defender/Test.MT.1264.md
index b974a11c76..16ac3f8851 100644
--- a/tests/maester/defender/Test.MT.1264.md
+++ b/tests/maester/defender/Test.MT.1264.md
@@ -4,7 +4,7 @@ Microsoft Secure Score measures a tenant's security posture as points earned acr
These results are not native Maester checks. The improvement actions, their points and the status details come from Microsoft Secure Score. A change made in the tenant usually takes 24 to 48 hours to show in Secure Score, and some Microsoft Teams and Microsoft Entra improvement actions refresh less often.
-An improvement action passes when it has all of its points and fails when it has fewer, showing the points earned. The severity of each result comes from the action's maximum points: 8 or more is High, 4 to 7 is Medium, and below 4 is Low. Improvement actions that an administrator has set to **Risk accepted**, **Resolved through third party** or **Resolved through alternate mitigation** in the Microsoft Defender portal are skipped, with the status, who set it and their note, so decisions already made in the portal are respected. Improvement actions set to **Planned** are still checked, since the work is not done yet.
+An improvement action passes when it has all of its points and fails when it has fewer, showing the points earned. The severity of each result comes from the action's maximum points: 8 or more is High, 4 to 7 is Medium, and below 4 is Low. Improvement actions that an administrator has set to **Risk accepted**, **Resolved through third party** or **Resolved through alternate mitigation** in the Microsoft Defender portal, or that carry the older **Reviewed** state, are skipped, with the status, who set it and their note, so decisions already made in the portal are respected. Improvement actions set to **Planned** are still checked, since the work is not done yet.
Some improvement actions, such as multifactor authentication for administrators, are also Entra recommendations reported by MT.1024. Maester matches them by name against the tenant's Entra recommendations, and those results note the overlap.
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index 0dabceea83..9efaa02836 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -132,11 +132,11 @@ function Test-MtSecureScoreControl {
Id = 'MT.1264',
Title = 'Microsoft Secure Score improvement actions should be completed.',
Product = 'defender',
- Feature = 'secure-score',
+ Feature = 'exposure-management',
Area = 'infrastructure',
ResourceType = 'Tenant',
Severity = 'Medium',
- UserImpact = 'Low',
+ UserImpact = 'Medium',
ImplementationCost = 'Medium',
Mitre = 'None',
Service = 'Graph',
diff --git a/website/src/data/test-builder.json b/website/src/data/test-builder.json
index 0fb8c59d07..e3398d1a59 100644
--- a/website/src/data/test-builder.json
+++ b/website/src/data/test-builder.json
@@ -439,10 +439,6 @@
{
"key": "defender-for-identity",
"name": "Defender for Identity"
- },
- {
- "key": "secure-score",
- "name": "Secure Score"
}
]
},
From 88faee6e48aedc14a0a809409d31a8347a822ee5 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Tue, 3 Nov 2026 09:16:41 -0700
Subject: [PATCH 04/16] fix(defender): MT.1264 report scored controls with no
profile instead of dropping them
---
.../Test-MtSecureScoreControl.Tests.ps1 | 8 +++++---
tests/maester/defender/Test.MT.1264.ps1 | 18 ++++++++++++++++--
2 files changed, 21 insertions(+), 5 deletions(-)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index c885d2cbc4..af626067ec 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -132,13 +132,15 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
$instances.Data.InMt1024 | Should -Not -Contain $true
}
- It 'skips a scored control that has no profile' {
+ It 'keeps a scored control that has no profile so the test reports it as an error' {
$script:Profiles = @($script:Profiles | Where-Object id -NE 'exo_mailboxaudit')
$instances = @(Get-MtSecureScoreControlInstance)
- $instances.Id | Should -Not -Contain 'exo_mailboxaudit'
- $instances.Count | Should -Be 2
+ $instances.Count | Should -Be 3
+ $missing = $instances | Where-Object Id -EQ 'exo_mailboxaudit'
+ $missing.Data.Profile | Should -BeNullOrEmpty
+ { Test-MtSecureScoreControl -Instance $missing } | Should -Throw '*no control profile*'
}
It 'skips a deprecated control' {
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index 9efaa02836..c9f73d95d7 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -52,8 +52,19 @@ function Get-MtSecureScoreControlInstance {
foreach ($controlScore in @($snapshot.controlScores)) {
$controlName = [string]$controlScore.controlName
$controlProfile = $profileLookup[$controlName]
- # Without the profile there is no maximum to compare the score against.
- if ($null -eq $controlProfile -or $controlProfile.deprecated) { continue }
+ if ($controlProfile.deprecated) { continue }
+ # A scored control with no profile has no maximum to compare against. Keep it as an instance so
+ # the test reports it as an error instead of dropping it from the results.
+ if ($null -eq $controlProfile) {
+ [pscustomobject]@{
+ Id = $controlName
+ Title = "$controlName."
+ Severity = 'Medium'
+ Tag = @(@($controlScore.controlCategory) | Where-Object { $_ })
+ Data = [pscustomobject]@{ ControlScore = $controlScore; Profile = $null; InMt1024 = $false }
+ }
+ continue
+ }
[pscustomobject]@{
Id = $controlName
@@ -154,6 +165,9 @@ function Test-MtSecureScoreControl {
$controlScore = $Instance.Data.ControlScore
$controlProfile = $Instance.Data.Profile
+ if ($null -eq $controlProfile) {
+ throw "Secure Score control '$($Instance.Id)' is in the tenant's score but has no control profile, so its maximum points could not be read."
+ }
$score = [double]$controlScore.score
$maxScore = [double]$controlProfile.maxScore
$severity = $Instance.Severity
From 2296a1cd45488850608fce89da0d87adc9635354 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Tue, 3 Nov 2026 09:51:35 -0700
Subject: [PATCH 05/16] fix: remove duplicate preview scope, add
instance-to-skip test for MT.1264
---
powershell/public/connect/Get-MtGraphScope.ps1 | 1 -
.../tests/functions/Test-MtSecureScoreControl.Tests.ps1 | 9 +++++++++
2 files changed, 9 insertions(+), 1 deletion(-)
diff --git a/powershell/public/connect/Get-MtGraphScope.ps1 b/powershell/public/connect/Get-MtGraphScope.ps1
index 75142e66a5..add7f3d41c 100644
--- a/powershell/public/connect/Get-MtGraphScope.ps1
+++ b/powershell/public/connect/Get-MtGraphScope.ps1
@@ -99,7 +99,6 @@
'AgentIdentityBlueprint.Read.All'
'AgentIdentityBlueprintPrincipal.Read.All'
'Application.Read.All'
- 'Application.Read.All'
'SecurityEvents.Read.All'
)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index af626067ec..c259010eef 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -143,6 +143,15 @@ Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
{ Test-MtSecureScoreControl -Instance $missing } | Should -Throw '*no control profile*'
}
+ It 'skips a control whose portal state update reaches the test through instance creation' {
+ $script:Profiles = @(Get-FakeControlProfile -Id 'exo_mailboxaudit' -MaxScore 5 -StateUpdates @([pscustomobject]@{ state = 'Ignored'; updatedBy = 'admin@contoso.com'; comment = 'Handled elsewhere'; updatedDateTime = '2026-10-01T00:00:00Z' }))
+ $script:Snapshot.value[0].controlScores = @(Get-FakeControlScore -Name 'exo_mailboxaudit' -Score 0)
+
+ $instance = @(Get-MtSecureScoreControlInstance) | Where-Object Id -EQ 'exo_mailboxaudit'
+
+ Test-MtSecureScoreControl -Instance $instance | Should -BeNullOrEmpty
+ }
+
It 'skips a deprecated control' {
$script:Profiles = @($script:Profiles | Where-Object id -NE 'exo_mailboxaudit') + @(Get-FakeControlProfile -Id 'exo_mailboxaudit' -MaxScore 3 -Deprecated $true)
From a4925cdc31f747356388abbb2191b55664f1cced Mon Sep 17 00:00:00 2001
From: Merill Fernando
Date: Thu, 5 Nov 2026 06:22:48 +1100
Subject: [PATCH 06/16] Regenerate the golden selection fixture after merging
main
Co-Authored-By: Claude Opus 5.5
---
powershell/tests/fixtures/golden/selection.json | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json
index fdee142834..9214b1ded0 100644
--- a/powershell/tests/fixtures/golden/selection.json
+++ b/powershell/tests/fixtures/golden/selection.json
@@ -1915,7 +1915,7 @@
"AD"
]
},
- "SelectedCount": 587,
+ "SelectedCount": 588,
"SelectedFamilies": [
"MT.1024",
"MT.1059",
@@ -2442,6 +2442,7 @@
"MT.1251",
"MT.1252",
"MT.1260",
+ "MT.1264",
"ORCA.100",
"ORCA.101",
"ORCA.102",
@@ -2523,7 +2524,7 @@
"AD"
]
},
- "SelectedCount": 617,
+ "SelectedCount": 618,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
@@ -3082,6 +3083,7 @@
"MT.1251",
"MT.1252",
"MT.1260",
+ "MT.1264",
"ORCA.100",
"ORCA.101",
"ORCA.102",
@@ -3914,7 +3916,7 @@
"AD"
]
},
- "SelectedCount": 573,
+ "SelectedCount": 574,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
@@ -4429,6 +4431,7 @@
"MT.1251",
"MT.1252",
"MT.1260",
+ "MT.1264",
"ORCA.100",
"ORCA.101",
"ORCA.102",
From d226517bc37319fb8ee7269c67ab55b70e26a6ea Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Thu, 5 Nov 2026 07:24:16 -0700
Subject: [PATCH 07/16] chore: regenerate golden fixture after merging main
---
powershell/tests/fixtures/golden/selection.json | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/powershell/tests/fixtures/golden/selection.json b/powershell/tests/fixtures/golden/selection.json
index e6d48ebb4d..cd0c27b8ac 100644
--- a/powershell/tests/fixtures/golden/selection.json
+++ b/powershell/tests/fixtures/golden/selection.json
@@ -1918,7 +1918,7 @@
"AD"
]
},
- "SelectedCount": 588,
+ "SelectedCount": 589,
"SelectedFamilies": [
"MT.1024",
"MT.1059",
@@ -2528,7 +2528,7 @@
"AD"
]
},
- "SelectedCount": 618,
+ "SelectedCount": 619,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
@@ -3922,7 +3922,7 @@
"AD"
]
},
- "SelectedCount": 574,
+ "SelectedCount": 575,
"SelectedFamilies": [
"MT.1024",
"MT.1033",
From cd17d676c7af54a4c0529527ff439821498d7508 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Thu, 5 Nov 2026 08:06:20 -0700
Subject: [PATCH 08/16] fix: keep preview scopes in alphabetical order
---
powershell/public/connect/Get-MtGraphScope.ps1 | 2 +-
website/docs/sections/permissions.md | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/powershell/public/connect/Get-MtGraphScope.ps1 b/powershell/public/connect/Get-MtGraphScope.ps1
index 2ebbc4c393..e6ba650257 100644
--- a/powershell/public/connect/Get-MtGraphScope.ps1
+++ b/powershell/public/connect/Get-MtGraphScope.ps1
@@ -99,8 +99,8 @@
'AgentIdentityBlueprint.Read.All'
'AgentIdentityBlueprintPrincipal.Read.All'
'Application.Read.All'
- 'SecurityEvents.Read.All'
'IdentityRiskyUser.Read.All'
+ 'SecurityEvents.Read.All'
)
if ($IncludePreview) {
diff --git a/website/docs/sections/permissions.md b/website/docs/sections/permissions.md
index e9a6bc3632..3f550fbad4 100644
--- a/website/docs/sections/permissions.md
+++ b/website/docs/sections/permissions.md
@@ -37,5 +37,5 @@ To run preview tests, also grant these application permissions:
- **AgentIdentityBlueprint.Read.All**
- **AgentIdentityBlueprintPrincipal.Read.All**
- **Application.Read.All**
-- **SecurityEvents.Read.All**
- **IdentityRiskyUser.Read.All**
+- **SecurityEvents.Read.All**
From d9fd1c82e8d38861433361a78357ea44fb3352f1 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Thu, 5 Nov 2026 08:36:09 -0700
Subject: [PATCH 09/16] chore: re-run CI
From 81c5ed15eea7c0d96e07fb419f76f3b7172469d8 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Thu, 5 Nov 2026 09:21:00 -0700
Subject: [PATCH 10/16] chore: re-run CI
From db1d02a7168a82e78b79068e747ee0535881c925 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Thu, 5 Nov 2026 13:20:12 -0700
Subject: [PATCH 11/16] fix(defender): MT.1264 declare supported clouds and add
BOM
---
powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 | 2 +-
tests/maester/defender/Test.MT.1264.md | 2 +-
tests/maester/defender/Test.MT.1264.ps1 | 3 ++-
3 files changed, 4 insertions(+), 3 deletions(-)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index c259010eef..f985e6483d 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -1,4 +1,4 @@
-Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
+Describe 'Microsoft Secure Score improvement actions (MT.1264)' {
BeforeAll {
Import-Module $PSScriptRoot/../../Maester.psd1 -Force
. "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1"
diff --git a/tests/maester/defender/Test.MT.1264.md b/tests/maester/defender/Test.MT.1264.md
index 16ac3f8851..4c8266cdc3 100644
--- a/tests/maester/defender/Test.MT.1264.md
+++ b/tests/maester/defender/Test.MT.1264.md
@@ -12,7 +12,7 @@ The check needs the Microsoft Graph permission `SecurityEvents.Read.All`, which
#### Remediation action
-Open each failed improvement action in the [Microsoft Secure Score](https://security.microsoft.com/securescore) page of the Microsoft Defender portal and follow its implementation steps. If an improvement action does not apply to your tenant, or is already covered by another product, set its status to **Risk accepted**, **Resolved through third party** or **Resolved through alternate mitigation** in the Defender portal; Maester then skips it on the next run.
+Open each failed improvement action in the [Microsoft Secure Score](https://security.microsoft.com/securescore) page of the Microsoft Defender portal and follow its implementation steps. If an improvement action does not apply to your tenant, or is already covered by another product, set its status to **Risk accepted**, **Resolved through third party** or **Resolved through alternate mitigation** in the Defender portal; Maester then skips it on the next run. Improvement actions in the Device category can't be given a status there; Microsoft directs you to the matching Defender Vulnerability Management recommendation instead.
#### Related links
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index c9f73d95d7..9407371508 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -1,4 +1,4 @@
-function Get-MtSecureScoreControlInstance {
+function Get-MtSecureScoreControlInstance {
<#
.SYNOPSIS
Returns one MT.1264 instance per Microsoft Secure Score control the tenant is scored on.
@@ -150,6 +150,7 @@ function Test-MtSecureScoreControl {
UserImpact = 'Medium',
ImplementationCost = 'Medium',
Mitre = 'None',
+ Cloud = ('Commercial', 'GCC', 'GCCHigh', 'DoD'),
Service = 'Graph',
Permission = 'Graph:Scope:SecurityEvents.Read.All',
Lifecycle = 'Preview',
From 6d01652cb6a9e46ab3aaa0b837c65d7264a1ce6c Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Sat, 7 Nov 2026 01:32:13 +0000
Subject: [PATCH 12/16] MT.1264: place each action under its own product
Secure Score names the service behind each action. Map it to the taxonomy
product (Entra, Exchange, Teams, SharePoint, Purview, Microsoft 365) and to
Defender for Identity for Azure ATP, so actions are not all filed under
Defender. Defender services keep the family product and feature.
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01WrYw8FTdwmyZ3ktKSYEJij
---
.../Test-MtSecureScoreControl.Tests.ps1 | 41 +++++++++++++++++++
tests/maester/defender/Test.MT.1264.ps1 | 38 ++++++++++++++++-
2 files changed, 78 insertions(+), 1 deletion(-)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index f985e6483d..15fccc83ee 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -5,6 +5,7 @@
# The native-test functions are not exported; reach them the same way the agent tests do.
Use-MtModuleFunction -Name Get-MtSecureScoreControlInstance
Use-MtModuleFunction -Name Get-MtSecureScoreControlSeverity
+ Use-MtModuleFunction -Name Get-MtSecureScoreControlProduct
Use-MtModuleFunction -Name ConvertFrom-MtSecureScoreHtml
Use-MtModuleFunction -Name Test-MtSecureScoreControl
@@ -107,6 +108,16 @@
$instance.Tag | Should -Contain 'Apps'
}
+ It 'places each instance under the product its service is about' {
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ ($instances | Where-Object Id -EQ 'AdminMFAV2').Product | Should -Be 'entra'
+ ($instances | Where-Object Id -EQ 'exo_mailboxaudit').Product | Should -Be 'exchange'
+ # Defender for Office keeps the family's Defender product and Exposure Management feature.
+ ($instances | Where-Object Id -EQ 'mdo_safelinks').Product | Should -BeNullOrEmpty
+ ($instances | Where-Object Id -EQ 'mdo_safelinks').Feature | Should -BeNullOrEmpty
+ }
+
It 'marks a control that is also an Entra recommendation, matching the name without regard to case' {
$instances = @(Get-MtSecureScoreControlInstance)
@@ -191,6 +202,36 @@
}
}
+ Context 'Product' {
+ It 'maps the service to ' -ForEach @(
+ @{ Service = 'AzureAD'; Product = 'entra'; Feature = $null }
+ @{ Service = 'EXO'; Product = 'exchange'; Feature = $null }
+ @{ Service = 'MS Teams'; Product = 'teams'; Feature = $null }
+ @{ Service = 'SPO'; Product = 'sharepoint'; Feature = $null }
+ @{ Service = 'MIP'; Product = 'purview'; Feature = $null }
+ @{ Service = 'Admincenter'; Product = 'microsoft-365'; Feature = $null }
+ @{ Service = 'Azure ATP'; Product = 'defender'; Feature = 'defender-for-identity' }
+ @{ Service = 'MDO'; Product = $null; Feature = $null }
+ @{ Service = 'MDA_Okta'; Product = $null; Feature = $null }
+ @{ Service = ''; Product = $null; Feature = $null }
+ ) {
+ $placement = Get-MtSecureScoreControlProduct -Service $Service
+ $placement.Product | Should -Be $Product
+ $placement.Feature | Should -Be $Feature
+ }
+
+ It 'uses only product and feature keys that are in the Maester taxonomy' {
+ $taxonomy = Import-PowerShellDataFile "$PSScriptRoot/../../assets/MaesterTaxonomy.psd1"
+ foreach ($service in 'AzureAD', 'EXO', 'MS Teams', 'SPO', 'MIP', 'FORMS', 'SWAY', 'Admincenter', 'Azure ATP') {
+ $placement = Get-MtSecureScoreControlProduct -Service $service
+ ($taxonomy | ConvertTo-Json -Depth 10) | Should -Match ([regex]::Escape("`"$($placement.Product)`""))
+ if ($placement.Feature) {
+ ($taxonomy | ConvertTo-Json -Depth 10) | Should -Match ([regex]::Escape("`"$($placement.Feature)`""))
+ }
+ }
+ }
+ }
+
Context 'HTML conversion' {
It 'turns links, list items and line breaks into markdown and drops other tags' {
$html = 'Turn it on.
Then check it.
'
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index 9407371508..8805edb776 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -66,12 +66,16 @@
continue
}
+ $placement = Get-MtSecureScoreControlProduct -Service ([string]$controlProfile.service)
[pscustomobject]@{
Id = $controlName
Title = "$($controlProfile.title)."
Severity = Get-MtSecureScoreControlSeverity -MaxScore ([double]$controlProfile.maxScore)
+ # Each action sits under the product it is about (Entra, Exchange, Teams...), not the family's Defender.
+ Product = $placement.Product
+ Feature = $placement.Feature
# The service (MDO, AzureAD, EXO...) and category (Apps, Identity...) as tags, so -Tag can pick
- # out one product's actions. The engine does not take a Product per instance.
+ # out one service's actions.
Tag = @(@($controlProfile.service, $controlProfile.controlCategory) | Where-Object { $_ } | Select-Object -Unique)
Data = [pscustomobject]@{
ControlScore = $controlScore
@@ -82,6 +86,38 @@
}
}
+function Get-MtSecureScoreControlProduct {
+ <#
+ .SYNOPSIS
+ Maps a Secure Score control's service to the Maester product (and feature, where one fits) it is about.
+
+ .DESCRIPTION
+ Secure Score names the service that owns each improvement action (AzureAD, EXO, MS Teams...). The engine
+ places a family instance under the Product and Feature it sets, checked against the taxonomy. A service
+ with no clear product returns nothing, so the instance keeps the family's Defender product and feature.
+ Defender for Cloud Apps connectors (MDA_*) stay under Defender.
+ #>
+ [CmdletBinding()]
+ [OutputType([hashtable])]
+ param(
+ [Parameter()] [AllowEmptyString()] [string] $Service
+ )
+
+ $map = @{
+ 'AzureAD' = @{ Product = 'entra' }
+ 'EXO' = @{ Product = 'exchange' }
+ 'MS Teams' = @{ Product = 'teams' }
+ 'SPO' = @{ Product = 'sharepoint' }
+ 'MIP' = @{ Product = 'purview' }
+ 'FORMS' = @{ Product = 'microsoft-365' }
+ 'SWAY' = @{ Product = 'microsoft-365' }
+ 'Admincenter' = @{ Product = 'microsoft-365' }
+ 'Azure ATP' = @{ Product = 'defender'; Feature = 'defender-for-identity' }
+ }
+ if ($Service -and $map.ContainsKey($Service)) { return $map[$Service] }
+ return @{ Product = $null; Feature = $null }
+}
+
function Get-MtSecureScoreControlSeverity {
<#
.SYNOPSIS
From 7a8cc3528bfa1fcbbc801f787f4a72d044fb3fbf Mon Sep 17 00:00:00 2001
From: Merill Fernando
Date: Sun, 8 Nov 2026 12:40:30 +1100
Subject: [PATCH 13/16] fix(defender): MT.1264 turns control names into valid
instance IDs
A Secure Score control name with a space or any character outside A-Z, a-z, 0-9, '.', '_' and '-' failed
the engine's instance-ID check, which errors the whole family with InvalidInstanceId. The instance source
now passes each name through ConvertTo-MtSecureScoreInstanceId: invalid characters become '-', leading
non-alphanumerics are dropped, the ID is cut to 128 characters, and a collision gets -2, -3... A name with
no letter or digit is skipped. Valid names, which are all of today's, are unchanged.
Co-Authored-By: Claude Opus 5.5
Entire-Checkpoint: 01M6WD0WBM1RAMWVG0ZZDMXSXP
---
.../Test-MtSecureScoreControl.Tests.ps1 | 57 +++++++++++++++++++
tests/maester/defender/Test.MT.1264.ps1 | 50 ++++++++++++++--
2 files changed, 102 insertions(+), 5 deletions(-)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index 15fccc83ee..9bb3b8e927 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -6,6 +6,7 @@
Use-MtModuleFunction -Name Get-MtSecureScoreControlInstance
Use-MtModuleFunction -Name Get-MtSecureScoreControlSeverity
Use-MtModuleFunction -Name Get-MtSecureScoreControlProduct
+ Use-MtModuleFunction -Name ConvertTo-MtSecureScoreInstanceId
Use-MtModuleFunction -Name ConvertFrom-MtSecureScoreHtml
Use-MtModuleFunction -Name Test-MtSecureScoreControl
@@ -143,6 +144,62 @@
$instances.Data.InMt1024 | Should -Not -Contain $true
}
+ It 'turns a control name that is not a valid instance ID into one, so the family still runs' {
+ $script:Snapshot.value[0].controlScores = @(
+ (Get-FakeControlScore -Name 'mdo_safelinks' -Score 9),
+ (Get-FakeControlScore -Name '_Turn on audit (EXO)' -Score 0)
+ )
+ $script:Profiles = @((Get-FakeControlProfile -Id 'mdo_safelinks' -MaxScore 9), (Get-FakeControlProfile -Id '_Turn on audit (EXO)' -MaxScore 3))
+
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ $instances.Id | Should -Be @('mdo_safelinks', 'Turn-on-audit--EXO-')
+ foreach ($id in $instances.Id) { $id | Should -Match '^[A-Za-z0-9][A-Za-z0-9._-]{0,127}\z' }
+ ($instances | Where-Object Id -EQ 'Turn-on-audit--EXO-').Title | Should -Be 'Title of _Turn on audit (EXO).'
+ }
+
+ It 'keeps instance IDs unique when two control names map to the same ID' {
+ $script:Snapshot.value[0].controlScores = @((Get-FakeControlScore -Name 'a b' -Score 0), (Get-FakeControlScore -Name 'a-b' -Score 0), (Get-FakeControlScore -Name 'A_B' -Score 0))
+ $script:Profiles = @((Get-FakeControlProfile -Id 'a b'), (Get-FakeControlProfile -Id 'a-b'), (Get-FakeControlProfile -Id 'A_B'))
+
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ $instances.Id | Should -Be @('a-b', 'a-b-2', 'A_B')
+ }
+
+ It 'cuts a long control name to the 128 characters an instance ID allows' {
+ $long = 'x' * 200
+ $script:Snapshot.value[0].controlScores = @((Get-FakeControlScore -Name $long -Score 0), (Get-FakeControlScore -Name ($long + 'y') -Score 0))
+ $script:Profiles = @((Get-FakeControlProfile -Id $long), (Get-FakeControlProfile -Id ($long + 'y')))
+
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ $instances[0].Id.Length | Should -Be 128
+ $instances[1].Id | Should -Be (('x' * 126) + '-2')
+ }
+
+ It 'skips a control whose name has no letter or digit' {
+ $script:Snapshot.value[0].controlScores = @((Get-FakeControlScore -Name 'mdo_safelinks' -Score 9), (Get-FakeControlScore -Name ' -- ' -Score 0))
+
+ $instances = @(Get-MtSecureScoreControlInstance)
+
+ $instances.Id | Should -Be @('mdo_safelinks')
+ }
+
+ It 'runs the whole family when a control name is not a valid instance ID' {
+ $script:Snapshot.value[0].controlScores = @((Get-FakeControlScore -Name 'mdo_safelinks' -Score 9), (Get-FakeControlScore -Name 'Turn on audit' -Score 0))
+ $script:Profiles = @((Get-FakeControlProfile -Id 'mdo_safelinks' -MaxScore 9), (Get-FakeControlProfile -Id 'Turn on audit' -MaxScore 3))
+
+ # Offline run: Graph forced connected through the run config, licences Unknown (never a skip).
+ Mock -ModuleName Maester Get-MtShippedMaesterConfig { [pscustomobject]@{} }
+ $runConfig = [pscustomobject]@{ Environment = [pscustomobject]@{ Services = [pscustomobject]@{ Graph = $true } } }
+ Push-Location $TestDrive
+ try { $rows = @(Invoke-MtTest -Id 'MT.1264' -Config $runConfig 3>$null 6>$null) } finally { Pop-Location }
+
+ $rows.ReasonCode | Should -Not -Contain 'InvalidInstanceId'
+ $rows.Id | Should -Contain 'MT.1264.Turn-on-audit'
+ }
+
It 'keeps a scored control that has no profile so the test reports it as an error' {
$script:Profiles = @($script:Profiles | Where-Object id -NE 'exo_mailboxaudit')
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index 8805edb776..c38585978e 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -8,8 +8,9 @@
Score snapshot, not from the full secureScoreControlProfiles catalog: the catalog lists every control
Microsoft has (including ones for products the tenant does not use), while the snapshot lists only the
controls the tenant is actually scored on. Each control is joined to its profile for the title, the
- maximum points and the remediation. The suffix is the control name (MT.1264.) and the
- severity comes from the control's maximum points.
+ maximum points and the remediation. The suffix is the control name (MT.1264.), made a
+ valid instance ID by ConvertTo-MtSecureScoreInstanceId when it is not one, and the severity comes from the
+ control's maximum points.
#>
[CmdletBinding()]
[OutputType([pscustomobject])]
@@ -49,15 +50,23 @@
Write-Verbose "MT.1264: could not read Entra recommendations, so no result notes the overlap with MT.1024. $($_.Exception.Message)"
}
+ # Instance IDs must match ^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$ and be unique, or the engine errors the whole
+ # family. Control names are Microsoft's, so one with a space or another character would break every result.
+ $usedIds = [System.Collections.Generic.HashSet[string]]::new([System.StringComparer]::OrdinalIgnoreCase)
foreach ($controlScore in @($snapshot.controlScores)) {
$controlName = [string]$controlScore.controlName
$controlProfile = $profileLookup[$controlName]
if ($controlProfile.deprecated) { continue }
+ $instanceId = ConvertTo-MtSecureScoreInstanceId -ControlName $controlName -UsedId $usedIds
+ if (-not $instanceId) {
+ Write-Verbose "MT.1264: skipped a Secure Score control with no usable name ('$controlName')."
+ continue
+ }
# A scored control with no profile has no maximum to compare against. Keep it as an instance so
# the test reports it as an error instead of dropping it from the results.
if ($null -eq $controlProfile) {
[pscustomobject]@{
- Id = $controlName
+ Id = $instanceId
Title = "$controlName."
Severity = 'Medium'
Tag = @(@($controlScore.controlCategory) | Where-Object { $_ })
@@ -68,7 +77,7 @@
$placement = Get-MtSecureScoreControlProduct -Service ([string]$controlProfile.service)
[pscustomobject]@{
- Id = $controlName
+ Id = $instanceId
Title = "$($controlProfile.title)."
Severity = Get-MtSecureScoreControlSeverity -MaxScore ([double]$controlProfile.maxScore)
# Each action sits under the product it is about (Entra, Exchange, Teams...), not the family's Defender.
@@ -86,6 +95,37 @@
}
}
+function ConvertTo-MtSecureScoreInstanceId {
+ <#
+ .SYNOPSIS
+ Turns a Secure Score control name into an instance ID the engine accepts, unique within the family.
+
+ .DESCRIPTION
+ Most control names (mdo_safelinks, AdminMFAV2) are valid IDs and are returned unchanged. A character outside
+ A-Z, a-z, 0-9, '.', '_' and '-' becomes '-', leading characters that are not a letter or digit are dropped and
+ the result is cut to 128 characters. A name that collides with one already used gets -2, -3... Returns
+ nothing for a name with no letter or digit. Adds the returned ID to UsedId.
+ #>
+ [CmdletBinding()]
+ [OutputType([string])]
+ param(
+ [Parameter(Mandatory)] [AllowEmptyString()] [string] $ControlName,
+ [Parameter(Mandatory)] [AllowEmptyCollection()] [System.Collections.Generic.HashSet[string]] $UsedId
+ )
+
+ $id = ($ControlName -replace '[^A-Za-z0-9._-]', '-') -replace '^[^A-Za-z0-9]+', ''
+ if (-not $id) { return }
+ if ($id.Length -gt 128) { $id = $id.Substring(0, 128) }
+ $candidate = $id
+ $n = 1
+ while (-not $UsedId.Add($candidate)) {
+ $n++
+ $suffix = "-$n"
+ $candidate = $id.Substring(0, [Math]::Min($id.Length, 128 - $suffix.Length)) + $suffix
+ }
+ $candidate
+}
+
function Get-MtSecureScoreControlProduct {
<#
.SYNOPSIS
@@ -203,7 +243,7 @@ function Test-MtSecureScoreControl {
$controlScore = $Instance.Data.ControlScore
$controlProfile = $Instance.Data.Profile
if ($null -eq $controlProfile) {
- throw "Secure Score control '$($Instance.Id)' is in the tenant's score but has no control profile, so its maximum points could not be read."
+ throw "Secure Score control '$($controlScore.controlName)' is in the tenant's score but has no control profile, so its maximum points could not be read."
}
$score = [double]$controlScore.score
$maxScore = [double]$controlProfile.maxScore
From d30f91a40c65a9f948c68b3b64ba12f1cfb27918 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Sun, 8 Nov 2026 14:50:08 -0700
Subject: [PATCH 14/16] MT.1264: escape updatedBy like the comment next to it
---
powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 | 3 ++-
tests/maester/defender/Test.MT.1264.ps1 | 2 +-
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index 9bb3b8e927..783ee1e09c 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -348,7 +348,8 @@
Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 5 -StateUpdates @($update)) | Should -BeNullOrEmpty
$script:SkippedBecause | Should -Be 'Custom'
$script:SkippedCustomReason | Should -Match $Label
- $script:SkippedCustomReason | Should -Match 'admin@contoso.com'
+ # updatedBy is tenant data, so it goes through Get-MtSafeMarkdown; the @ comes back escaped.
+ $script:SkippedCustomReason | Should -Match 'admin\\@contoso\.com'
$script:SkippedCustomReason | Should -Match 'Handled elsewhere'
}
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index c38585978e..8bce97d372 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -280,7 +280,7 @@ function Test-MtSecureScoreControl {
}
if ($latestState -and $stateNames.ContainsKey([string]$latestState.state)) {
$reason = "This improvement action is marked as **$($stateNames[[string]$latestState.state])** ($($latestState.state)) in the Microsoft Defender portal"
- if ($latestState.updatedBy) { $reason += " by $($latestState.updatedBy)" }
+ if ($latestState.updatedBy) { $reason += " by $(Get-MtSafeMarkdown ([string]$latestState.updatedBy))" }
$reason += '.'
if ($latestState.comment) { $reason += "`n`nComment: $(Get-MtSafeMarkdown ([string]$latestState.comment))" }
$reason += "`n`nIf it applies to this tenant, change its status back to **To address** to have Maester check it again.$actionLinkMd"
From 742a5eb2b7c8a18a2ef8d43b0cc07aeeeb321943 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Fri, 13 Nov 2026 07:10:59 -0700
Subject: [PATCH 15/16] feat(defender): MT.1264 show the Secure Score snapshot
date in each result
---
.../Test-MtSecureScoreControl.Tests.ps1 | 32 ++++++++++++++++++-
tests/maester/defender/Test.MT.1264.ps1 | 24 +++++++++++++-
2 files changed, 54 insertions(+), 2 deletions(-)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index 783ee1e09c..9f4567f876 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -226,6 +226,14 @@
@(Get-MtSecureScoreControlInstance).Id | Should -Not -Contain 'exo_mailboxaudit'
}
+ It 'carries the snapshot date on every instance' {
+ $script:Snapshot.value[0] | Add-Member -NotePropertyName createdDateTime -NotePropertyValue '2026-11-12T03:00:00Z'
+
+ $instances = @(Get-MtSecureScoreControlInstance)
+ $instances.Count | Should -Be 3
+ $instances | ForEach-Object { $_.Data.SnapshotDate | Should -Be '2026-11-12T03:00:00Z' }
+ }
+
It 'returns no instances when the tenant has no snapshot yet' {
$script:Snapshot = [pscustomobject]@{ value = @() }
@@ -311,7 +319,7 @@
Context 'Test' {
BeforeEach {
function Get-FakeInstance {
- param([double] $Score, [double] $MaxScore, [object[]] $StateUpdates = @(), [bool] $InMt1024 = $false)
+ param([double] $Score, [double] $MaxScore, [object[]] $StateUpdates = @(), [bool] $InMt1024 = $false, [object] $SnapshotDate = $null)
[pscustomobject]@{
Id = 'ctrl'
Severity = 'Medium'
@@ -319,6 +327,7 @@
ControlScore = (Get-FakeControlScore -Name 'ctrl' -Score $Score)
Profile = (Get-FakeControlProfile -Id 'ctrl' -MaxScore $MaxScore -StateUpdates $StateUpdates)
InMt1024 = $InMt1024
+ SnapshotDate = $SnapshotDate
}
}
}
@@ -337,6 +346,27 @@
$script:TestResult | Should -Match 'Open this improvement action\]\(https://security.microsoft.com/ctrl\)'
}
+ It 'shows the snapshot date in UTC when Graph returns it as text' {
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 9 -MaxScore 9 -SnapshotDate '2026-11-12T03:00:00Z') | Should -BeTrue
+ $script:TestResult | Should -Match 'snapshot taken 2026-11-12 03:00 UTC'
+ }
+
+ It 'shows the snapshot date in UTC when Graph returns it as a date' {
+ $date = [datetime]::SpecifyKind([datetime]'2026-11-12T03:00:00', [System.DateTimeKind]::Utc)
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 0 -MaxScore 3 -SnapshotDate $date) | Should -BeFalse
+ $script:TestResult | Should -Match 'snapshot taken 2026-11-12 03:00 UTC'
+ }
+
+ It 'says the snapshot date could not be read instead of failing' {
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 9 -MaxScore 9 -SnapshotDate 'not a date') | Should -BeTrue
+ $script:TestResult | Should -Match 'date of the Secure Score snapshot could not be read'
+ }
+
+ It 'leaves the snapshot line out when the snapshot has no date' {
+ Test-MtSecureScoreControl -Instance (Get-FakeInstance -Score 9 -MaxScore 9) | Should -BeTrue
+ $script:TestResult | Should -Not -Match 'snapshot taken'
+ }
+
It 'skips a control marked and reports who set it and their comment' -ForEach @(
@{ State = 'Ignored'; Label = 'risk accepted' }
@{ State = 'ThirdParty'; Label = 'resolved through third party' }
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index 8bce97d372..7e09badb57 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -70,7 +70,7 @@
Title = "$controlName."
Severity = 'Medium'
Tag = @(@($controlScore.controlCategory) | Where-Object { $_ })
- Data = [pscustomobject]@{ ControlScore = $controlScore; Profile = $null; InMt1024 = $false }
+ Data = [pscustomobject]@{ ControlScore = $controlScore; Profile = $null; InMt1024 = $false; SnapshotDate = $snapshot.createdDateTime }
}
continue
}
@@ -90,6 +90,8 @@
ControlScore = $controlScore
Profile = $controlProfile
InMt1024 = $entraRecommendationTypes.Contains($controlName)
+ # When Microsoft took the snapshot, so a setting changed after it is not mistaken for a failure.
+ SnapshotDate = $snapshot.createdDateTime
}
}
}
@@ -292,6 +294,26 @@ function Test-MtSecureScoreControl {
$resultMd = "**$score of $maxScore points** for this improvement action."
$status = ConvertFrom-MtSecureScoreHtml -Html ([string]$controlScore.implementationStatus)
if ($status) { $resultMd += "`n`n$status" }
+ # Secure Score refreshes once a day, so say which snapshot the points come from. Graph can hand the date
+ # back as text or as a date; both are shown in UTC. No date, no line. A date that cannot be read is said
+ # so, rather than dropped or failing the test.
+ $snapshotDate = $Instance.Data.SnapshotDate
+ if ($snapshotDate) {
+ $snapshotUtc = $null
+ if ($snapshotDate -is [datetime]) {
+ $snapshotUtc = if ($snapshotDate.Kind -eq [System.DateTimeKind]::Unspecified) { [datetime]::SpecifyKind($snapshotDate, [System.DateTimeKind]::Utc) } else { $snapshotDate.ToUniversalTime() }
+ } else {
+ $parsed = [datetimeoffset]::MinValue
+ if ([datetimeoffset]::TryParse([string]$snapshotDate, [cultureinfo]::InvariantCulture, [System.Globalization.DateTimeStyles]::AssumeUniversal, [ref]$parsed)) {
+ $snapshotUtc = $parsed.UtcDateTime
+ }
+ }
+ if ($snapshotUtc) {
+ $resultMd += "`n`nFrom the Secure Score snapshot taken $($snapshotUtc.ToString('yyyy-MM-dd HH:mm', [cultureinfo]::InvariantCulture)) UTC."
+ } else {
+ $resultMd += "`n`nThe date of the Secure Score snapshot could not be read."
+ }
+ }
if (-not $passed) { $resultMd += $actionLinkMd }
Add-MtTestResultDetail -Description $descriptionMd -Severity $severity -Result $resultMd
From 38578c0b2fe789bf795c821790de28e4c5fc5c41 Mon Sep 17 00:00:00 2001
From: Darius Frank
Date: Mon, 16 Nov 2026 10:13:14 -0700
Subject: [PATCH 16/16] fix(defender): MT.1264 keep decoded markup from
reaching the report as HTML
ConvertFrom-MtSecureScoreHtml stripped tags and then decoded entities, so
encoded text such as <script> came back as live markup. After decoding,
escape any remaining < and > the way Get-MtSafeMarkdown does, so the report
shows them as text. Escaping instead of decoding first keeps placeholders such
as in remediation steps, which decode-then-strip would delete.
Note at the profile lookup that the join relies on the profile id being the
control name, although the reference documents it as a GUID.
Co-Authored-By: Claude Opus 5.5
Claude-Session: https://claude.ai/code/session_01WrYw8C2gSDFxzWqZ2zKtJB
---
.../functions/Test-MtSecureScoreControl.Tests.ps1 | 13 +++++++++++++
tests/maester/defender/Test.MT.1264.ps1 | 8 ++++++++
2 files changed, 21 insertions(+)
diff --git a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1 b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
index 9f4567f876..85e3305bf7 100644
--- a/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
+++ b/powershell/tests/functions/Test-MtSecureScoreControl.Tests.ps1
@@ -310,6 +310,19 @@
$md | Should -Not -Match ' '
}
+ It 'does not turn encoded markup back into HTML' -ForEach @(
+ @{ Html = '<script>alert(1)</script>'; Expected = '\' }
+ @{ Html = '<img src=x onerror=alert(1)>'; Expected = '\
' }
+ @{ Html = '<iframe src="https://example.com"></iframe>
'; Expected = '\' }
+ ) {
+ ConvertFrom-MtSecureScoreHtml -Html $Html | Should -BeExactly $Expected
+ }
+
+ It 'keeps an encoded placeholder as text instead of dropping it' {
+ ConvertFrom-MtSecureScoreHtml -Html 'Run Set-Mailbox -Identity <MailboxIdentity> -AuditEnabled $true
' |
+ Should -BeExactly 'Run Set-Mailbox -Identity \ -AuditEnabled $true'
+ }
+
It 'returns an empty string for empty input' {
ConvertFrom-MtSecureScoreHtml -Html '' | Should -Be ''
ConvertFrom-MtSecureScoreHtml -Html $null | Should -Be ''
diff --git a/tests/maester/defender/Test.MT.1264.ps1 b/tests/maester/defender/Test.MT.1264.ps1
index 7e09badb57..cfaacafbed 100644
--- a/tests/maester/defender/Test.MT.1264.ps1
+++ b/tests/maester/defender/Test.MT.1264.ps1
@@ -33,6 +33,10 @@
# No snapshot yet (for example a brand new tenant): no instances, so the engine skips the family.
if ($null -eq $snapshot) { return }
+ # Joined on the profile id, which in practice is the control name (exo_mailboxaudit, AdminMFAV2), although
+ # the secureScoreControlProfile reference describes id as a "Provider-generated GUID/unique identifier".
+ # If Microsoft ever makes it a GUID, no control finds its profile and every result errors (see the
+ # no-profile check in Test-MtSecureScoreControl) rather than passing empty.
$profileLookup = @{}
foreach ($controlProfile in $profiles) { $profileLookup[[string]$controlProfile.id] = $controlProfile }
@@ -196,6 +200,10 @@ function ConvertFrom-MtSecureScoreHtml {
$text = $text -replace '(?i)]*>', "`n- " -replace '(?i)
', "`n" -replace '(?i)|', "`n`n"
$text = $text -replace '<[^>]+>', ''
$text = [System.Net.WebUtility]::HtmlDecode($text)
+ # Decoding can turn encoded text back into markup (<script> becomes