1.8: Repo: Audit powershell, use powershell_builder more (#4093) - #4129
Merged
Steven Malis (smalis-msft) merged 1 commit intoAug 4, 2026
Merged
Conversation
An internal audit flagged that our powershell handling was vulnerable to command injection in certain cases. Fix this in powershell_builder, and then update other powershell use sites to use powershell_builder instead of duplicating the logic around. This is not a security concern as all of this powershell is for local utilities/testing/CI, none of it is shipped. (cherry picked from commit 50f2923)
Steven Malis (smalis-msft)
enabled auto-merge (squash)
July 31, 2026 17:21
Contributor
There was a problem hiding this comment.
Pull request overview
Backports the PowerShell command-injection hardening from #4093 onto release/1.8.2607 by centralizing quoting/escaping behavior in powershell_builder and updating callers to use it rather than hand-rolled quoting.
Changes:
- Switch PowerShell string quoting to single-quoted literals (escaping
'by doubling) and add unit tests to validate no expansion/breakout. - Update multiple call sites (Hyper-V tooling, diag client, flowey scripts) to use
powershell_builderand add-NonInteractive/-NoProfilein more places. - Tighten/clarify PowerShell typing in scripts (e.g.,
[guid]parameters/casts) and make hashtable key emission safer by quoting string keys.
Reviewed changes
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| support/powershell_builder/src/lib.rs | Implements safer PowerShell quoting, documents trust boundaries, adjusts hashtable key handling, and adds tests. |
| petri/src/vm/hyperv/utilities.psm1 | Casts VM ID to [guid] before interpolation to match expected query format. |
| petri/src/vm/hyperv/powershell.rs | Removes manual quoting and uses typed/safer hashtable keys (numeric where appropriate). |
| openhcl/diag_client/src/lib.rs | Replaces ad-hoc PowerShell script formatting with powershell_builder cmdlet construction. |
| openhcl/diag_client/Cargo.toml | Adds powershell_builder as a Windows-only dependency. |
| hyperv/tools/hypestv/src/windows/vm.rs | Updates PowerShell param types for VM IDs to [guid]. |
| hyperv/tools/hypestv/src/windows/hyperv.rs | Replaces manual PowerShell arg escaping with powershell_builder and improves error propagation. |
| hyperv/tools/hypestv/Cargo.toml | Adds powershell_builder dependency. |
| flowey/flowey_lib_common/src/install_git.rs | Makes PowerShell invocation more deterministic by adding -NoProfile -NonInteractive -Command. |
| flowey/flowey_lib_common/src/install_dotnet_cli.rs | Adds -NoProfile -NonInteractive to the PowerShell install script invocation. |
| flowey/flowey_lib_common/src/gen_cargo_nextest_run_cmd.rs | Centralizes shell quoting (PowerShell uses powershell_builder::quote_str) for generated scripts. |
| flowey/flowey_lib_common/Cargo.toml | Adds powershell_builder dependency. |
| Cargo.lock | Records new dependency edges on powershell_builder. |
Comment on lines
+191
to
+195
| if let Some(s) = s.to_str() { | ||
| quoted.push(s.replace(r#"'"#, r#"''"#)); | ||
| } else { | ||
| todo!("quote_str: non-UTF8 string {:?}", s); | ||
| } |
Matt LaFayette (Kurjanowicz) (mattkur)
approved these changes
Aug 4, 2026
Steven Malis (smalis-msft)
merged commit Aug 4, 2026
a989014
into
microsoft:release/1.8.2607
154 of 158 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Backport of #4093 to
release/1.8.2607.The cherry-pick of 50f2923 applied cleanly onto
release/1.8.2607with no conflicts and no manual edits.Original PR: #4093
This backport PR was created by an AI agent (GitHub Copilot) on behalf of Steven Malis (@smalis-msft).