Skip to content

[1.8-stable] Gated port: MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY child-process isolation (#5987)#6631

Merged
Scottj1s merged 2 commits into
release/1.8-stablefrom
users/sjones/mrt-basedir-1.8-cp
Jul 20, 2026
Merged

[1.8-stable] Gated port: MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY child-process isolation (#5987)#6631
Scottj1s merged 2 commits into
release/1.8-stablefrom
users/sjones/mrt-basedir-1.8-cp

Conversation

@Scottj1s

Copy link
Copy Markdown
Member

Servicing port of #6619 (main) into release/1.8-stable, gated behind a runtime-compatibility containment change so apps can revert.

Problem

MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY is set by the Windows App SDK auto-initializer (a requirement for PublishSingleFile SxS manifest redirection). As a process environment variable it is inherited by CreateProcess children, so a child's MRTCore resolved the parent's resources.pri, and reg-free WinRT redirection could be steered by a parent-controlled directory.

Fix (gated on WINAPPSDK_CHANGEID_63098344)

The setter now also stamps MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY_PID with the owning process id. 1.8 uses the ContainmentV1 model, so the change ID bakes in the target patch version: #define WINAPPSDK_CHANGEID_63098344 63098344, WinAppSDK_1_8_11.

  • Enabled (default): MRM.cpp and catalog.cpp honor the base directory only when the stamp matches the current process; inherited (foreign) values fall back to the module directory.
  • Disabled (via RuntimeCompatibilityOptions): the base directory is honored regardless of the stamp — byte-for-byte prior behavior.

Changes

  • UndockedRegFreeWinRT-AutoInitializer.cs — stamp the owning process id (ungated; consumers ignore it when the change is disabled).
  • MRM.cpp — add WINAPPSDK_CHANGEID_63098344 + gate the base-directory PID guard.
  • catalog.cpp — gate the %MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY% strip on the change (WindowsAppRuntime_DLL already links the FrameworkUdk containment worker).
  • MrmTests.cppEnvironmentVariableIsolationTests (enabled: in-process guard + real cross-process insulation) and BaseDirectoryContainmentDisabledTest (IsolationLevel=Method; disables 63098344 and verifies the inherited base directory is honored).

The base-directory naming refactor from #6619 is intentionally not ported (servicing = minimal change); the setter stays in UndockedRegFreeWinRT-AutoInitializer.cs.

Validation

Local (VS x64 Debug): MRM.vcxproj + MrmUnitTest.vcxproj build clean; MrmUnitTest 25/26 (1 skipped child-only worker), covering both enabled and disabled states; catalog.cpp additions syntax-checked (cl /W4).

…hild-process isolation (#5987)

Ports the base-directory PID-guard fix (main #6619) into release/1.8-stable, gated behind a
runtime-compatibility containment change (WINAPPSDK_CHANGEID_63098344) so apps can revert.

MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY is set by the Windows App SDK auto-initializer (a
requirement for PublishSingleFile SxS manifest redirection). Because it is a process environment
variable it is inherited by child processes spawned via CreateProcess, so a child's MRTCore resolved
the parent's resources.pri and reg-free WinRT redirection could be steered by a parent-controlled
directory.

The setter now also stamps MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY_PID with the owning process id.
Gated behind WINAPPSDK_CHANGEID_63098344 (2-arg ContainmentV1 form, target WinAppSDK_1_8_11):
- Enabled (default): MRM.cpp and catalog.cpp honor the base directory only when the stamp matches the
  current process; inherited (foreign) values fall back to the module directory.
- Disabled (via RuntimeCompatibilityOptions): the base directory is honored regardless of the stamp
  (byte-for-byte prior behavior).

Changes:
- UndockedRegFreeWinRT-AutoInitializer.cs: stamp the owning process id (ungated; consumers ignore it
  when the change is disabled).
- MRM.cpp: add WINAPPSDK_CHANGEID_63098344 and gate the base-directory PID guard.
- catalog.cpp: gate the %MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY% strip on the change
  (WindowsAppRuntime_DLL already links the FrameworkUdk containment worker).
- MrmTests.cpp: EnvironmentVariableIsolationTests (enabled: in-process guard + real cross-process
  insulation) and BaseDirectoryContainmentDisabledTest (IsolationLevel=Method; disables 63098344 and
  verifies the inherited base directory is honored).

Verified locally (x64 Debug): MrmUnitTest 25/26 (1 skipped child-only worker), both enabled and
disabled cases.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: dac4165f-ec13-4406-9206-60cd55b24c2b
@Scottj1s
Scottj1s requested a review from a team July 17, 2026 13:29
@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
There may be pipelines that require an authorized user to comment /azp run to run.

agniuks
agniuks previously approved these changes Jul 17, 2026
@agniuks

agniuks commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.

…ent (#5987)

RCA of a PR-validation regression in CompatibilityTests (CanSetRuntimeCompatibilityOptions and
VerifyDisabledChanges failing intermittently with E_ILLEGAL_STATE_CHANGE, "Configuration already set
or locked"):

WinAppSdk::Containment::IsChangeEnabled<>() locks the process's runtime-compatibility configuration on
first call. catalog.cpp's WinRTLoadComponentFromString runs during reg-free WinRT activation - before
an app (or test) can call RuntimeCompatibilityOptions.Apply(). Calling IsChangeEnabled unconditionally
there locked the configuration early, so a subsequent Apply() failed.

The manifest only references %MICROSOFT_WINDOWSAPPRUNTIME_BASE_DIRECTORY% for PublishSingleFile apps,
so only consult the containment change when that token is actually present. Non-single-file activation
(the common case, including CompatibilityTests) no longer calls IsChangeEnabled and no longer locks
the configuration. MRTCore MrmUnitTest is unaffected (catalog.cpp is not in that binary).

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: dac4165f-ec13-4406-9206-60cd55b24c2b
@Scottj1s

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines:
Successfully started running 1 pipeline(s).
2 pipeline(s) were filtered out due to trigger conditions.

@Scottj1s
Scottj1s merged commit 27e2201 into release/1.8-stable Jul 20, 2026
40 checks passed
@Scottj1s
Scottj1s deleted the users/sjones/mrt-basedir-1.8-cp branch July 20, 2026 21:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants