File tree Expand file tree Collapse file tree 1 file changed +7
-1
lines changed
src/Shared/CertificateGeneration Expand file tree Collapse file tree 1 file changed +7
-1
lines changed Original file line number Diff line number Diff line change @@ -617,6 +617,9 @@ private static bool TryTrustCertificateInWindowsStore(string certificatePath)
617617 // PowerShell command to import the certificate into the CurrentUser Root store.
618618 // We use Import-Certificate which can handle PEM files on modern Windows.
619619 // The -CertStoreLocation parameter specifies the store location.
620+ // Using -EncodedCommand with Base64 encoding to avoid command shell escaping issues.
621+ // We still need to escape single quotes within the PowerShell script itself to prevent
622+ // PowerShell injection vulnerabilities.
620623 var escapedPath = certificatePath . Replace ( "'" , "''" ) ;
621624 var escapedFriendlyName = WslFriendlyName . Replace ( "'" , "''" ) ;
622625 var powershellScript = $@ "
@@ -628,7 +631,10 @@ private static bool TryTrustCertificateInWindowsStore(string certificatePath)
628631 $store.Close()
629632 " ;
630633
631- var startInfo = new ProcessStartInfo ( PowerShellCommand , $ "-NoProfile -NonInteractive -Command \" { powershellScript } \" ")
634+ // Encode the PowerShell script to Base64 (UTF-16LE as required by PowerShell)
635+ var encodedCommand = Convert . ToBase64String ( System . Text . Encoding . Unicode . GetBytes ( powershellScript ) ) ;
636+
637+ var startInfo = new ProcessStartInfo ( PowerShellCommand , $ "-NoProfile -NonInteractive -EncodedCommand { encodedCommand } ")
632638 {
633639 RedirectStandardOutput = true ,
634640 RedirectStandardError = true ,
You can’t perform that action at this time.
0 commit comments