Skip to content

Commit 94a5021

Browse files
committed
Make AppLocker Enforce mode take precedence over UMCI Audit mode (#14353)
1 parent 02bbf0f commit 94a5021

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
@@ -72,36 +72,39 @@ public static SystemEnforcementMode GetSystemLockdownPolicy()
7272
/// <returns>An EnforcementMode that describes policy.</returns>
7373
public static SystemEnforcementMode GetLockdownPolicy(string path, SafeHandle handle)
7474
{
75-
// Check the WLDP API
76-
SystemEnforcementMode lockdownPolicy = GetWldpPolicy(path, handle);
77-
if (lockdownPolicy == SystemEnforcementMode.Enforce)
75+
// Check the WLDP File policy via API
76+
var wldpFilePolicy = GetWldpPolicy(path, handle);
77+
if (wldpFilePolicy == SystemEnforcementMode.Enforce)
7878
{
79-
return lockdownPolicy;
79+
return wldpFilePolicy;
80+
}
81+
82+
// Check the AppLocker File policy via API
83+
// This needs to be checked before WLDP audit policy
84+
// So, that we don't end up in Audit mode,
85+
// when we should be enforce mode.
86+
var appLockerFilePolicy = GetAppLockerPolicy(path, handle);
87+
if (appLockerFilePolicy == SystemEnforcementMode.Enforce)
88+
{
89+
return appLockerFilePolicy;
8090
}
8191

8292
// At this point, LockdownPolicy = Audit or Allowed.
8393
// If there was a WLDP policy, but WLDP didn't block it,
8494
// then it was explicitly allowed. Therefore, return the result for the file.
8595
SystemEnforcementMode systemWldpPolicy = s_cachedWldpSystemPolicy.GetValueOrDefault(SystemEnforcementMode.None);
86-
if ((systemWldpPolicy == SystemEnforcementMode.Enforce) ||
87-
(systemWldpPolicy == SystemEnforcementMode.Audit))
88-
{
89-
return lockdownPolicy;
90-
}
91-
92-
// Check the AppLocker API
93-
lockdownPolicy = GetAppLockerPolicy(path, handle);
94-
if (lockdownPolicy == SystemEnforcementMode.Enforce)
96+
if ((systemWldpPolicy == SystemEnforcementMode.Audit) ||
97+
(systemWldpPolicy == SystemEnforcementMode.Enforce))
9598
{
96-
return lockdownPolicy;
99+
return wldpFilePolicy;
97100
}
98101

99102
// If there was a system-wide AppLocker policy, but AppLocker didn't block it,
100103
// then return AppLocker's status.
101104
if (s_cachedSaferSystemPolicy.GetValueOrDefault(SaferPolicy.Allowed) ==
102105
SaferPolicy.Disallowed)
103106
{
104-
return lockdownPolicy;
107+
return appLockerFilePolicy;
105108
}
106109

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

0 commit comments

Comments
 (0)