Skip to content

1.8: Repo: Audit powershell, use powershell_builder more (#4093) - #4129

Merged
Steven Malis (smalis-msft) merged 1 commit into
microsoft:release/1.8.2607from
smalis-msft:backport-1.8-pr4093
Aug 4, 2026
Merged

1.8: Repo: Audit powershell, use powershell_builder more (#4093)#4129
Steven Malis (smalis-msft) merged 1 commit into
microsoft:release/1.8.2607from
smalis-msft:backport-1.8-pr4093

Conversation

@smalis-msft

Copy link
Copy Markdown
Contributor

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 Steven Malis (@smalis-msft).

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)
Copilot AI review requested due to automatic review settings July 31, 2026 17:18
@smalis-msft
Steven Malis (smalis-msft) requested a review from a team as a code owner July 31, 2026 17:18
@smalis-msft Steven Malis (smalis-msft) added the release_1.8.2607 Targets the release/1.8.2607 branch. label Jul 31, 2026
@smalis-msft
Steven Malis (smalis-msft) enabled auto-merge (squash) July 31, 2026 17:21

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.

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_builder and add -NonInteractive/-NoProfile in 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);
}
@github-actions

Copy link
Copy Markdown

@smalis-msft
Steven Malis (smalis-msft) merged commit a989014 into microsoft:release/1.8.2607 Aug 4, 2026
154 of 158 checks passed
@smalis-msft
Steven Malis (smalis-msft) deleted the backport-1.8-pr4093 branch August 4, 2026 17:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release_1.8.2607 Targets the release/1.8.2607 branch.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants