From e9a0ff3abf7d7932fd0555d3f44c162f7c3ae159 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Tue, 10 Nov 2026 08:02:56 +1300 Subject: [PATCH 1/4] fix(cis): align 3.2 DLP checks with benchmark procedures Require a qualifying workload location, review permitted Teams exceptions, and show Copilot exclusion evidence. Align remediation guides and cover label-based rules with focused regression tests. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../functions/Test-MtCisDlpPolicies.Tests.ps1 | 325 ++++++++++++++++++ tests/cis/Test.CIS.M365.3.2.1.md | 10 +- tests/cis/Test.CIS.M365.3.2.1.ps1 | 27 +- tests/cis/Test.CIS.M365.3.2.2.md | 9 +- tests/cis/Test.CIS.M365.3.2.2.ps1 | 50 ++- tests/cis/Test.CIS.M365.3.2.3.md | 13 +- tests/cis/Test.CIS.M365.3.2.3.ps1 | 23 +- 7 files changed, 413 insertions(+), 44 deletions(-) create mode 100644 powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 diff --git a/powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 b/powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 new file mode 100644 index 0000000000..24db88a1c1 --- /dev/null +++ b/powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 @@ -0,0 +1,325 @@ +BeforeAll { + Import-Module "$PSScriptRoot/../../Maester.psd1" -Force -WarningAction SilentlyContinue + . "$PSScriptRoot/../helpers/Use-MtModuleFunction.ps1" + Use-MtModuleFunction -Name Test-MtCisDlpPoliciesEnabled, Test-MtCisTeamsDlpPolicy, Test-MtCisDlpPoliciesCopilot + + function Get-DlpPolicyFixture { + param([hashtable] $Properties = @{}) + $policy = @{ + Name = 'DLP policy' + Mode = 'Enable' + EnforcementPlanes = @() + Workload = 'Exchange' + ExchangeLocation = @() + SharePointLocation = @() + OneDriveLocation = @() + TeamsLocation = @() + TeamsLocationException = @() + PolicyRBACScopes = @() + IsSimulationPolicy = $false + MicrosoftCopilotLocation = @() + Locations = @() + LocationInclusions = @('All') + LocationExclusions = @() + } + foreach ($key in $Properties.Keys) { $policy[$key] = $Properties[$key] } + [pscustomobject]$policy + } + + function Get-DlpRuleFixture { + param([hashtable] $Properties = @{}) + $rule = @{ + ParentPolicyName = 'DLP policy' + Disabled = $false + Mode = 'Enforce' + ContentContainsSensitiveInformation = @(@{ Name = 'Credit Card Number' }) + AdvancedRule = $null + BlockAccess = $true + RestrictAccess = @() + RestrictWebGrounding = $false + } + foreach ($key in $Properties.Keys) { $rule[$key] = $Properties[$key] } + [pscustomobject]$rule + } +} + +Describe 'CIS 3.2 DLP audit alignment' { + BeforeEach { + $script:Result = $null + $script:Investigate = $false + $script:Policies = @() + $script:Rules = @() + Mock -ModuleName Maester Get-MtExo { + if ($Request -eq 'DlpCompliancePolicy') { $script:Policies } + elseif ($Request -eq 'DlpComplianceRule') { $script:Rules } + else { throw "Unexpected request: $Request" } + } + Mock -ModuleName Maester Add-MtTestResultDetail { + param($Result, [switch] $Investigate) + $script:Result = $Result + $script:Investigate = $Investigate.IsPresent + } + } + + Context '3.2.1 required workload locations' { + It 'accepts a defined ()' -ForEach @( + foreach ($location in 'ExchangeLocation', 'SharePointLocation', 'OneDriveLocation', 'TeamsLocation') { + @{ Location = $location; Shape = 'string'; Value = @('All') } + @{ Location = $location; Shape = 'object'; Value = @([pscustomobject]@{ ImmutableIdentity = 'target-id'; DisplayName = 'Target' }) } + } + ) { + $script:Policies = @(Get-DlpPolicyFixture -Properties @{ $Location = $Value }) + + Test-MtCisDlpPoliciesEnabled | Should -BeTrue + $script:Investigate | Should -BeFalse + $script:Result | Should -Match $Location + } + + It 'fails with ' -ForEach @( + @{ Case = 'no policies'; Properties = $null } + @{ Case = 'no required location'; Properties = @{} } + @{ Case = 'null and empty locations'; Properties = @{ ExchangeLocation = $null; SharePointLocation = @($null); OneDriveLocation = @('') } } + @{ Case = 'a disabled policy'; Properties = @{ Mode = 'Disable'; ExchangeLocation = @('All') } } + @{ Case = 'a simulation mode'; Properties = @{ Mode = 'TestWithNotifications'; ExchangeLocation = @('All') } } + @{ Case = 'a Copilot-only policy'; Properties = @{ EnforcementPlanes = @('CopilotExperiences') } } + @{ Case = 'another workload only'; Properties = @{ Workload = 'Endpoint'; Locations = @('Endpoint') } } + ) { + if ($null -ne $Properties) { $script:Policies = @(Get-DlpPolicyFixture -Properties $Properties) } + + Test-MtCisDlpPoliciesEnabled | Should -BeFalse + $script:Investigate | Should -BeFalse + } + + It 'does not combine an enabled policy without locations with a disabled policy with locations' { + $script:Policies = @( + Get-DlpPolicyFixture + Get-DlpPolicyFixture -Properties @{ Mode = 'Disable'; ExchangeLocation = @('All') } + ) + + Test-MtCisDlpPoliciesEnabled | Should -BeFalse + } + + It 'accepts a mixed Copilot and required-workload policy' { + $script:Policies = @(Get-DlpPolicyFixture -Properties @{ EnforcementPlanes = @('CopilotExperiences'); TeamsLocation = @('All') }) + + Test-MtCisDlpPoliciesEnabled | Should -BeTrue + } + } + + Context '3.2.2 Teams all accounts and permitted exceptions' { + BeforeEach { + $script:Policies = @(Get-DlpPolicyFixture -Properties @{ Workload = 'Exchange, Teams'; TeamsLocation = @([pscustomobject]@{ ImmutableIdentity = 'All' }) }) + } + + It 'passes without exceptions' { + Test-MtCisTeamsDlpPolicy | Should -BeTrue + $script:Investigate | Should -BeFalse + } + + It 'accepts string and DisplayName representations of All' -ForEach @( + @{ Value = @('All') } + @{ Value = @([pscustomobject]@{ DisplayName = 'All' }) } + ) { + $script:Policies[0].TeamsLocation = $Value + + Test-MtCisTeamsDlpPolicy | Should -BeTrue + } + + It 'accepts a mixed Copilot and Teams policy' { + $script:Policies[0].EnforcementPlanes = @('CopilotExperiences') + + Test-MtCisTeamsDlpPolicy | Should -BeTrue + } + + It 'marks exceptions for investigation and lists their identities' { + $script:Policies[0].TeamsLocationException = @('allowed@contoso.com', [pscustomobject]@{ ImmutableIdentity = 'group-id'; DisplayName = 'Approved group' }) + + Test-MtCisTeamsDlpPolicy | Should -BeTrue + $script:Investigate | Should -BeTrue + $script:Result | Should -Match ([regex]::Escape((Get-MtSafeMarkdown 'allowed@contoso.com'))) + $script:Result | Should -Match 'group-id' + $script:Result | Should -Match 'Approved group' + $script:Result | Should -Match 'permitted by the organization' + } + + It 'passes if another qualifying policy has no exceptions' { + $script:Policies[0].TeamsLocationException = @('allowed@contoso.com') + $script:Policies += Get-DlpPolicyFixture -Properties @{ Name = 'Unrestricted'; Workload = 'Teams'; TeamsLocation = @('All') } + + Test-MtCisTeamsDlpPolicy | Should -BeTrue + $script:Investigate | Should -BeFalse + } + + It 'fails rather than investigates , even with exceptions' -ForEach @( + @{ Case = 'a disabled policy'; Property = 'Mode'; Value = 'Disable' } + @{ Case = 'a non-Teams workload'; Property = 'Workload'; Value = 'Exchange' } + @{ Case = 'selected accounts'; Property = 'TeamsLocation'; Value = @('user@contoso.com') } + @{ Case = 'an unknown location'; Property = 'TeamsLocation'; Value = @() } + @{ Case = 'an administrative-unit scope'; Property = 'PolicyRBACScopes'; Value = @('unit-id') } + ) { + $script:Policies[0].$Property = $Value + $script:Policies[0].TeamsLocationException = @('allowed@contoso.com') + + Test-MtCisTeamsDlpPolicy | Should -BeFalse + $script:Investigate | Should -BeFalse + } + + It 'fails when no policy is returned' { + $script:Policies = @() + + Test-MtCisTeamsDlpPolicy | Should -BeFalse + } + } + + Context '3.2.3 Copilot rules and exclusion evidence' { + BeforeEach { + $script:Policies = @(Get-DlpPolicyFixture -Properties @{ EnforcementPlanes = @('CopilotExperiences'); Workload = 'Copilot' }) + $script:Rules = @(Get-DlpRuleFixture) + } + + It 'accepts an enforcing sensitive-information rule' { + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + $script:Investigate | Should -BeFalse + } + + It 'accepts sensitivity-label groups in ContentContainsSensitiveInformation' { + $script:Rules[0].ContentContainsSensitiveInformation = @(@{ + operator = 'And' + groups = @(@{ operator = 'Or'; name = 'Default'; labels = @(@{ name = 'Confidential'; type = 'Sensitivity' }) }) + }) + + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + $script:Investigate | Should -BeFalse + } + + It 'accepts label conditions in AdvancedRule' { + $script:Rules[0].ContentContainsSensitiveInformation = @() + $script:Rules[0].AdvancedRule = '{"Version":"1.0","Condition":{"Operator":"And","SubConditions":[{"ConditionName":"ContentContainsSensitiveInformation","Value":[{"operator":"And","groups":[{"operator":"Or","name":"Default","labels":[{"name":"Confidential","type":"Sensitivity"}]}]}]}]}}' + + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + } + + It 'accepts the restriction' -ForEach @( + @{ Action = 'RestrictAccess'; Value = @('Block') } + @{ Action = 'RestrictWebGrounding'; Value = $true } + ) { + $script:Rules[0].BlockAccess = $false + $script:Rules[0].$Action = $Value + + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + } + + It 'fails for ' -ForEach @( + @{ Case = 'no rules'; Properties = $null } + @{ Case = 'a disabled rule'; Properties = @{ Disabled = $true } } + @{ Case = 'an audit-only rule'; Properties = @{ Mode = 'TestWithNotifications' } } + @{ Case = 'a rule for another policy'; Properties = @{ ParentPolicyName = 'Other policy' } } + @{ Case = 'no sensitive condition'; Properties = @{ ContentContainsSensitiveInformation = @() } } + @{ Case = 'no restrictive action'; Properties = @{ BlockAccess = $false; RestrictAccess = @('None') } } + ) { + $script:Rules = @() + if ($null -ne $Properties) { $script:Rules = @(Get-DlpRuleFixture -Properties $Properties) } + + Test-MtCisDlpPoliciesCopilot | Should -BeFalse + $script:Investigate | Should -BeFalse + } + + It 'fails rather than investigates ' -ForEach @( + @{ Case = 'a disabled policy'; Properties = @{ Mode = 'Disable' } } + @{ Case = 'a simulation policy'; Properties = @{ IsSimulationPolicy = $true } } + @{ Case = 'an administrative-unit scope'; Properties = @{ PolicyRBACScopes = @('unit-id') } } + @{ Case = 'selected accounts'; Properties = @{ LocationInclusions = @('user@contoso.com') } } + @{ Case = 'no Copilot location'; Properties = @{ EnforcementPlanes = @(); Workload = 'Exchange' } } + ) { + foreach ($key in $Properties.Keys) { $script:Policies[0].$key = $Properties[$key] } + $script:Policies[0].LocationExclusions = @('allowed@contoso.com') + + Test-MtCisDlpPoliciesCopilot | Should -BeFalse + $script:Investigate | Should -BeFalse + } + + It 'investigates an unknown inclusion scope' { + $script:Policies[0].LocationInclusions = @() + + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + $script:Investigate | Should -BeTrue + } + + It 'lists top-level exclusions for manual approval' { + $script:Policies[0].LocationExclusions = @('allowed@contoso.com', [pscustomobject]@{ ImmutableIdentity = 'excluded-id'; DisplayName = 'Approved group' }) + + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + $script:Investigate | Should -BeTrue + $script:Result | Should -Match ([regex]::Escape((Get-MtSafeMarkdown 'allowed@contoso.com'))) + $script:Result | Should -Match 'excluded-id' + $script:Result | Should -Match 'Approved group' + } + + It 'lists exclusions from without borrowing another workload scope' -ForEach @( + @{ Field = 'Locations' } + @{ Field = 'MicrosoftCopilotLocation' } + ) { + $copilot = [pscustomobject]@{ Location = '470f2276-e011-4e9d-a6ec-20768be3a4b0'; Inclusions = @('All'); Exclusions = @('copilot-exclusion-id') } + $script:Policies[0].Locations = @([pscustomobject]@{ Location = 'Exchange'; Inclusions = @('All'); Exclusions = @('exchange-exclusion-id') }) + if ($Field -eq 'Locations') { + $script:Policies[0].Locations += $copilot + $script:Policies[0].Locations = ConvertTo-Json -InputObject $script:Policies[0].Locations -Depth 10 -Compress + } + else { $script:Policies[0].MicrosoftCopilotLocation = @($copilot) } + + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + $script:Investigate | Should -BeTrue + $script:Result | Should -Match 'copilot-exclusion-id' + $script:Result | Should -Not -Match 'exchange-exclusion-id' + } + + It 'does not borrow All from Exchange in a mixed-location policy' { + $script:Policies[0].Locations = @( + [pscustomobject]@{ Location = 'Exchange'; Inclusions = @('All') } + [pscustomobject]@{ Location = 'Copilot'; Inclusions = @('selected-user') } + ) + + Test-MtCisDlpPoliciesCopilot | Should -BeFalse + } + + It 'passes if another qualifying Copilot policy has no exclusions' { + $script:Policies[0].LocationExclusions = @('allowed@contoso.com') + $script:Policies += Get-DlpPolicyFixture -Properties @{ Name = 'Unrestricted'; EnforcementPlanes = @('CopilotExperiences'); Workload = 'Copilot' } + $script:Rules += Get-DlpRuleFixture -Properties @{ ParentPolicyName = 'Unrestricted' } + + Test-MtCisDlpPoliciesCopilot | Should -BeTrue + $script:Investigate | Should -BeFalse + } + + It 'fails when no policy is returned' { + $script:Policies = @() + + Test-MtCisDlpPoliciesCopilot | Should -BeFalse + } + } + + Context 'safe result evidence' { + It 'escapes tenant-controlled names, modes and exceptions for ' -ForEach @( + @{ Check = 'Test-MtCisDlpPoliciesEnabled' } + @{ Check = 'Test-MtCisTeamsDlpPolicy' } + @{ Check = 'Test-MtCisDlpPoliciesCopilot' } + ) { + $name = '![x](https://example.com)|$&' + $exception = 'excluded@contoso.com|[link](https://example.com)' + $mode = 'Disabled|[link](https://example.com)' + $script:Policies = @(Get-DlpPolicyFixture -Properties @{ + Name = $name; Mode = $mode; Workload = 'Teams' + TeamsLocation = @('All'); TeamsLocationException = @($exception) + EnforcementPlanes = @('CopilotExperiences'); LocationExclusions = @($exception) + }) + + & $Check | Should -BeFalse + $script:Result | Should -Match ([regex]::Escape((Get-MtSafeMarkdown $name))) + $script:Result | Should -Match ([regex]::Escape((Get-MtSafeMarkdown $mode))) + if ($Check -ne 'Test-MtCisDlpPoliciesEnabled') { + $script:Result | Should -Match ([regex]::Escape((Get-MtSafeMarkdown $exception))) + } + $script:Result | Should -Not -Match '%TestResult%' + } + } +} diff --git a/tests/cis/Test.CIS.M365.3.2.1.md b/tests/cis/Test.CIS.M365.3.2.1.md index 5ed6fcb652..1b0d8bc412 100644 --- a/tests/cis/Test.CIS.M365.3.2.1.md +++ b/tests/cis/Test.CIS.M365.3.2.1.md @@ -1,15 +1,17 @@ -At least one data loss prevention (DLP) policy for Exchange, SharePoint, OneDrive or Teams is enabled. Policies for Copilot are checked separately. +At least one data loss prevention (DLP) policy for Exchange, SharePoint, OneDrive or Teams is enabled. A Copilot-only policy does not satisfy this requirement. Without DLP, sensitive information such as card numbers, national identifiers and health records can be emailed, shared or uploaded with nothing to stop it, warn the user or record it. A DLP policy gives you that control and an audit trail, even if you only start in a mode that reports. The locations it covers are the repositories and cloud storage that an attacker collects data from (T1213 and T1530), and it detects and blocks sensitive content that is sent out through a web service (T1567). -The test passes when one non-Copilot policy is in the **Enable** mode. It does not check which locations or users the policy covers, or whether the policy has exclusions. Policies for Copilot are checked in a separate test. A Microsoft 365 licence that includes Purview DLP is required; tenants without it are skipped. +The test passes when at least one policy is in **Enable** mode and defines an **ExchangeLocation**, **SharePointLocation**, **OneDriveLocation**, or **TeamsLocation**. A policy can also cover Copilot, but must define at least one of these four workload locations to qualify. The test does not assess whether the selected rules meet the organization's DLP needs, which users are covered, or whether exclusions are permitted; review those separately. A Microsoft 365 licence that includes Purview DLP is required; tenants without it are skipped. #### Remediation action 1. Sign in to the [Microsoft Purview portal](https://purview.microsoft.com). 2. Go to **Solutions** > **Data loss prevention** > [**Policies**](https://purview.microsoft.com/datalossprevention/policies) and select **Create policy**. -3. Choose a template or a custom policy, give it a name, and select the locations and users that need protection. -4. Configure the rules for the sensitive information that matters to you and set the policy mode to **Turn it on right away**. +3. Choose a template or a custom policy and give it a name. +4. Select at least one of **Exchange email**, **SharePoint sites**, **OneDrive accounts**, or **Teams chat and channel messages**, and select the users that need protection. +5. Configure the rules for the sensitive information that matters to the organization, such as credit card numbers and personally identifiable information. +6. Set the policy mode to **Turn it on right away**, review the settings, and submit the policy. Verify that its mode is **On** in the portal (**Enable** in PowerShell). #### Related links diff --git a/tests/cis/Test.CIS.M365.3.2.1.ps1 b/tests/cis/Test.CIS.M365.3.2.1.ps1 index 8b0fbe98a7..345342f27e 100644 --- a/tests/cis/Test.CIS.M365.3.2.1.ps1 +++ b/tests/cis/Test.CIS.M365.3.2.1.ps1 @@ -4,13 +4,13 @@ Checks that at least one data loss prevention policy is enabled. .DESCRIPTION - Checks that at least one data loss prevention policy that is not a Copilot policy is enabled. + Checks that at least one enabled data loss prevention policy defines an Exchange, SharePoint, OneDrive or Teams location. CIS Microsoft 365 Foundations Benchmark v7.0.0 (3.2.1, L1) .EXAMPLE Test-MtCisDlpPoliciesEnabled - Returns true if a non-Copilot DLP policy is enabled. + Returns true if an enabled DLP policy defines at least one required workload location. .LINK https://maester.dev/docs/tests/CIS.M365.3.2.1 @@ -36,32 +36,37 @@ param() Write-Verbose 'Getting data loss prevention policies...' - $policies = @(Get-MtExo -Request DlpCompliancePolicy | Where-Object { $_.EnforcementPlanes -notcontains 'CopilotExperiences' }) + $policies = @(Get-MtExo -Request DlpCompliancePolicy) $report = foreach ($policy in $policies) { + $locations = @('ExchangeLocation', 'SharePointLocation', 'OneDriveLocation', 'TeamsLocation' | Where-Object { + @($policy.$_ | Where-Object { $_ }).Count -gt 0 + }) [pscustomobject]@{ Name = $policy.Name Mode = $policy.Mode - Pass = $policy.Mode -eq 'Enable' + Locations = $locations -join ', ' + Pass = $policy.Mode -eq 'Enable' -and $locations.Count -gt 0 } } $testResult = @($report | Where-Object { $_.Pass }).Count -ge 1 - $passText = 'At least one non-Copilot data loss prevention policy is enabled.' - $failText = if ($policies.Count -eq 0) { 'No non-Copilot data loss prevention policy was found.' } else { 'No non-Copilot data loss prevention policy is enabled.' } + $passText = 'At least one enabled data loss prevention policy defines an Exchange, SharePoint, OneDrive or Teams location.' + $failText = 'No enabled data loss prevention policy defines an Exchange, SharePoint, OneDrive or Teams location.' - $resultMd = "| Policy | Mode | Result |`n" - $resultMd += "| --- | --- | --- |`n" + $resultMd = "| Policy | Mode | Required workload locations | Result |`n" + $resultMd += "| --- | --- | --- | --- |`n" foreach ($row in $report) { - $resultMd += "| $($row.Name) | $($row.Mode) | $(if ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" + $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $(Get-MtSafeMarkdown $row.Mode) | $($row.Locations) | $(if ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" } if ($testResult) { $testResultMarkdown = "Well done. $passText`n`n%TestResult%" - } else { + } + else { $testResultMarkdown = "$failText`n`n%TestResult%" } - $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd + $testResultMarkdown = $testResultMarkdown.Replace('%TestResult%', $resultMd) Add-MtTestResultDetail -Result $testResultMarkdown return $testResult diff --git a/tests/cis/Test.CIS.M365.3.2.2.md b/tests/cis/Test.CIS.M365.3.2.2.md index b9af8a0a3f..bd3651c6e3 100644 --- a/tests/cis/Test.CIS.M365.3.2.2.md +++ b/tests/cis/Test.CIS.M365.3.2.2.md @@ -4,12 +4,15 @@ Chat and channel messages are a quick way to paste a customer list or credential The policy must be in the **Enable** mode. Once it is on, a user who posts sensitive content in a chat or channel meets a policy tip or a block. DLP for Teams chat and channel messages needs Microsoft 365 E5 or the Microsoft Purview suite licence. +The test requires the Teams workload with **TeamsLocation** including **All**, without an administrative-unit scope. CIS permits **TeamsLocationException** entries when the organization permits them. If the only otherwise qualifying policies have exceptions, Maester lists their values and marks the result for investigation: an administrator must confirm each exception is permitted. Maester cannot infer approval from the policy configuration. Separately verify that the policy's enabled rules protect the data the organization needs. + #### Remediation action 1. Sign in to the [Microsoft Purview portal](https://purview.microsoft.com). -2. Go to **Solutions** > **Data loss prevention** > [**Policies**](https://purview.microsoft.com/datalossprevention/policies) and edit a policy, or create a new one. -3. Under **Locations**, turn on **Teams chat and channel messages** and apply it to all accounts, without excluding any account or group. -4. Set the policy mode to **Turn it on right away** and save the policy. +2. Go to **Solutions** > **Data loss prevention** > [**Policies**](https://purview.microsoft.com/datalossprevention/policies) and edit **Default policy for Teams**. If it is absent, edit another suitable policy or create a new one. +3. Under **Locations**, turn on **Teams chat and channel messages** and apply it to **All accounts**. Review any excluded accounts or groups and retain only exceptions permitted by the organization. +4. On **Customized advanced DLP rules**, turn on **Default Teams DLP policy rule** or an organization-specific rule that protects the required data, such as credit card numbers and personally identifiable information. +5. Set the policy mode to **Turn it on right away**, review the settings, and submit the policy. Verify that its mode is **On** in the portal (**Enable** in PowerShell). #### Related links diff --git a/tests/cis/Test.CIS.M365.3.2.2.ps1 b/tests/cis/Test.CIS.M365.3.2.2.ps1 index 511d8ea31a..9f6a276b0d 100644 --- a/tests/cis/Test.CIS.M365.3.2.2.ps1 +++ b/tests/cis/Test.CIS.M365.3.2.2.ps1 @@ -4,7 +4,8 @@ Checks that at least one data loss prevention policy that covers Microsoft Teams is enabled. .DESCRIPTION - Checks that at least one data loss prevention policy that is not a Copilot policy includes the Teams workload and is turned on. + Checks that at least one enabled data loss prevention policy includes the Teams workload for all accounts. + Policies with Teams location exceptions require manual review of the permitted exceptions. CIS Microsoft 365 Foundations Benchmark v7.0.0 (3.2.2, L1) .EXAMPLE @@ -36,40 +37,63 @@ param() Write-Verbose 'Getting data loss prevention policies...' - $policies = @(Get-MtExo -Request DlpCompliancePolicy | Where-Object { $_.EnforcementPlanes -notcontains 'CopilotExperiences' }) + $policies = @(Get-MtExo -Request DlpCompliancePolicy) $report = foreach ($policy in $policies) { $coversTeams = "$($policy.Workload)" -match 'Teams' - # TeamsLocation must include All with no TeamsLocationException in an enabled policy - $coversAll = (@($policy.TeamsLocation.ImmutableIdentity) -contains 'All') -and @($policy.TeamsLocationException | Where-Object { $_ }).Count -eq 0 + $teamsLocations = @($policy.TeamsLocation | ForEach-Object { + if ($_ -is [string]) { $_ } + else { $_.ImmutableIdentity ?? $_.Identity ?? $_.Name ?? $_.DisplayName } + }) + $coversAll = $teamsLocations -contains 'All' + $exceptions = @($policy.TeamsLocationException | Where-Object { $_ }) $unitScoped = @($policy.PolicyRBACScopes | Where-Object { $_ }).Count -gt 0 + $qualifies = $coversTeams -and $policy.Mode -eq 'Enable' -and $coversAll -and -not $unitScoped [pscustomobject]@{ Name = $policy.Name Mode = $policy.Mode Workload = "$($policy.Workload)" AllAccounts = $coversAll -and -not $unitScoped - Pass = $coversTeams -and $policy.Mode -eq 'Enable' -and $coversAll -and -not $unitScoped + Exceptions = (@($exceptions | ForEach-Object { + if ($_ -is [string]) { $_ } + else { ConvertTo-Json -InputObject $_ -Depth 20 -Compress } + }) -join '; ') + Pass = $qualifies -and $exceptions.Count -eq 0 + ReviewRequired = $qualifies -and $exceptions.Count -gt 0 } } - $testResult = @($report | Where-Object { $_.Pass }).Count -ge 1 + $passingPolicy = @($report | Where-Object { $_.Pass }).Count -ge 1 + $reviewRequired = -not $passingPolicy -and @($report | Where-Object { $_.ReviewRequired }).Count -gt 0 + $testResult = $passingPolicy -or $reviewRequired $passText = 'At least one data loss prevention policy that covers Microsoft Teams for all accounts is enabled.' + $reviewText = 'An enabled data loss prevention policy covers Microsoft Teams for all accounts, but its Teams location exceptions need manual review. Confirm that each listed exception is permitted by the organization.' $failText = if ($policies.Count -eq 0) { 'No data loss prevention policy was found.' } else { 'No enabled data loss prevention policy covers Microsoft Teams for all accounts.' } - $resultMd = "| Policy | Mode | Workload | All accounts | Result |`n" - $resultMd += "| --- | --- | --- | --- | --- |`n" + $resultMd = "| Policy | Mode | Workload | All accounts | Teams location exceptions | Result |`n" + $resultMd += "| --- | --- | --- | --- | --- | --- |`n" foreach ($row in $report) { $allText = if ($row.AllAccounts) { 'Yes' } else { 'No' } - $resultMd += "| $($row.Name) | $($row.Mode) | $($row.Workload) | $allText | $(if ($row.Pass) { '✅ Pass' } else { '❌ Fail' }) |`n" + $result = if ($row.Pass) { '✅ Pass' } elseif ($row.ReviewRequired) { 'Review' } else { '❌ Fail' } + $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $(Get-MtSafeMarkdown $row.Mode) | $(Get-MtSafeMarkdown $row.Workload) | $allText | $(Get-MtSafeMarkdown $row.Exceptions) | $result |`n" } - if ($testResult) { + if ($passingPolicy) { $testResultMarkdown = "Well done. $passText`n`n%TestResult%" - } else { + } + elseif ($reviewRequired) { + $testResultMarkdown = "$reviewText`n`n%TestResult%" + } + else { $testResultMarkdown = "$failText`n`n%TestResult%" } - $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd + $testResultMarkdown = $testResultMarkdown.Replace('%TestResult%', $resultMd) - Add-MtTestResultDetail -Result $testResultMarkdown + if ($reviewRequired) { + Add-MtTestResultDetail -Result $testResultMarkdown -Investigate + } + else { + Add-MtTestResultDetail -Result $testResultMarkdown + } return $testResult } diff --git a/tests/cis/Test.CIS.M365.3.2.3.md b/tests/cis/Test.CIS.M365.3.2.3.md index 1f3dc3e475..479a06b12c 100644 --- a/tests/cis/Test.CIS.M365.3.2.3.md +++ b/tests/cis/Test.CIS.M365.3.2.3.md @@ -2,22 +2,25 @@ A data loss prevention policy for the Microsoft 365 Copilot location is turned o Microsoft 365 Copilot can read and summarise everything that a user can open. Without a DLP policy for the Copilot location, a prompt can bring sensitive content into an answer, or send it to a web search, and nothing in the policy limits that. A policy lets you keep content with certain sensitivity labels or sensitive information types out of Copilot responses and processing. Copilot reads SharePoint sites and OneDrive files, so a policy on that location limits what an attacker who gets a session can collect through Copilot from them (T1213.002 and T1530). -The test requires an enabled, non-simulation Copilot policy with an active **Enforce** rule that detects sensitive information or sensitivity labels and uses a restrictive action. If the only otherwise qualifying policy has location exclusions, the result is marked for investigation so an administrator can confirm that each exception is permitted by the organization. Maester cannot determine that approval from the policy configuration alone. +The test requires an enabled, non-simulation Copilot policy for all users, without an administrative-unit scope, with an active **Enforce** rule that detects sensitive information types or sensitivity labels and uses a restrictive action. PowerShell represents both types of **Content contains** conditions through **ContentContainsSensitiveInformation**, including label groups, or through **AdvancedRule**. If the only otherwise qualifying policies have location exclusions or an unknown inclusion scope, the result is marked for investigation. The report lists the excluded locations so an administrator can confirm that each exception is permitted by the organization. Maester cannot determine that approval, or whether the selected data meets the organization's needs, from the policy configuration alone. Copilot DLP needs Microsoft 365 Copilot licences and the Microsoft Purview licences for DLP. #### Remediation action 1. Sign in to the [Microsoft Purview portal](https://purview.microsoft.com). -2. Go to **Solutions** > **Data loss prevention** > [**Policies**](https://purview.microsoft.com/datalossprevention/policies) and select **Create policy**. -3. Choose the **Custom** category and the **Custom policy** template, and under **Locations** turn on **Microsoft 365 Copilot and Copilot Chat** for all users. -4. Add a rule that blocks Copilot from processing content that has the sensitivity labels or the sensitive information types that you want to protect. -5. Set the policy mode to **Turn it on right away** and save the policy. +2. Go to **Solutions** > **Data loss prevention** > [**Policies**](https://purview.microsoft.com/datalossprevention/policies). Edit a suitable existing policy or select **Create policy**. The guided **Default DLP policy - Protect sensitive M365 Copilot interactions** policy can also be used if it meets the criteria above. +3. For a new custom policy, select **Enterprise applications & devices**, then **Custom** > **Custom policy**, and give it a name. +4. Under **Locations**, turn on **Microsoft 365 Copilot and Copilot Chat** for **All accounts**. Retain only location exclusions permitted by the organization. +5. Under **Advanced DLP rules**, select **Create rule**, name the rule, and add **Content contains** > **Sensitive info types**. Select the sensitive information types the organization needs to protect, such as credit card numbers and personally identifiable information. +6. Add **Restrict Copilot from processing content**, select the relevant restriction, and save the rule. Repeat for other required rules. To protect labeled files or emails, use a separate rule with **Content contains** > **Sensitivity labels** and the corresponding restriction; do not combine labels and sensitive information types in one rule. +7. Set the policy mode to **Turn it on right away**, review the settings, and submit the policy. Compliance requires enforcement mode, not simulation. #### Related links * [Microsoft Purview portal - Data loss prevention policies](https://purview.microsoft.com/datalossprevention/policies) * [Learn about the Microsoft 365 Copilot data loss prevention policy location](https://learn.microsoft.com/purview/dlp-microsoft365-copilot-location-learn-about) +* [New-DlpComplianceRule - ContentContainsSensitiveInformation](https://learn.microsoft.com/powershell/module/exchangepowershell/new-dlpcompliancerule#-contentcontainssensitiveinformation) * [Create and deploy data loss prevention policies](https://learn.microsoft.com/purview/dlp-create-deploy-policy) * [CIS Microsoft 365 Foundations Benchmark v7.0.0 - 3.2.3](https://www.cisecurity.org/benchmark/microsoft_365) diff --git a/tests/cis/Test.CIS.M365.3.2.3.ps1 b/tests/cis/Test.CIS.M365.3.2.3.ps1 index 2fc0f700d0..95f7bbc51e 100644 --- a/tests/cis/Test.CIS.M365.3.2.3.ps1 +++ b/tests/cis/Test.CIS.M365.3.2.3.ps1 @@ -23,7 +23,7 @@ Area = 'data-protection', ResourceType = 'Tenant', Severity = 'Medium', - UserImpact = 'Low', + UserImpact = 'Medium', ImplementationCost = 'Medium', Mitre = ('T1213.002', 'T1530'), Control = ('cis-m365:3.2.3', 'nist-800-53-r5:AC-4'), @@ -50,7 +50,7 @@ $hasCopilotScope = $copilotScope.Count -gt 0 -or $copilotLocations.Count -gt 0 if ($hasCopilotScope) { $copilotInclusions = @($copilotScope + @($copilotScope | ForEach-Object { $_.Inclusions }) + @($copilotLocations | ForEach-Object { $_.Inclusions }) | Where-Object { $_ }) - $copilotExclusions = @($copilotLocations | ForEach-Object { $_.Exclusions } | Where-Object { $_ }) + $copilotExclusions = @($copilotScope + $copilotLocations | ForEach-Object { $_.Exclusions } | Where-Object { $_ }) if ($copilotInclusions.Count -gt 0) { $locationInclusions = $copilotInclusions } elseif ($canUseTopLevelScope) { @@ -88,6 +88,7 @@ $properties = $_.PSObject.Properties $sensitiveCondition = $properties['ContentContainsSensitiveInformation'] $advancedRule = $properties['AdvancedRule'] + # This property represents both sensitive information types and sensitivity-label groups. $hasSensitiveCondition = ($sensitiveCondition -and @($sensitiveCondition.Value | Where-Object { $_ }).Count -gt 0) -or ($advancedRule -and "$($advancedRule.Value)" -match 'ContentContainsSensitiveInformation') $blockAccess = $properties['BlockAccess'] $restrictAccess = $properties['RestrictAccess'] @@ -105,7 +106,10 @@ Copilot = $isCopilot IncludesAll = if ($scopeKnown) { $includesAll } else { 'Unknown' } UnitScoped = $unitScoped - Exclusions = $locationExclusions.Count + Exclusions = (@($locationExclusions | ForEach-Object { + if ($_ -is [string]) { $_ } + else { ConvertTo-Json -InputObject $_ -Depth 20 -Compress } + }) -join '; ') Rules = $policyRules.Count RestrictingRules = $restrictingRules.Count Pass = $qualifies -and $locationExclusions.Count -eq 0 @@ -124,21 +128,24 @@ $resultMd += "| --- | --- | --- | --- | --- | --- | --- | --- | --- |`n" foreach ($row in $report) { $result = if ($row.Pass) { '✅ Pass' } elseif ($row.ReviewRequired) { 'Review' } else { '❌ Fail' } - $resultMd += "| $($row.Name) | $($row.Mode) | $($row.Copilot) | $($row.IncludesAll) | $($row.UnitScoped) | $($row.Exclusions) | $($row.Rules) | $($row.RestrictingRules) | $result |`n" + $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $(Get-MtSafeMarkdown $row.Mode) | $($row.Copilot) | $($row.IncludesAll) | $($row.UnitScoped) | $(Get-MtSafeMarkdown $row.Exclusions) | $($row.Rules) | $($row.RestrictingRules) | $result |`n" } if ($passingPolicy) { $testResultMarkdown = "Well done. $passText`n`n%TestResult%" - } elseif ($reviewRequired) { + } + elseif ($reviewRequired) { $testResultMarkdown = "$reviewText`n`n%TestResult%" - } else { + } + else { $testResultMarkdown = "$failText`n`n%TestResult%" } - $testResultMarkdown = $testResultMarkdown -replace '%TestResult%', $resultMd + $testResultMarkdown = $testResultMarkdown.Replace('%TestResult%', $resultMd) if ($reviewRequired) { Add-MtTestResultDetail -Result $testResultMarkdown -Investigate - } else { + } + else { Add-MtTestResultDetail -Result $testResultMarkdown } return $testResult From 33e07141e01c6faca0b7fc8cec25351ab7dfa3d7 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Tue, 10 Nov 2026 08:28:01 +1300 Subject: [PATCH 2/4] docs(cis): clarify full-directory scope for Teams DLP Explain that All accounts remains limited by administrative-unit scope and direct administrators to select Full directory or create an unrestricted policy. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/cis/Test.CIS.M365.3.2.2.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/cis/Test.CIS.M365.3.2.2.md b/tests/cis/Test.CIS.M365.3.2.2.md index bd3651c6e3..d235ac4d59 100644 --- a/tests/cis/Test.CIS.M365.3.2.2.md +++ b/tests/cis/Test.CIS.M365.3.2.2.md @@ -10,15 +10,17 @@ The test requires the Teams workload with **TeamsLocation** including **All**, w 1. Sign in to the [Microsoft Purview portal](https://purview.microsoft.com). 2. Go to **Solutions** > **Data loss prevention** > [**Policies**](https://purview.microsoft.com/datalossprevention/policies) and edit **Default policy for Teams**. If it is absent, edit another suitable policy or create a new one. -3. Under **Locations**, turn on **Teams chat and channel messages** and apply it to **All accounts**. Review any excluded accounts or groups and retain only exceptions permitted by the organization. -4. On **Customized advanced DLP rules**, turn on **Default Teams DLP policy rule** or an organization-specific rule that protects the required data, such as credit card numbers and personally identifiable information. -5. Set the policy mode to **Turn it on right away**, review the settings, and submit the policy. Verify that its mode is **On** in the portal (**Enable** in PowerShell). +3. For the policy's administrative-unit scope, select **Full directory**. If the existing policy's scope cannot be changed, have an unrestricted DLP administrator create a new policy with **Full directory** selected. **All accounts** within an administrative unit does not cover the full directory. +4. Under **Locations**, turn on **Teams chat and channel messages** and apply it to **All accounts**. Review any excluded accounts or groups and retain only exceptions permitted by the organization. +5. On **Customized advanced DLP rules**, turn on **Default Teams DLP policy rule** or an organization-specific rule that protects the required data, such as credit card numbers and personally identifiable information. +6. Set the policy mode to **Turn it on right away**, review the settings, and submit the policy. Verify that its mode is **On** in the portal (**Enable** in PowerShell). #### Related links * [Microsoft Purview portal - Data loss prevention policies](https://purview.microsoft.com/datalossprevention/policies) * [Create and deploy data loss prevention policies](https://learn.microsoft.com/purview/dlp-create-deploy-policy) * [Data loss prevention and Microsoft Teams](https://learn.microsoft.com/purview/dlp-microsoft-teams) +* [DLP policy reference - Administrative units](https://learn.microsoft.com/purview/dlp-policy-reference#administrative-units) * [CIS Microsoft 365 Foundations Benchmark v7.0.0 - 3.2.2](https://www.cisecurity.org/benchmark/microsoft_365) From 7725beb1ca7297a3efae96134669188f8e700589 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Tue, 10 Nov 2026 10:24:10 +1300 Subject: [PATCH 3/4] docs(cis): explain creating missing Teams DLP rules Complete the CIS 3.2.2 remediation path for policies without a suitable rule by documenting conditions, actions, saving, and enabling the rule. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- tests/cis/Test.CIS.M365.3.2.2.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/cis/Test.CIS.M365.3.2.2.md b/tests/cis/Test.CIS.M365.3.2.2.md index d235ac4d59..08a14e2bea 100644 --- a/tests/cis/Test.CIS.M365.3.2.2.md +++ b/tests/cis/Test.CIS.M365.3.2.2.md @@ -12,7 +12,7 @@ The test requires the Teams workload with **TeamsLocation** including **All**, w 2. Go to **Solutions** > **Data loss prevention** > [**Policies**](https://purview.microsoft.com/datalossprevention/policies) and edit **Default policy for Teams**. If it is absent, edit another suitable policy or create a new one. 3. For the policy's administrative-unit scope, select **Full directory**. If the existing policy's scope cannot be changed, have an unrestricted DLP administrator create a new policy with **Full directory** selected. **All accounts** within an administrative unit does not cover the full directory. 4. Under **Locations**, turn on **Teams chat and channel messages** and apply it to **All accounts**. Review any excluded accounts or groups and retain only exceptions permitted by the organization. -5. On **Customized advanced DLP rules**, turn on **Default Teams DLP policy rule** or an organization-specific rule that protects the required data, such as credit card numbers and personally identifiable information. +5. On **Customized advanced DLP rules**, if no suitable rule exists, select **Create rule**, configure conditions for the required data and appropriate actions, and save the rule. Turn on **Default Teams DLP policy rule** or an organization-specific rule that protects the required data, such as credit card numbers and personally identifiable information. 6. Set the policy mode to **Turn it on right away**, review the settings, and submit the policy. Verify that its mode is **On** in the portal (**Enable** in PowerShell). #### Related links From a4ddb9383f7ca89b68b73238c7a4a59522b5e621 Mon Sep 17 00:00:00 2001 From: Jeremy Finney Date: Thu, 12 Nov 2026 07:54:48 +1300 Subject: [PATCH 4/4] fix(cis): require an enabled Teams DLP rule --- .../functions/Test-MtCisDlpPolicies.Tests.ps1 | 24 +++++++++++++ tests/cis/Test.CIS.M365.3.2.2.md | 4 +-- tests/cis/Test.CIS.M365.3.2.2.ps1 | 34 +++++++++++++------ 3 files changed, 50 insertions(+), 12 deletions(-) diff --git a/powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 b/powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 index 24db88a1c1..fabcb6c4ab 100644 --- a/powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 +++ b/powershell/tests/functions/Test-MtCisDlpPolicies.Tests.ps1 @@ -109,6 +109,7 @@ Describe 'CIS 3.2 DLP audit alignment' { Context '3.2.2 Teams all accounts and permitted exceptions' { BeforeEach { $script:Policies = @(Get-DlpPolicyFixture -Properties @{ Workload = 'Exchange, Teams'; TeamsLocation = @([pscustomobject]@{ ImmutableIdentity = 'All' }) }) + $script:Rules = @(Get-DlpRuleFixture) } It 'passes without exceptions' { @@ -116,6 +117,28 @@ Describe 'CIS 3.2 DLP audit alignment' { $script:Investigate | Should -BeFalse } + It 'fails when no enabled rule exists, even with permitted exceptions' { + $script:Rules = @() + $script:Policies[0].TeamsLocationException = @('allowed@contoso.com') + + Test-MtCisTeamsDlpPolicy | Should -BeFalse + $script:Investigate | Should -BeFalse + } + + It 'fails when the only matching rule is disabled' { + $script:Rules = @(Get-DlpRuleFixture -Properties @{ Disabled = $true }) + + Test-MtCisTeamsDlpPolicy | Should -BeFalse + $script:Investigate | Should -BeFalse + } + + It 'does not count an enabled rule for another policy' { + $script:Rules = @(Get-DlpRuleFixture -Properties @{ ParentPolicyName = 'Other policy' }) + + Test-MtCisTeamsDlpPolicy | Should -BeFalse + $script:Investigate | Should -BeFalse + } + It 'accepts string and DisplayName representations of All' -ForEach @( @{ Value = @('All') } @{ Value = @([pscustomobject]@{ DisplayName = 'All' }) } @@ -145,6 +168,7 @@ Describe 'CIS 3.2 DLP audit alignment' { It 'passes if another qualifying policy has no exceptions' { $script:Policies[0].TeamsLocationException = @('allowed@contoso.com') $script:Policies += Get-DlpPolicyFixture -Properties @{ Name = 'Unrestricted'; Workload = 'Teams'; TeamsLocation = @('All') } + $script:Rules += Get-DlpRuleFixture -Properties @{ ParentPolicyName = 'Unrestricted' } Test-MtCisTeamsDlpPolicy | Should -BeTrue $script:Investigate | Should -BeFalse diff --git a/tests/cis/Test.CIS.M365.3.2.2.md b/tests/cis/Test.CIS.M365.3.2.2.md index 08a14e2bea..29fb410c28 100644 --- a/tests/cis/Test.CIS.M365.3.2.2.md +++ b/tests/cis/Test.CIS.M365.3.2.2.md @@ -1,10 +1,10 @@ -At least one data loss prevention policy includes the Microsoft Teams location and is turned on. +At least one data loss prevention policy includes the Microsoft Teams location, has an enabled rule, and is turned on. Chat and channel messages are a quick way to paste a customer list or credentials, and files that users share in Teams end up in SharePoint and OneDrive. A DLP policy that covers Teams can block or warn about sensitive information in chat messages and channel conversations, in addition to the files. The policy covers the Teams content that an attacker collects from (T1213), the files stored behind it in SharePoint and OneDrive (T1530), and it stops sensitive content from leaving through a web service such as a message or an upload (T1567). The policy must be in the **Enable** mode. Once it is on, a user who posts sensitive content in a chat or channel meets a policy tip or a block. DLP for Teams chat and channel messages needs Microsoft 365 E5 or the Microsoft Purview suite licence. -The test requires the Teams workload with **TeamsLocation** including **All**, without an administrative-unit scope. CIS permits **TeamsLocationException** entries when the organization permits them. If the only otherwise qualifying policies have exceptions, Maester lists their values and marks the result for investigation: an administrator must confirm each exception is permitted. Maester cannot infer approval from the policy configuration. Separately verify that the policy's enabled rules protect the data the organization needs. +The test requires the Teams workload with **TeamsLocation** including **All**, without an administrative-unit scope, and at least one enabled DLP rule attached to the policy. CIS permits **TeamsLocationException** entries when the organization permits them. If the only otherwise qualifying policies have exceptions, Maester lists their values and marks the result for investigation: an administrator must confirm each exception is permitted. Maester cannot infer approval from the policy configuration. The check confirms that a rule is enabled but does not assess whether its conditions protect the data the organization needs; verify the rule separately. #### Remediation action diff --git a/tests/cis/Test.CIS.M365.3.2.2.ps1 b/tests/cis/Test.CIS.M365.3.2.2.ps1 index 9f6a276b0d..69dc545476 100644 --- a/tests/cis/Test.CIS.M365.3.2.2.ps1 +++ b/tests/cis/Test.CIS.M365.3.2.2.ps1 @@ -1,17 +1,17 @@ function Test-MtCisTeamsDlpPolicy { <# .SYNOPSIS - Checks that at least one data loss prevention policy that covers Microsoft Teams is enabled. + Checks that an enabled Teams data loss prevention policy covers all accounts and has an enabled rule. .DESCRIPTION - Checks that at least one enabled data loss prevention policy includes the Teams workload for all accounts. + Checks that at least one enabled data loss prevention policy includes the Teams workload for all accounts and has an enabled rule. Policies with Teams location exceptions require manual review of the permitted exceptions. CIS Microsoft 365 Foundations Benchmark v7.0.0 (3.2.2, L1) .EXAMPLE Test-MtCisTeamsDlpPolicy - Returns true if an enabled DLP policy covers Microsoft Teams. + Returns true if an enabled DLP policy covers Microsoft Teams and has an enabled rule. .LINK https://maester.dev/docs/tests/CIS.M365.3.2.2 @@ -38,6 +38,7 @@ Write-Verbose 'Getting data loss prevention policies...' $policies = @(Get-MtExo -Request DlpCompliancePolicy) + $rules = @(Get-MtExo -Request DlpComplianceRule) $report = foreach ($policy in $policies) { $coversTeams = "$($policy.Workload)" -match 'Teams' @@ -48,12 +49,25 @@ $coversAll = $teamsLocations -contains 'All' $exceptions = @($policy.TeamsLocationException | Where-Object { $_ }) $unitScoped = @($policy.PolicyRBACScopes | Where-Object { $_ }).Count -gt 0 - $qualifies = $coversTeams -and $policy.Mode -eq 'Enable' -and $coversAll -and -not $unitScoped + $enabledRules = @($rules | Where-Object { + $_.ParentPolicyName -eq $policy.Name -and + $_.PSObject.Properties['Disabled'] -and + $_.Disabled -is [bool] -and + -not $_.Disabled + }) + $qualifies = ( + $coversTeams -and + $policy.Mode -eq 'Enable' -and + $coversAll -and + -not $unitScoped -and + $enabledRules.Count -gt 0 + ) [pscustomobject]@{ Name = $policy.Name Mode = $policy.Mode Workload = "$($policy.Workload)" AllAccounts = $coversAll -and -not $unitScoped + EnabledRules = $enabledRules.Count Exceptions = (@($exceptions | ForEach-Object { if ($_ -is [string]) { $_ } else { ConvertTo-Json -InputObject $_ -Depth 20 -Compress } @@ -66,16 +80,16 @@ $reviewRequired = -not $passingPolicy -and @($report | Where-Object { $_.ReviewRequired }).Count -gt 0 $testResult = $passingPolicy -or $reviewRequired - $passText = 'At least one data loss prevention policy that covers Microsoft Teams for all accounts is enabled.' - $reviewText = 'An enabled data loss prevention policy covers Microsoft Teams for all accounts, but its Teams location exceptions need manual review. Confirm that each listed exception is permitted by the organization.' - $failText = if ($policies.Count -eq 0) { 'No data loss prevention policy was found.' } else { 'No enabled data loss prevention policy covers Microsoft Teams for all accounts.' } + $passText = 'At least one enabled data loss prevention policy covers Microsoft Teams for all accounts and has an enabled rule.' + $reviewText = 'An enabled data loss prevention policy with an enabled rule covers Microsoft Teams for all accounts, but its Teams location exceptions need manual review. Confirm that each listed exception is permitted by the organization.' + $failText = if ($policies.Count -eq 0) { 'No data loss prevention policy was found.' } else { 'No enabled data loss prevention policy covers Microsoft Teams for all accounts with an enabled rule.' } - $resultMd = "| Policy | Mode | Workload | All accounts | Teams location exceptions | Result |`n" - $resultMd += "| --- | --- | --- | --- | --- | --- |`n" + $resultMd = "| Policy | Mode | Workload | All accounts | Enabled rules | Teams location exceptions | Result |`n" + $resultMd += "| --- | --- | --- | --- | --- | --- | --- |`n" foreach ($row in $report) { $allText = if ($row.AllAccounts) { 'Yes' } else { 'No' } $result = if ($row.Pass) { '✅ Pass' } elseif ($row.ReviewRequired) { 'Review' } else { '❌ Fail' } - $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $(Get-MtSafeMarkdown $row.Mode) | $(Get-MtSafeMarkdown $row.Workload) | $allText | $(Get-MtSafeMarkdown $row.Exceptions) | $result |`n" + $resultMd += "| $(Get-MtSafeMarkdown $row.Name) | $(Get-MtSafeMarkdown $row.Mode) | $(Get-MtSafeMarkdown $row.Workload) | $allText | $($row.EnabledRules) | $(Get-MtSafeMarkdown $row.Exceptions) | $result |`n" } if ($passingPolicy) {