-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Potential for command injection in arguments of Process.run
on Windows
#14536
Comments
Oh this is so bizarre. In that case we should error out if the value ends with ".bat" or ".cmd" |
Rust indeed took the completely inexplicable approach of trying to escape the args somehow according to the Batch language if the command name ends with ".bat" or ".cmd". They did that because they were also already prepending |
We should consider it a bug in Crystal that |
Consider also this: Process.run("script.bat", ["&calc"])
Process.run("cmd.exe", ["/c", "script.bat", "&calc"]) Maybe something can be done about the 1st footgun, but never about the 2nd. |
We're in the comfortable position that Windows is still not an officially supported platform and we can more freely introduce changes that might break backwards compatibility. Other languages are more constrained in supporting existing behaviour that might depend on these features. I'd be fine with disallowing |
We actually rely on being able to run I'm not so sure if we can completely reject anything |
Run |
crystal/spec/std/spec_helper.cr Line 85 in 82a208c
@HertzDevil I'm not sure if this is even used, actually.
So it must be that the specs are relying on something like this setup crystal/.github/workflows/win.yml Line 253 in 82a208c
|
@HertzDevil Where does |
This issue originates in the Win32 API and is present in many libraries exposing a feature to start a process on Windows. The vulnerability has been dubbed BatBadBut.
A deeper analysis is available at https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/
Crystal's
Process.run
is affected as this program shows:Instead of evaluating
script.bat
and passing an argument of value&calc
, it ends up running the batch script as well ascalc.exe
.(Note the content of
script.bat
doesn't doesn't really matter, the issue is in the argument handling of the implicitcmd.exe /c
.)This is without
shell: true
, so the expectation is that command arguments passed viaargs
parameter are safely escaped.It's possible to abuse this behaviour by injecting commands into arguments for batch files.
According to the linked article it's possible to prevent this by applying proper escaping.
I think we're already doing some amount of that (particularly related to double quotes) but we also need to take other characters (particularly
&
and%
) into account. There is already a discussion about this in #14300.For reference, this is what Rust did: rust-lang/rust#123681
This is what node.js did: nodejs/node@64b6777
Related discussions: #9030, #12873, #14300
The text was updated successfully, but these errors were encountered: