Repo: Audit powershell, use powershell_builder more - #4093
Merged
Steven Malis (smalis-msft) merged 2 commits intoJul 30, 2026
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR addresses a command-injection risk in how PowerShell command lines were being constructed by hardening powershell_builder’s quoting behavior and migrating several call sites to use the centralized builder instead of ad-hoc quoting/escaping.
Changes:
- Harden PowerShell argument quoting and hashtable serialization in
powershell_builder(single-quoted literals; hashtable keys now go throughAsVal) and add unit tests. - Migrate Hyper-V-related utilities to build PowerShell invocations via
powershell_builderand tighten GUID typing in PowerShellparamblocks / scripts. - Improve Flowey Windows PowerShell invocations and reuse
powershell_builder::quote_strfor PowerShell script generation.
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 | Switch to single-quote literal quoting, improve trust-boundary docs, adjust hashtable key handling, add unit tests. |
| petri/src/vm/hyperv/utilities.psm1 | Cast VM ID to [guid] to avoid unsafe string interpolation behavior. |
| petri/src/vm/hyperv/powershell.rs | Stop manually pre-quoting hashtable keys; use typed keys (GUIDs/integers) with powershell_builder quoting rules. |
| openhcl/diag_client/src/lib.rs | Replace ad-hoc PowerShell script formatting with powershell_builder composition for COM port queries. |
| openhcl/diag_client/Cargo.toml | Add powershell_builder as a Windows-only dependency. |
| hyperv/tools/hypestv/src/windows/vm.rs | Tighten script param types from [string] to [guid] for VM IDs. |
| hyperv/tools/hypestv/src/windows/hyperv.rs | Rework powershell_script to use powershell_builder for safe argument quoting and add better process-launch error context. |
| hyperv/tools/hypestv/Cargo.toml | Add powershell_builder dependency. |
| flowey/flowey_lib_common/src/install_git.rs | Make PowerShell invocation explicitly -NoProfile -NonInteractive -Command ... for consistency/safety. |
| flowey/flowey_lib_common/src/install_dotnet_cli.rs | Add -NoProfile -NonInteractive to PowerShell used for dotnet installer script. |
| flowey/flowey_lib_common/src/gen_cargo_nextest_run_cmd.rs | Centralize shell quoting per-shell; use powershell_builder::quote_str for PowerShell quoting. |
| flowey/flowey_lib_common/Cargo.toml | Add powershell_builder dependency. |
| Cargo.lock | Lockfile updates due to new workspace dependency edges. |
Trevor Jones (tjones60)
approved these changes
Jul 30, 2026
Trevor Jones (tjones60)
left a comment
Contributor
There was a problem hiding this comment.
Looks good aside from a few nits.
Contributor
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.
Comments suppressed due to low confidence (3)
support/powershell_builder/src/lib.rs:195
quote_strpanics on non-UTF8OsStrviatodo!(). This can crash callers (e.g. flowey script generation) when a path/env value contains non-UTF8 / non-UTF-8-representable data. Prefer a non-panicking quoting strategy (lossy or explicit encoding) so quoting is always safe.
if let Some(s) = s.to_str() {
quoted.push(s.replace(r#"'"#, r#"''"#));
} else {
todo!("quote_str: non-UTF8 string {:?}", s);
}
petri/src/vm/hyperv/powershell.rs:773
vsidis&guid::Guidhere, andpowershell_builder::AsValis not implemented forGuid, so using it as aHashTablekey will fail to compile. Convert it to aString(it will be quoted by the builder).
vsid,
petri/src/vm/hyperv/powershell.rs:750
vsidis aguid::Guidkey, butpowershell_builder::AsValis not implemented forGuid. This will not compile with the newHashTable<K: AsVal>bounds; use a string key instead.
vsid,
Trevor Jones (tjones60)
approved these changes
Jul 30, 2026
Steven Malis (smalis-msft)
merged commit Jul 30, 2026
50f2923
into
microsoft:main
129 of 133 checks passed
Steven Malis (smalis-msft)
added a commit
that referenced
this pull request
Aug 4, 2026
Backport of #4093 to `release/1.8.2607`. The cherry-pick of 50f2923 applied cleanly onto `release/1.8.2607` with no conflicts and no manual edits. Original PR: #4093 --- *This backport PR was created by an AI agent (GitHub Copilot) on behalf of @smalis-msft.*
Member
|
Backported to release/1.8.2607 in #4129 |
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.
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.