Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -180,7 +200,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' })
Expand All @@ -189,7 +209,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.
Expand All @@ -205,11 +225,11 @@ Describe 'Entra ID Protection unremediated high-risk users (MT.1260)' {
}

Test-MtEntraUnremediatedHighRiskUser | Should -BeFalse
$script:Severity | Should -Be 'High'
$script:TestResult | Should -Match 'Global Administrator \(eligible\)'
$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' })
Expand Down
2 changes: 1 addition & 1 deletion tests/maester/entra/Test.MT.1260.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Comment thread
Dfrank77 marked this conversation as resolved.
Resolved

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.

Expand Down
24 changes: 10 additions & 14 deletions tests/maester/entra/Test.MT.1260.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 = ''
Expand Down Expand Up @@ -129,31 +129,27 @@

$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| --- | --- | --- | --- | --- | --- |"
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
Comment thread
Dfrank77 marked this conversation as resolved.
Resolved
$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 |"
}
$Result += $RoleNote

if ($PrivilegedCount -gt 0) {
Add-MtTestResultDetail -Result $Result -Severity 'High'
} else {
Add-MtTestResultDetail -Result $Result
}
Add-MtTestResultDetail -Result $Result
return $false
}
Loading