-
Notifications
You must be signed in to change notification settings - Fork 12.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Windows: Consider disallowing .bat
and .cmd
files in Command::new
#123728
Comments
https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/ says:
does libstd ignore PATHEXT? or is it possible that |
Rust's std does not use |
FWIW, I was previously confused about Other relevant issues for cross reference: #37519 #87945 #93124 |
I think we definitely do need to flesh out our documentation. But I'd also like to explicitly decide what our behaviour should be rather than just documenting behaviour which is mostly accidental. Even if that decision ends up being to keep doing what we're currently doing, I'd rather that was a conscious choice. |
This was discussed in the libs-api meeting. There was no consensus on dropping this behaviour. However there's also not currently a consensus on documenting this behaviour, rather than just keeping some degree of hidden support for compatibility reasons but not actively advertising it (maybe with a lint on static strings passed to |
This was again discussed in the latest libs-api meeting. It was felt that keeping our current behaviour was worth it for the sake of compatibility. So I'll close this. I'll add that our documentation does now have warnings around bat use. Improved documentation for Windows specific issues can of course be added but that's a separate issue. |
In light of CVE-2024-24576 it was suggested we disallow running
.bat
files usingCommand::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 factCreateProcess
actively documents against using it this way: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:
cmd /c
as stated above[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 inPATH
. 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]The text was updated successfully, but these errors were encountered: