-
Notifications
You must be signed in to change notification settings - Fork 13.7k
Description
In light of CVE-2024-24576 it was suggested we disallow running .bat
files using Command::new
. It was not a change we wanted to make in a point release, especially without discussion with the full libs-api team. so I'm writing this issue for libs-api to consider and accept or reject.
This was never (previously) documented and originally only worked accidentally due to undocumented CreateProcess
behaviour. In fact CreateProcess
actively documents against using it this way:
To run a batch file, you must start the command interpreter; set lpApplicationName to cmd.exe and set lpCommandLine to the following arguments: /c plus the name of the batch file.
Which in Rust terms means using Command::new("cmd.exe").args(["/c", "script.bat"])
.
However, while this is was not previously documented, people could be (and some are) relying on it. so it would be breaking for them. The fix would be:
- for trusted input, use
cmd /c
as stated above - for untrusted input, use
[insert crate here]
Note that this would only affect people that use a path to a .bat
file. The standard library only searches for .exe
files in PATH
. The standard library (on Windows) also does not support running script files in general. Previously, .bat
files had been an accidental special case. So using a crate (or your own code) is necessary for other script types.
[side note: when I say .bat
I also mean .cmd
as they are effectively the same thing as far as this issue is concerned]