Skip to content

xaml-triage child: verify what it loads instead of trusting its arguments - #1046

Merged
Nikola Metulev (nmetulev) merged 13 commits into
mainfrom
fix-xaml-triage-child-signature
Oct 16, 2026
Merged

Nikola Metulev (nmetulev) merged 13 commits into
mainfrom
fix-xaml-triage-child-signature

Conversation

@nmetulev

@nmetulev Nikola Metulev (nmetulev) commented Oct 9, 2026 •

Copy link
Copy Markdown
Member

Description

winapp __xaml-triage is a hidden verb: during crash analysis, winapp starts it as a separate process to host the Windows debugger engine (DbgEng). It loaded whatever --bin (dbgeng.dll and its DLLs), --jsprovider and --ext (a debugger script) it was given. Only the parent process verified them, so anyone could start a signed winapp.exe directly and point it at an arbitrary DLL.

The child process now verifies what it loads instead of trusting its arguments:

  • The debugger DLLs: dbgeng.dll, its supporting DLLs and JsProvider.dll must be Microsoft-signed and from the same build, using the parent's own check (reused, not duplicated). Each file is held open with no write or delete sharing until the engine is done, so it can't be swapped between the check and the load.
  • The script: --ext must be the pinned winui-dbgext.js. A debugger script can .load any DLL, so checking the DLLs alone isn't enough.

Anything else is refused with a plain error.

Usage Example

I used a harmless test DLL whose DllMain writes a marker file naming the process that loaded it.

Arbitrary dbgeng.dll: winapp __xaml-triage --dump x.dmp --bin <temp>\bin --jsprovider <temp>\bin\JsProvider.dll --ext ext.js

Before (main):

xaml-triage failed: Unable to find an entry point named 'DebugCreate' in DLL 'dbgeng.dll'.
MARKER: arbitrary dbgeng.dll loaded into ...\cli-main\winapp.exe (pid 19624)

After:

xaml-triage failed: refusing to load the debugger from '...\bin' and '...\bin\JsProvider.dll': they must be Microsoft-signed debugger files from the same build.
(no marker: the DLL was never loaded)

Genuine Microsoft-signed debugger files plus a custom --ext script that .loads the test DLL:

  • Before (main): exit 0, and the marker reports the test DLL loaded into ...\cli-main\winapp.exe.
  • After: xaml-triage failed: refusing to run '...\evil.js': it is not the pinned WinUI debugger extension. No marker.

Real use (genuine signed files, pinned script, a real minidump): still exits 0 and runs the WinUI triage commands.

Related Issue

Follow-up to #954. The same class of issue as the DevTools injection worker fix in #943.

Type of Change

  • 🐛 Bug fix

Checklist

  • New tests added for new functionality (if applicable). Run_UnsignedEngine_IsRefusedBeforeLoading fails on main with xaml-triage failed: Could not load '...\bin\dbgeng.dll', which shows the child really tries to load the file. Another new test covers refusing a non-pinned script.
  • Tested locally on Windows

Additional Notes

  • Not covered: a process already running as the same user can still get a DLL loaded, for example by planting a default debugger extension where DbgEng searches (PATH, _NT_DEBUGGER_EXTENSION_PATH, %LOCALAPPDATA%\Dbg\EngineExtensions, or a folder holding copies of the signed engine), or by planting a DLL next to a copy of winapp.exe. That user can already run code, so this PR doesn't try to stop them. Resolve winapp.exe's own DLL imports from System32 only #1073 stops winapp.exe loading its own imports (such as version.dll) from its folder. It can't cover DLLs that Windows' own DLLs import, so installing to a folder the user can't write to remains the real protection.

… arguments

The hidden __xaml-triage verb hosts DbgEng in winapp.exe and loaded whatever
--bin, --jsprovider and --ext it was given; only the parent verified them. A
signed winapp could therefore be started directly to load an arbitrary DLL.

The child now, before loading anything:
- holds and verifies dbgeng.dll, its supporting DLLs and JsProvider.dll with the
  parent's own check (Microsoft-signed, same build), with no write or delete sharing;
- requires --ext to be the pinned winui-dbgext.js (a script can .load any DLL);
- copies the verified engine files into a folder it creates and runs the engine
  from there, because DbgEng also loads default extension DLLs found beside the
  engine (the pinned script triggers that); the copies are held and re-verified.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nmetulev Nikola Metulev (nmetulev) added the agent-preparing Agent is addressing feedback or completing required validation and CI label Oct 9, 2026
Review found two ways around the private engine folder:
- DbgEng takes extension and symbol-server search paths from _NT_* variables,
  which whoever starts the child controls; they are now cleared first.
- Another process running as the same user could add a default-extension DLL
  to the folder before the engine searched it. The folder is now locked after
  the copy (OWNER RIGHTS removes the owner's ability to change permissions back),
  and anything present besides the copied files is refused.

Also fixes CA1861 in the new test.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Administrators keep full control of the folder, so an elevated process (as on CI)
is not denied. The staged-contents check still runs everywhere.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Oct 9, 2026 •

Copy link
Copy Markdown
Contributor

⏳ Build in progress — metrics below are from a previous commit and will update when the current build finishes.

Build Metrics Report

Validation passed. All required build and validation jobs succeeded.

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 64.72 MB 64.73 MB 📈 +5.0 KB (+0.01%)
CLI (x64) 64.66 MB 64.67 MB 📈 +4.5 KB (+0.01%)
MSIX (ARM64) 26.80 MB 26.79 MB 📉 -7.2 KB (-0.03%)
MSIX (x64) 28.40 MB 28.40 MB 📈 +1.3 KB (+0.00%)
NPM Package 55.83 MB 55.83 MB 📉 -0.5 KB (-0.00%)
NuGet Package 55.96 MB 55.96 MB 📈 +1.2 KB (+0.00%)

.NET Test Results (TRX reports)

Other suites are reflected in the overall validation status above.

✅ 10465 passed, 43 skipped out of 10508 tests in 1935.2s (+2 tests, +100.3s vs. baseline)

Test Coverage

✅ 87.2% line coverage, 81.4% branch coverage · ✅ no change vs. baseline

CLI Startup Time

63ms median (x64, winapp --version) · 📉 -11ms vs. baseline


Updated 2026-10-16 17:17:14 UTC · commit a2f9c70 · workflow run

Use 'using' for the original debugger holds and the staged folder in tests, and
Path.Join in the new tests.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nmetulev
Nikola Metulev (nmetulev) marked this pull request as ready for review October 9, 2026 19:20
Copilot AI balanced review requested due to automatic review settings October 9, 2026 19:20
@nmetulev Nikola Metulev (nmetulev) added ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge and removed agent-preparing Agent is addressing feedback or completing required validation and CI labels Oct 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot encountered an error and was unable to review this pull request. You can try again by re-requesting a review.

Note

This error may be related to your runner configuration. You can now configure runners for Copilot code review separately from Copilot cloud agent by creating a copilot-code-review.yml file with your setup steps. Read the docs for details.

@zateutsch Zach Teutsch (zateutsch) left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤖 AI-generated review (winappcli pr-review skill) — verify before acting.

Changes requested. The hardening is the right shape, and every layer is needed for the threat it targets. But a same-user process can still undo the new staging-folder lock (reproduced, details inline). The other two inline comments are non-blocking.

What was exercised: dotnet test --filter XamlTriage (134 passed, 1 skipped); a Debug __xaml-triage run against the real signed arm64 debugger cache (files verified, copied, re-verified, ACL applied, cleanup worked); and two local reproductions of the lock bypass. The Windows Kits layout was not available, so the ext.dll comment is from reading the code only.

@nmetulev Nikola Metulev (nmetulev) added agent-preparing Agent is addressing feedback or completing required validation and CI and removed ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge labels Oct 9, 2026
Same-user processes can already run code, and a copied winapp.exe loads a
planted version.dll, so the copy-and-lock folder added cost (about 40 MB per
run) without stopping that user. Keep the signature, pinned-script and _NT_*
checks that stop the child being pointed at arbitrary files.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Whoever sets the environment also controls PATH, which DbgEng searches for
default extensions, so clearing _NT_* didn't close that route. It only took
_NT_SYMBOL_PATH symbols away from developers who rely on it.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nmetulev Nikola Metulev (nmetulev) added ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge and removed agent-preparing Agent is addressing feedback or completing required validation and CI labels Oct 15, 2026
Nikola Metulev (nmetulev) added a commit that referenced this pull request Oct 16, 2026
Follow-up to #1046.

## What was wrong
`winapp.exe` statically imports several DLLs that aren't KnownDLLs
(`version.dll`, `bcrypt.dll`, `crypt32.dll`, `iphlpapi.dll`,
`ncrypt.dll`, `secur32.dll`). Windows searches the exe's own folder for
those first. A DLL with one of those names placed next to `winapp.exe`
gets loaded into the signed process.

## What changed
The published exe sets the PE dependent-load flag to
`LOAD_LIBRARY_SEARCH_SYSTEM32` (`/DEPENDENTLOADFLAG:0x800`).
winapp.exe's own static imports now resolve only from System32. Runtime
`LoadLibrary` calls (dbgeng, UI Automation, SkiaSharp, etc.) are
unaffected.

## Repro: copy `winapp.exe` into an empty folder, add a junk
`version.dll`, run `winapp.exe --version`

| | Result |
|---|---|
| Before | exit `0xC000012F` (planted DLL was loaded) |
| After | exit 0, prints the version |

After the fix, junk copies of all six direct imports placed together
also leave `--version` and `--help` at exit 0.

`dumpbin /loadconfig winapp.exe` (Release publish):

| | Dependent Load Flag |
|---|---|
| win-x64 before | `0000` |
| win-x64 after | `0800` |
| win-arm64 after | `0800` |

## Limitation
This reduces the obvious case. It doesn't close it. I planted each of
the ~220 non-KnownDLL names from the full import chain next to the fixed
exe, one at a time. Two are still loaded from the exe's folder:
- `sspicli.dll`, imported by Windows' `crypt32.dll` and `advapi32.dll`
- `ntasn1.dll`, imported by Windows' `ncrypt.dll`

Those system DLLs don't set this flag, and the exe's flag only applies
to the exe's own imports. Any exe in a user-writable folder has this
exposure. The real protection is installing to a location the user can't
write to.

## Verification
- `dotnet publish -c Release` for win-x64 and win-arm64 succeeds. The
published `winapp --version` and `winapp --help` exit 0.
- The exe has no delay-loaded imports, so this flag doesn't apply to
anything loaded later at runtime.
- Each check below ran the published x64 exe before and after the
change. Results were identical:
- `ui inspect` and `ui screenshot` against a running app work. The
composite screenshot loads the bundled `libSkiaSharp.dll` from the exe's
folder at runtime.
- The `__xaml-triage` child loads dbgeng, JsProvider and the WinUI
extension against a dump and produces the same output.
- `perf start` / `stop` / `analyze` against a running WinUI 3 app: the
ETW providers are enabled the same way.
- The gated UI tests that drive the published exe
(`WINAPP_UI_MULTIPROCESS_TESTS=1`, `InteractiveDesktop*`,
`UiCommandTests`) passed 897/900. One was an intentional skip. The two
failures were `foreground_not_target` focus races on a shared desktop.
On reruns the baseline exe also failed one of them, and the fixed exe
passed both twice.
- No user-facing behavior change, so no doc updates.

Co-authored-by: Nikola Metulev <711864+nmetulev@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@nmetulev
Nikola Metulev (nmetulev) merged commit 27133d8 into main Oct 16, 2026
41 checks passed
@nmetulev
Nikola Metulev (nmetulev) deleted the fix-xaml-triage-child-signature branch October 16, 2026 19:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants