Skip to content

Hold and verify every WinUI triage debugger DLL until triage finishes - #954

Merged
Nikola Metulev (nmetulev) merged 5 commits into
mainfrom
azchohfi-jsprovider-verified-load
Sep 30, 2026
Merged

Nikola Metulev (nmetulev) merged 5 commits into
mainfrom
azchohfi-jsprovider-verified-load

Conversation

@azchohfi

@azchohfi Alexandre Zollinger Chohfi (azchohfi) commented Sep 30, 2026 •

Copy link
Copy Markdown
Collaborator

Description

The WinUI stowed-exception triage pass (run automatically by winapp run --debug-output when a WinUI app crashes) loads downloaded debugger DLLs into a child process. Before this change, winapp checked JsProvider.dll's Microsoft signature and then handed only its path to the child, which loaded it later. Nothing kept the file in place in between, so anything able to write the debugger cache could replace it after the check and have its own code run as the user. The engine DLLs next to it (dbgeng.dll, dbghelp.dll, dbgcore.dll, dbgmodel.dll, msdia140.dll, symsrv.dll) were worse: their signatures were never checked when triage used them.

Now every DLL the triage child loads is:

  • held open (reads allowed; no write, rename or delete of the file or any folder above it) from the moment it is checked until the child has exited, including after a timeout or cancellation kill;
  • signature-checked by the path its handle actually resolves to, and the child is given that same path, so a re-pointed junction can't substitute another file;
  • required to live in the engine folder under its own name (the engine loads these by name, so a symlink to a file elsewhere is rejected).

The WinUI debugger extension script (winui-dbgext.js) gets the same treatment: it is held open, hash-checked by its resolved path, and kept locked until the child exits. A script loaded into the debugger can run debugger commands, so swapping it was also code execution.

A layout that fails any of these is skipped, the same as before. A cached engine DLL that fails the signature check is downloaded again on the next run instead of disabling triage permanently. This reuses VerifiedTool from #922, which does the same for build tools.

Usage Example

No command or flag changes. Reproduction (real Windows Kits debugger layout, real triage child, unsigned payload DLL whose DllMain writes a marker file):

main:         swap JsProvider.dll after verification -> SUCCEEDED
              result: attacker DllMain ran in pid 66852 (...\winapp.exe)
this branch:  swap JsProvider.dll after verification -> REFUSED (IOException: ... being used by another process)
              result: attacker code did NOT execute

The same result holds when swapping dbgcore.dll instead. On this branch, the genuine JsProvider.dll from the held Windows Kits layout still loads and runs a script in the triage child.

Related Issue

Fixes #923

Type of Change

  • 🐛 Bug fix

Checklist

  • New tests added for new functionality (if applicable)
  • Tested locally on Windows

Screenshots / Demo

N/A (no UI change; textual reproduction above).

Additional Notes

  • Validation: 161 triage/VerifiedTool/JsProvider-acquirer tests pass locally (1 existing environment-dependent test is inconclusive). They cover: files locked while held and released after; every loaded DLL checked by its resolved path; any single unsigned DLL rejecting the layout and releasing all holds; junction re-point; symlinked engine files; re-acquiring an unsigned cached engine DLL; holds lasting until the child exits, including a killed child that is slow to die; the extension script being held and a tampered cached copy being replaced; and the child requiring --jsprovider. scripts/build-cli.ps1 -SkipTests -SkipMsix -SkipNpm succeeds, with no CLI schema change.
  • Hidden child verb: the internal __xaml-triage child now requires --jsprovider rather than guessing <bin>\JsProvider.dll. It is only ever invoked by the same binary, so there is no external consumer.
  • Known limit (same as Require a Microsoft organization on build-tool signers, and run what was verified #922): holding pins files that exist. Someone with write access to the cache can still add a new DLL that the engine later searches for by name.
  • Not covered locally: a full end-to-end triage of a real WinUI crash through the downloaded NuGet cache (no populated cache on this machine). The Windows Kits layout was exercised end to end.
  • docs/debugging.md now states that every debugger DLL, including those in a WINAPP_DBGTOOLS_DIR layout, must be Microsoft-signed, and that those DLLs and the extension script are locked while triage runs.

The WinUI triage pass verified JsProvider.dll by path and the child process
later loaded it by path, with nothing holding the file in between. The
engine DLLs (dbgeng, dbghelp, dbgcore, dbgmodel, msdia140, symsrv) were
never signature-checked at use time at all.

Resolution now holds every DLL the child loads via VerifiedTool, verifies
each one's Microsoft signature by its handle-resolved path, and hands the
child those resolved paths. ResolvedTriageBinaries owns the holds and the
service releases them only after the child has exited (waiting for a
killed child to finish exiting). Engine files must resolve inside the
engine directory under their own names, the child now requires
--jsprovider, and an unsigned cached engine DLL is re-acquired.

Fixes #923

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f0de6168-3f21-4efa-8844-f5ca8ff1b59c
Copilot AI balanced review requested due to automatic review settings September 30, 2026 21:26
@azchohfi Alexandre Zollinger Chohfi (azchohfi) added the agent-preparing Agent is addressing feedback or completing required validation and CI label Sep 30, 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 review overview

🟡 Changes recommended

The timeout path can release verified DLL holds before a slowly terminating child has exited.

Review effort: Balanced
Findings: 1 High severity

Open (1)
What changed in this PR

Hardens WinUI crash triage against debugger-DLL replacement between verification and loading.

Changes:

  • Holds and verifies every known debugger DLL through child-process exit.
  • Requires the child to use the verified JsProvider.dll path.
  • Adds security, acquisition, lifecycle, and documentation coverage.
File Description
XamlTriageService.cs Manages verified DLL lifetime and child termination.
XamlTriageRunner.cs Requires the explicit provider path.
XamlTriageBinaries.cs Resolves, verifies, and holds debugger DLLs.
VerifiedTool.cs Generalizes documentation to native binaries.
XamlTriageServiceWorkflowTests.cs Tests hold lifetime across child outcomes.
XamlTriageRunnerTests.cs Tests required provider arguments.
XamlTriageBinariesTests.cs Tests locking, signatures, links, and junctions.
XamlTriageBinariesAcquisitionTests.cs Tests reacquisition of unsigned cache files.
docs/​debugging.md Documents signature and locking behavior.

💡 Configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

WaitForExit(30s) could return with the child still alive, releasing the
verified DLLs while it ran. Wait until termination is confirmed instead.
Also hand held files over through a using-scoped owner and use Path.Join
for fixed file-name segments.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f0de6168-3f21-4efa-8844-f5ca8ff1b59c
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f0de6168-3f21-4efa-8844-f5ca8ff1b59c

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 review overview

🟡 Changes recommended

The hash-verified JavaScript extension remains replaceable before the child loads it, preserving a code-execution path.

Review effort: Balanced
Findings: 1 High severity

Open (1)
Resolved since last review (1)

winui-dbgext.js was hash-checked by path and later loaded by path with
.scriptload. A script can run debugger commands, so a swap in between was
still code execution. EnsureExtensionAsync now returns the script held
open, hashed by its handle-resolved path, and the child is given that path.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Copilot-Session: f0de6168-3f21-4efa-8844-f5ca8ff1b59c

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 review overview

🔵 Needs a closer look

The security-sensitive changes build successfully and 146 targeted tests pass, but downloaded-cache end-to-end triage was not exercised.

Review effort: Balanced
Findings: None

Resolved since last review (1)

@github-actions

Copy link
Copy Markdown
Contributor

Build Metrics Report

Validation passed. All required build and validation jobs succeeded.

Binary Sizes

Artifact Baseline Current Delta
CLI (ARM64) 57.31 MB 57.32 MB 📈 +15.0 KB (+0.03%)
CLI (x64) 57.35 MB 57.36 MB 📈 +14.0 KB (+0.02%)
MSIX (ARM64) 23.79 MB 23.80 MB 📈 +9.9 KB (+0.04%)
MSIX (x64) 25.27 MB 25.28 MB 📈 +5.3 KB (+0.02%)
NPM Package 49.65 MB 49.66 MB 📈 +14.1 KB (+0.03%)
NuGet Package 49.75 MB 49.76 MB 📈 +10.7 KB (+0.02%)

.NET Test Results (TRX reports)

Other suites are reflected in the overall validation status above.

✅ 7907 passed, 37 skipped out of 7944 tests in 1379.3s (+21 tests, -314.3s vs. baseline)

Test Coverage

✅ 86.4% line coverage, 80.9% branch coverage · ✅ +0.1% vs. baseline

CLI Startup Time

60ms median (x64, winapp --version) · ⚠️ +12ms vs. baseline

Try This Build

Installs the MSIX for your architecture, replacing any previously installed build. Needs the GitHub CLI — the command offers to install it and sign you in if it is missing.

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) 954
Switching between builds often?

Put the tool on your PATH once:

& ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPath

Then this build is just:

winapp-pr 954

Run winapp-pr with no arguments to pick from a list of open PRs.


Updated 2026-09-30 22:42:55 UTC · commit 734d4c7 · workflow run

@azchohfi Alexandre Zollinger Chohfi (azchohfi) 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 Sep 30, 2026
@nmetulev
Nikola Metulev (nmetulev) merged commit 3e1bfc5 into main Sep 30, 2026
41 checks passed
@nmetulev
Nikola Metulev (nmetulev) deleted the azchohfi-jsprovider-verified-load branch September 30, 2026 22:46
@azchohfi Alexandre Zollinger Chohfi (azchohfi) removed the ready-for-review Agent work and technical checks complete; awaiting review or re-review, not approval or merge label Oct 1, 2026
Nikola Metulev (nmetulev) added a commit that referenced this pull request Oct 16, 2026
…ents (#1046)

## 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 `.load`s 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

- [x] 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.
- [x] 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.
#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.

---------

Co-authored-by: Nikola Metulev <711864+nmetulev@users.noreply.github.com>
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Zach Teutsch <88554871+zateutsch@users.noreply.github.com>
This was referenced Nov 13, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

JsProvider.dll is verified by path and then loaded by path, with nothing holding it in between

3 participants