Skip to content

Commit 3905cb0

Browse files
authored
Make AppLocker Enforce mode take precedence over UMCI Audit mode (#14353)
1 parent 9724293 commit 3905cb0

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/System.Management.Automation/security/wldpNativeMethods.cs

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -78,36 +78,39 @@ public static SystemEnforcementMode GetSystemLockdownPolicy()
7878
/// <returns>An EnforcementMode that describes policy.</returns>
7979
public static SystemEnforcementMode GetLockdownPolicy(string path, SafeHandle handle)
8080
{
81-
// Check the WLDP API
82-
SystemEnforcementMode lockdownPolicy = GetWldpPolicy(path, handle);
83-
if (lockdownPolicy == SystemEnforcementMode.Enforce)
81+
// Check the WLDP File policy via API
82+
var wldpFilePolicy = GetWldpPolicy(path, handle);
83+
if (wldpFilePolicy == SystemEnforcementMode.Enforce)
8484
{
85-
return lockdownPolicy;
85+
return wldpFilePolicy;
86+
}
87+
88+
// Check the AppLocker File policy via API
89+
// This needs to be checked before WLDP audit policy
90+
// So, that we don't end up in Audit mode,
91+
// when we should be enforce mode.
92+
var appLockerFilePolicy = GetAppLockerPolicy(path, handle);
93+
if (appLockerFilePolicy == SystemEnforcementMode.Enforce)
94+
{
95+
return appLockerFilePolicy;
8696
}
8797

8898
// At this point, LockdownPolicy = Audit or Allowed.
8999
// If there was a WLDP policy, but WLDP didn't block it,
90100
// then it was explicitly allowed. Therefore, return the result for the file.
91101
SystemEnforcementMode systemWldpPolicy = s_cachedWldpSystemPolicy.GetValueOrDefault(SystemEnforcementMode.None);
92-
if ((systemWldpPolicy == SystemEnforcementMode.Enforce) ||
93-
(systemWldpPolicy == SystemEnforcementMode.Audit))
94-
{
95-
return lockdownPolicy;
96-
}
97-
98-
// Check the AppLocker API
99-
lockdownPolicy = GetAppLockerPolicy(path, handle);
100-
if (lockdownPolicy == SystemEnforcementMode.Enforce)
102+
if ((systemWldpPolicy == SystemEnforcementMode.Audit) ||
103+
(systemWldpPolicy == SystemEnforcementMode.Enforce))
101104
{
102-
return lockdownPolicy;
105+
return wldpFilePolicy;
103106
}
104107

105108
// If there was a system-wide AppLocker policy, but AppLocker didn't block it,
106109
// then return AppLocker's status.
107110
if (s_cachedSaferSystemPolicy.GetValueOrDefault(SaferPolicy.Allowed) ==
108111
SaferPolicy.Disallowed)
109112
{
110-
return lockdownPolicy;
113+
return appLockerFilePolicy;
111114
}
112115

113116
// If it's not set to 'Enforce' by the platform, allow debug overrides

0 commit comments

Comments
 (0)