Repository navigation
Use -EncodedCommand for the elevated Developer Mode script - #727
Conversation
EnsureWin11DevModeAsync embedded its registry script inside a
-Command "& { ... }" argument and relied on EscapeForPSArg, which only escaped
double quotes. That is the fragile half of a quoting problem rather than a fix
for it.
-EncodedCommand takes base64 UTF-16LE, so the script never passes through
command-line quoting at all and the escaping helper is no longer needed. This
matches the pattern already used in scripts/winapp-pr.ps1 and the debug-output
tests.
The test that asserted on the raw argument string now decodes the payload and
asserts on the script text, which is a stronger check than the substring match
it replaces.
There was a problem hiding this comment.
Pull request overview
Replaces fragile PowerShell command quoting with UTF-16LE -EncodedCommand.
Changes:
- Base64-encodes the Developer Mode script.
- Updates tests to decode and validate the payload.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
DevModeService.cs |
Uses encoded PowerShell commands. |
DevModeServiceTests.cs |
Validates the decoded script. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Build Metrics ReportBinary Sizes
Test Results✅ 4549 passed, 5 skipped out of 4554 tests in 607.7s (-37.5s vs. baseline) Test Coverage✅ 89.1% line coverage, 82.4% branch coverage · ✅ no change vs. baseline CLI Startup Time47ms median (x64, Try This BuildInstalls 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))) 727Switching between builds often?Put the tool on your PATH once: & ([scriptblock]::Create((irm https://raw.githubusercontent.com/microsoft/winappCli/main/scripts/winapp-pr.ps1))) -AddToPathThen this build is just: winapp-pr 727Run Updated 2026-08-11 22:33:30 UTC · commit |
What
DevModeService.EnsureWin11DevModeAsyncembedded its registry script inside a-Command "& { ... }"argument:EscapeForPSArgonly escaped double quotes, which is the fragile half of a quoting problem rather than a fix for it. The script itself is hardcoded, so there is no injection path today — but the shape invites one the moment anything dynamic is added, and the escaping helper looks more complete than it is.How
Switch to
-EncodedCommand, which takes base64 UTF-16LE:Base64 output contains no characters with meaning to the shell, so the quoting problem disappears rather than being escaped around, and
EscapeForPSArgis deleted.This is already the established pattern elsewhere in the repo —
scripts/winapp-pr.ps1and the debug-output tests both use-EncodedCommandfor the same reason.The
cmd.exe+reg.exefallback is untouched.Validation
DevModeServiceTestspasses. One test asserted on the raw argument string containingAppModelUnlock, which base64 naturally breaks; it now decodes the payload and asserts on the script text:That is a stronger assertion than the substring match it replaces — it verifies the script that will actually execute, not just the command line.