From 3a1b56ac6a5ee9cdd937cba2c00ecd9d5000448b Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Sat, 7 Nov 2026 01:06:50 +0000 Subject: [PATCH 1/3] fix(entra): MT.1260 stop claiming a severity raise that never applies Add-MtTestResultDetail -Severity is ignored in a single-result native test (website/docs/writing-tests/index.mdx), so MT.1260 never actually raised severity to High for privileged users, while the result text said it did. Remove the -Severity call and the "severity is raised to High" wording. Privileged users are still detected, listed first, and shown with their roles. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01WrYw8FTdwmyZ3ktKSYEJij --- ...est-MtEntraUnremediatedHighRiskUser.Tests.ps1 | 8 ++++---- tests/maester/entra/Test.MT.1260.md | 2 +- tests/maester/entra/Test.MT.1260.ps1 | 16 ++++++---------- 3 files changed, 11 insertions(+), 15 deletions(-) diff --git a/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 b/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 index 65fa680747..42a80c2f69 100644 --- a/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 +++ b/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 @@ -180,7 +180,7 @@ Describe 'Entra ID Protection unremediated high-risk users (MT.1260)' { } } - It 'raises severity to High and lists the role when an at-risk user holds a privileged role' { + It 'lists the role first when an at-risk user holds a privileged role' { Mock -ModuleName Maester Get-MtDirectoryRoleAssignment { return [pscustomobject]@{ Assignments = @([pscustomobject]@{ principalId = 'user-2'; roleDefinitionId = 'role-ga'; AssignmentType = 'Active' }) @@ -189,7 +189,7 @@ Describe 'Entra ID Protection unremediated high-risk users (MT.1260)' { } Test-MtEntraUnremediatedHighRiskUser | Should -BeFalse - $script:Severity | Should -Be 'High' + $script:Severity | Should -BeNullOrEmpty $script:TestResult | Should -Match 'Global Administrator' $script:TestResult | Should -Match '1 of them hold a privileged directory role' # The privileged user is listed first. @@ -205,11 +205,11 @@ Describe 'Entra ID Protection unremediated high-risk users (MT.1260)' { } Test-MtEntraUnremediatedHighRiskUser | Should -BeFalse - $script:Severity | Should -Be 'High' + $script:Severity | Should -BeNullOrEmpty $script:TestResult | Should -Match 'Global Administrator \(eligible\)' } - It 'does not raise severity for a non-privileged role' { + It 'does not list a non-privileged role' { Mock -ModuleName Maester Get-MtDirectoryRoleAssignment { return [pscustomobject]@{ Assignments = @([pscustomobject]@{ principalId = 'user-1'; roleDefinitionId = 'role-dr'; AssignmentType = 'Active' }) diff --git a/tests/maester/entra/Test.MT.1260.md b/tests/maester/entra/Test.MT.1260.md index 268e31267a..1d101bac3e 100644 --- a/tests/maester/entra/Test.MT.1260.md +++ b/tests/maester/entra/Test.MT.1260.md @@ -4,7 +4,7 @@ Entra ID Protection rates a user's risk and tracks a risk state for each flagged This check reports users whose risk level is **high** and whose risk state is still active and unremediated (`atRisk` or `confirmedCompromised`). States that represent a handled flag (`remediated`, `dismissed`, `confirmedSafe`, `none`) are not reported. The check reads risk only and never changes a user's risk state. -If a reported user holds a privileged directory role, active or PIM-eligible, the result lists the role and the severity is raised to High, since a compromised admin account puts the whole tenant at risk. +If a reported user holds a privileged directory role, active or PIM-eligible, the result lists the role and shows that entry first, since a compromised admin account puts the whole tenant at risk. The check needs the Microsoft Graph permission `IdentityRiskyUser.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. diff --git a/tests/maester/entra/Test.MT.1260.ps1 b/tests/maester/entra/Test.MT.1260.ps1 index 9ccbf2476d..8367f7517f 100644 --- a/tests/maester/entra/Test.MT.1260.ps1 +++ b/tests/maester/entra/Test.MT.1260.ps1 @@ -7,8 +7,8 @@ risk state. A flag only clears when someone remediates it (password reset) or an admin dismisses or confirms-safe it. This check reports users whose risk level is high and whose risk state still shows active, unremediated risk, so an admin can act on flags that have been - left sitting. If a reported user holds a privileged directory role, the severity is raised to - High. It reads risk only; it never changes a user's risk state. + left sitting. If a reported user holds a privileged directory role, it is listed first + with its roles. It reads risk only; it never changes a user's risk state. .EXAMPLE Test-MtEntraUnremediatedHighRiskUser .LINK @@ -76,8 +76,8 @@ return $true } - # Privileged users at risk raise severity to High (#2518). Roles are only read when there is - # something to report, so a clean tenant makes no extra Graph calls. The role lookup is extra + # Privileged users at risk are listed first with their roles (#2518). Roles are only read when + # there is something to report, so a clean tenant makes no extra Graph calls. The role lookup is extra # detail: if it fails, the unremediated users are still reported, with a note. $PrivilegedRolesByUser = @{} $RoleNote = '' @@ -129,7 +129,7 @@ $Result = "Found $($Unremediated.Count) high-risk user(s) with unremediated risk." if ($PrivilegedCount -gt 0) { - $Result += " $PrivilegedCount of them hold a privileged directory role, so severity is raised to High." + $Result += " $PrivilegedCount of them hold a privileged directory role and are listed first." } $Result += "`n`n| User | User principal name | Risk state | Risk detail | Risk last updated | Privileged role |" $Result += "`n| --- | --- | --- | --- | --- | --- |" @@ -150,10 +150,6 @@ } $Result += $RoleNote - if ($PrivilegedCount -gt 0) { - Add-MtTestResultDetail -Result $Result -Severity 'High' - } else { - Add-MtTestResultDetail -Result $Result - } + Add-MtTestResultDetail -Result $Result return $false } From d1ac0dc03457bf8d31b6a2a7a51cec6264861e85 Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Fri, 6 Nov 2026 19:14:47 -0700 Subject: [PATCH 2/3] Re-run CI From 64cb65530fb7ace4d3ad8059dfa84e5ee378e5c1 Mon Sep 17 00:00:00 2001 From: Darius Frank Date: Sat, 7 Nov 2026 09:14:38 -0700 Subject: [PATCH 3/3] MT.1260: escape tenant names with Get-MtSafeMarkdown HtmlEncode escapes HTML, not markdown, so a display name like [Sign in again](https://phish.example) rendered as a live link in the report. Use Get-MtSafeMarkdown as #2254 requires for tenant-controlled values, matching MT.1261. Raised in #2711. Co-Authored-By: Claude Opus 5.5 --- ...-MtEntraUnremediatedHighRiskUser.Tests.ps1 | 22 ++++++++++++++++++- tests/maester/entra/Test.MT.1260.ps1 | 8 +++---- 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 b/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 index 42a80c2f69..6130582016 100644 --- a/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 +++ b/powershell/tests/functions/Test-MtEntraUnremediatedHighRiskUser.Tests.ps1 @@ -73,6 +73,26 @@ Describe 'Entra ID Protection unremediated high-risk users (MT.1260)' { $script:TestResult | Should -Match 'atRisk' } + It 'escapes a tenant-controlled display name so it cannot render as a link' { + Mock -ModuleName Maester Invoke-MtGraphRequest { + return @( + [pscustomobject]@{ + id = 'user-1' + userPrincipalName = 'alice@contoso.com' + userDisplayName = '[Sign in again](https://phish.example)' + riskLevel = 'high' + riskState = 'atRisk' + riskDetail = 'none' + riskLastUpdatedDateTime = '2026-10-01T00:00:00Z' + } + ) + } + + Test-MtEntraUnremediatedHighRiskUser | Should -BeFalse + $script:TestResult | Should -Not -Match '\| \[Sign in again\]\(' + $script:TestResult | Should -Match ([regex]::Escape('\[Sign in again\]\(https://phish.example\)')) + } + It 'fails when a high-risk user is confirmedCompromised (must not be treated as remediated)' { # This is the case that breaks if the check filters on riskState eq atRisk only: # confirmCompromised lands a user in confirmedCompromised, which is still unremediated. @@ -206,7 +226,7 @@ Describe 'Entra ID Protection unremediated high-risk users (MT.1260)' { Test-MtEntraUnremediatedHighRiskUser | Should -BeFalse $script:Severity | Should -BeNullOrEmpty - $script:TestResult | Should -Match 'Global Administrator \(eligible\)' + $script:TestResult | Should -Match 'Global Administrator \\\(eligible\\\)' } It 'does not list a non-privileged role' { diff --git a/tests/maester/entra/Test.MT.1260.ps1 b/tests/maester/entra/Test.MT.1260.ps1 index 8367f7517f..51c863322a 100644 --- a/tests/maester/entra/Test.MT.1260.ps1 +++ b/tests/maester/entra/Test.MT.1260.ps1 @@ -136,15 +136,15 @@ foreach ($Item in $Sorted) { $DisplayName = [string]$Item.userDisplayName if ([string]::IsNullOrWhiteSpace($DisplayName)) { $DisplayName = '(unnamed)' } - $DisplayName = [System.Net.WebUtility]::HtmlEncode($DisplayName) -replace '\|', '|' - $Upn = [System.Net.WebUtility]::HtmlEncode([string]$Item.userPrincipalName) -replace '\|', '|' + $DisplayName = Get-MtSafeMarkdown $DisplayName + $Upn = Get-MtSafeMarkdown ([string]$Item.userPrincipalName) $State = [string]$Item.riskState - $Detail = [System.Net.WebUtility]::HtmlEncode([string]$Item.riskDetail) -replace '\|', '|' + $Detail = Get-MtSafeMarkdown ([string]$Item.riskDetail) $Updated = if ($Item.riskLastUpdatedDateTime) { ($Item.riskLastUpdatedDateTime -as [datetime]).ToUniversalTime().ToString('yyyy-MM-dd') } else { 'Unknown' } $Roles = if ($PrivilegedRolesByUser.ContainsKey([string]$Item.id)) { - [System.Net.WebUtility]::HtmlEncode(($PrivilegedRolesByUser[[string]$Item.id] -join ', ')) -replace '\|', '|' + Get-MtSafeMarkdown ($PrivilegedRolesByUser[[string]$Item.id] -join ', ') } else { 'None' } $Result += "`n| $DisplayName | $Upn | $State | $Detail | $Updated | $Roles |" }