Fix CWE-295: Remove WinRM certificate/hostname validation bypass in PSCloudShellUtility related to ICM 842194797 - #638
Merged
Richard Hoover (rhkodiak) merged 1 commit intoAug 12, 2026
Conversation
Scott Kool (ComradeCow)
approved these changes
Aug 11, 2026
Mitchell Bifeld (mbifeld)
approved these changes
Aug 11, 2026
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.
Summary
Resolves ICM 847527874 (CWE-295, Improper Certificate Validation). PSCloudShellUtility.psm1 set a module-scoped PSSessionOption with SkipCACheck = $true / SkipCNCheck = $true , used by the exported Invoke-AzVMCommand to connect to Windows VMs over WinRM-HTTPS with self-signed certs. This disabled all server-identity validation, letting a network attacker who could intercept/redirect traffic to the VM's public endpoint spoof the server and steal the Basic-auth credential.
Fix
Replaced the WinRM/self-signed-cert connection path (Windows only) with Azure Invoke-AzVMRunCommand , which executes via the ARM control plane instead of a direct network connection to the VM — eliminating the need for any client-side certificate trust decision entirely.
Invoke-AzVMCommand : Windows branch now validates the VM exists ( Get-AzVM ) and calls Invoke-AzVMRunCommand ( CommandId = RunPowerShellScript ) instead of Invoke-Command over WinRM. Result parsing splits the returned status into StdOut/StdErr; StdOut is written as output, and a non-empty StdErr message is thrown as a terminating InvalidOperationException (Run Command's status object never signals failure via Level/Code — only a non-empty StdErr message indicates the script errored).
Credential remains a mandatory parameter (validated non-null) for backward compatibility but is no longer forwarded anywhere — Run Command always executes as SYSTEM , and Invoke-AzVMRunCommand has no -RunAsUser / -RunAsPassword parameters. Authorization is now enforced via Azure RBAC on the VM resource rather than a guest-OS credential. Documented in the .PARAMETER Credential help.
Enable-AzVMPSRemoting / Disable-AzVMPSRemoting : Windows branches converted to no-ops (kept only so existing -OsType windows callers don't break) — there's no WinRM listener, self-signed cert, or NSG port to provision/tear down anymore.
Test-AzVM : simplified remoting-status check to Linux-only (SSH), since Windows no longer routes through this check.
The Linux/SSH code path is entirely untouched.
Removed the flagged module-scope $script:sessionOption block and all references to it.
Validation (live Cloud Shell session)
Follow-ups (not in scope for this PR)
Tenant NRMS baseline NSG policy blocks direct internet SSH — pre-existing, unrelated to this fix.
Enable-AzVMPSRemoting Linux install script is hardcoded to Ubuntu 18.04 and fails on newer Ubuntu releases — pre-existing bug, separate from this fix.
Fixes ICM 847527874.
Test Results
The fix continues to work as expected on a fresh Cloud Shell session.