processcontainer: sandboxed process can read persistent user environment variables from HKCU\Environment
Summary
A process started with containment: "processcontainer" can read the host user's persistent environment variables from HKCU\Environment. This includes reg query and [Environment]::GetEnvironmentVariable(name, 'User'). The sandboxed process gets a clean process environment block, but the persistent values stored in the registry are still readable in full.
The policy schema has no way to restrict registry access, so the config cannot prevent this.
Environment
- Windows 11 25H2, build 26200.9711
wxc-exec.exebuilt frommicrosoft/mxc(version/commit:)
Steps to reproduce
-
In a normal (non-sandboxed) terminal, create a persistent user variable:
setx MXC_REG_DEMO "not-a-real-secret-12345" -
Save this as
repro.json:{ "version": "1.0.0", "containerId": "registry-env-repro", "containment": "processcontainer", "process": { "commandLine": "cmd.exe /c reg query HKCU\\Environment /v MXC_REG_DEMO", "timeout": 10000 }, "filesystem": { "readonlyPaths": [ "C:\\Windows" ] } } -
Run it:
wxc-exec.exe repro.json -
Optionally, repeat with a PowerShell command line to check the .NET path:
powershell.exe -NoProfile -Command "[Environment]::GetEnvironmentVariable('MXC_REG_DEMO','User')"
Expected behavior
With no registryRead capability and no registry grant in the config, the sandboxed process cannot read the value of MXC_REG_DEMO from HKCU\Environment. It gets access denied or an empty result.
Actual behavior
The sandboxed process prints the real value:
HKEY_CURRENT_USER\Environment
MXC_REG_DEMO REG_SZ not-a-real-secret-12345
The PowerShell variant also returns not-a-real-secret-12345.
Impact
Callers that scrub or replace sensitive variables in the sandbox process environment expect the sandboxed code not to see them. The persistent registry copy bypasses that scrubbing, and the config has no option to close it. Any value stored with setx or the System Properties dialog is readable by sandboxed code.
Notes
- In the current policy schema (PSEC layout and the
mxc-configschema) I found no registry-related field to restrict this. The only registry-related knob I found is theregistryReadcapability. - I have not tested whether other
HKCUlocations are also readable.
@caarlos0 I reproduced this through both reg query and the .NET API with a clean process environment. Both still read HKCU\Environment when capabilities are omitted or empty.
Looking at #1496, #1182 and #1558, LPAC is unsupported on the current PSEC path and the older implementations were removed. Is there a supported way to block these registry reads without modifying host ACLs, or does this need additional Windows support?
I have an uncommitted regression test covering both APIs, omitted/empty capabilities, and explicit registryRead controls. I’d like to confirm the intended enforcement approach before implementing the fix