| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
To find the system-wide AppLocker policy, PowerShell writes two __PSScriptPolicyTest_* files to %TEMP% on every start, checks them with SAFER, and deletes them. When the machine has no AppLocker script rules and no Software Restriction Policy, the result is always Allowed. Check the places such a policy lives first and skip the test files when none of them has a policy: the compiled AppLocker script policy (%windir%\System32\AppLocker\Script.AppLocker), AppLocker script rules under HKLM\SOFTWARE\Policies\Microsoft\Windows\SrpV2\Script, and SRP under SOFTWARE\Policies\Microsoft\Windows\Safer\CodeIdentifiers in HKLM and HKCU. A CodeIdentifiers key with only AuthenticodeEnabled is treated as no policy. Anything that exists or cannot be read keeps the test. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
|
Azure Pipelines: There may be pipelines that require an authorized user to comment /azp run to run. |
Sorry, something went wrong.
There was a problem hiding this comment.
The WOW64 path lookup can miss an effective AppLocker policy and leave the session in FullLanguage, while additional policy-detection and test-reliability issues remain unresolved.
5 open issuesThis PR addresses #28372 by reducing PowerShell startup overhead when no AppLocker script policy or Software Restriction Policy is detected, avoiding temporary policy-test files and their SAFER checks.
Changes:
| File | Description |
|---|---|
| test/xUnit/csharp/test_SystemPolicy.cs | Tests registry, file, and machine-policy detection. |
| test/powershell/engine/Security/AppLockerProbe.Tests.ps1 | Monitors temporary probe-file creation in a child PowerShell process. |
| src/System.Management.Automation/security/wldpNativeMethods.cs | Adds policy-presence checks and skips the SAFER probe when no policy is detected. |
Review effort: Balanced
Sorry, something went wrong.
- Keep the AppLocker probe in 32-bit processes on 64-bit Windows, where the system directory is redirected. - Treat an existing SrpV2\Script key as a policy even when it is empty. - Fail the Pester test if the child pwsh exits with an error, and do not expect the test files when WDAC enforces lockdown. - Use the same helpers in the xUnit machine check. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
| Back | FazBrowse Home | New Git URL |
PR Summary
Fixes #28372.
On every start, SystemPolicy.GetSystemLockdownPolicy() finds the system-wide AppLocker policy by writing two __PSScriptPolicyTest_* files to %TEMP%, checking them with SaferIdentifyLevel/SaferComputeTokenFromLevel, and deleting them. When the machine has no AppLocker script rules and no Software Restriction Policy, the answer is always "allowed".
This adds a check before the test files are written. They are skipped only when none of these has a policy:
A location counts as "no policy" only if it does not exist. The one exception is the CodeIdentifiers key: Windows can create it with just AuthenticodeEnabled and nothing else, and that key with no subkeys and no other values does not define an SRP policy (creating one adds DefaultLevel, TransparentEnabled, rule subkeys and so on). If anything exists or cannot be read, the test files are written as before. WDAC and the per-file checks are unchanged.
PR Context
Measured on Windows 11 26100 (i9-10900K), Release builds of master 1aac7f5 with and without this change (the two outputs differ only in System.Management.Automation.dll), 40 interleaved runs, median of the paired differences with 95% confidence interval:
On this machine (no AppLocker or SRP policy) the build without the change writes two test files to %TEMP% per start and the build with it writes none; both report GetSystemLockdownPolicy() = None and FullLanguage.
Tests:
I could not test with a real AppLocker or SRP policy because writing those policy keys needs admin rights. To check enforcement on a test machine (as admin):
I used GitHub Copilot to investigate this and to help write the change and tests; I reviewed the code and ran the tests above myself.
PR Checklist