File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -44,6 +44,11 @@ export function runPowerShell(
4444 config : ServerConfig
4545) : Promise < PowerShellResult > {
4646 return new Promise ( ( resolve , reject ) => {
47+ // Encode the script as Base64 UTF-16LE and use -EncodedCommand so that
48+ // no part of the script (including any user-supplied parameter values
49+ // embedded in it) is ever parsed as a command-line argument by PowerShell.
50+ // This eliminates the command-injection risk present with -Command.
51+ const encodedCommand = Buffer . from ( script , "utf16le" ) . toString ( "base64" ) ;
4752 const pwsh = spawn (
4853 config . powershellExe ,
4954 [
@@ -52,8 +57,8 @@ export function runPowerShell(
5257 "-NoLogo" ,
5358 "-ExecutionPolicy" ,
5459 "Bypass" ,
55- "-Command " ,
56- script ,
60+ "-EncodedCommand " ,
61+ encodedCommand ,
5762 ] ,
5863 { shell : false }
5964 ) ;
You can’t perform that action at this time.
0 commit comments