-
Notifications
You must be signed in to change notification settings - Fork 5.6k
adds a windows-specific method to check if a command is safe #4119
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
Changes from all commits
3175f2b
ed1cdf1
5988041
ac4989e
26ab571
2f5e161
8c5455e
5f1178d
798eba8
4dce8f4
d2b4835
92c7705
3c36d04
13f0876
23dbb6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub mod is_safe_command; | ||
#[cfg(target_os = "windows")] | ||
pub mod windows_safe_commands; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// This is a WIP. This will eventually contain a real list of common safe Windows commands. | ||
pub fn is_safe_command_windows(_command: &[String]) -> bool { | ||
false | ||
} | ||
|
||
#[cfg(test)] | ||
mod tests { | ||
use super::is_safe_command_windows; | ||
|
||
fn vec_str(args: &[&str]) -> Vec<String> { | ||
args.iter().map(ToString::to_string).collect() | ||
} | ||
|
||
#[test] | ||
fn everything_is_unsafe() { | ||
for cmd in [ | ||
vec_str(&["powershell.exe", "-NoLogo", "-Command", "echo hello"]), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know this is a WIP, but wouldn't this be safe? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah, this is more just meant to test the current "everything is unsafe" behavior. It'll change shortly |
||
vec_str(&["copy", "foo", "bar"]), | ||
vec_str(&["del", "file.txt"]), | ||
vec_str(&["powershell.exe", "Get-ChildItem"]), | ||
] { | ||
assert!(!is_safe_command_windows(&cmd)); | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is making me question whether we should be doing
is_safe_to_call_with_exec()
as it works today on Windows. Possibly only if you have Git Bash enabled or whatever it is on Windows and we're actually going to run the command through it? What do you think?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I originally had a version where only the new windows function is called and nothing after it. But there are some tests that are depending on the other safety checks being called (ie, Windows tests that use commands such as
"ls"
). I'm not sure if those tests are valid, but I left this for now to be conservative and not regress anything until I can learn moreUh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ls works in PowerShell by default, apparently. It works in cmd.exe on my machine, but probably due to Git Bash.