From d507e77016c7bcc13e700011b4e4291868ad2ece Mon Sep 17 00:00:00 2001 From: Vera Petrenkova Date: Tue, 19 Nov 2024 11:34:07 +0100 Subject: [PATCH] IJPL-164957 Refine Windows Defender exclusions path comparison Enhanced the `Test-Excluded` function to better handle directory paths by checking if the exclusion is a directory and ensuring it has more path segments than the excluded path. This improves the accuracy of determining whether a path should be excluded. GitOrigin-RevId: e494da49d0722bbd599704d9e51c9d37e9a37987 --- bin/win/defender-exclusions.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bin/win/defender-exclusions.ps1 b/bin/win/defender-exclusions.ps1 index fb0da043b4fd..2c1dd6a641f8 100644 --- a/bin/win/defender-exclusions.ps1 +++ b/bin/win/defender-exclusions.ps1 @@ -37,7 +37,7 @@ try { # returns `$true` when a path is already covered by the exclusion list function Test-Excluded ([string] $path, [string[]] $exclusions) { foreach ($exclusion in $exclusions) { - if ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $exclusion, @("IgnoreCase"))) { + if (((Get-Item -Path $exclusion) -is [System.IO.DirectoryInfo]) -and ([cultureinfo]::InvariantCulture.CompareInfo.IsPrefix($path, $exclusion, @("IgnoreCase"))) -and ($exclusion.TrimEnd('\').split('\').Count -gt $path.TrimEnd('\').Split('\').Count)) { return $true } }