node-windows icon indicating copy to clipboard operation
node-windows copied to clipboard

Fix Shell command built from environment values

Open odaysec opened this issue 7 months ago • 0 comments

https://github.com/coreybutler/node-windows/blob/54ac1e382f1cf56bc7278672672aba1342c96c01/lib/binaries.js#L2-L2 https://github.com/coreybutler/node-windows/blob/54ac1e382f1cf56bc7278672672aba1342c96c01/lib/binaries.js#L76-L76

fix the issue the dynamically constructed shell command should be replaced with a safer approach that avoids shell interpretation. Specifically:

  1. Use execFile instead of exec to execute the command. This allows passing arguments as an array, which prevents the shell from interpreting special characters.
  2. Construct the command and its arguments separately. The executable path (path.join(bin, 'sudowin', 'sudo.exe')) should be passed as the first argument to execFile, and the remaining parts (-p and password, cmd) should be passed as elements of the arguments array.
  3. Ensure that the cmd and password values are properly handled to avoid unintended behavior.

The changes will be made in the sudo function on line 76.

odaysec avatar May 15 '25 03:05 odaysec