-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [HIGH] Harden Windows command execution against injection #799
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
base: main
Are you sure you want to change the base?
Changes from all commits
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 |
|---|---|---|
|
|
@@ -163,6 +163,10 @@ pub fn cmd_escape(s: &str) -> Cow<'_, str> { | |
| for c in s.chars() { | ||
| if c == '"' { | ||
| escaped.push_str("\"\""); | ||
| } else if c == '%' { | ||
| // Insert empty string ("") after % to prevent variable expansion in cmd.exe | ||
| // e.g. %VAR% becomes %""VAR%"" | ||
| escaped.push_str("%\"\""); | ||
| } else { | ||
|
Comment on lines
+166
to
170
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.
Rewriting Useful? React with πΒ / π. |
||
| escaped.push(c); | ||
| } | ||
|
|
@@ -319,6 +323,11 @@ mod tests { | |
| assert_eq!(cmd_escape("foo&bar"), "\"foo&bar\""); | ||
| assert_eq!(cmd_escape("foo|bar"), "\"foo|bar\""); | ||
| assert_eq!(cmd_escape(""), "\"\""); | ||
|
|
||
| // Test environment variable expansion prevention | ||
| // % is replaced with %"" which breaks the variable token in cmd.exe | ||
| assert_eq!(cmd_escape("%USERNAME%"), "\"%\"\"USERNAME%\"\"\""); | ||
| assert_eq!(cmd_escape("foo%bar"), "\"foo%\"\"bar\""); | ||
| } | ||
|
|
||
| #[test] | ||
|
|
||
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.
%/^rejection to Windows command pathsAdding
%and^to the globaldangerous_patternslist makesvalidate_command_argsfail for these characters on every platform, but this validator is called unconditionally by modules likeCommandModule::validate_params(src/modules/command.rs) andServiceConfig::from_params(src/modules/service.rs) before any Windows shell selection. This creates a cross-platform regression where legitimate non-Windows arguments (for example format strings containing%or regex anchors with^) are now rejected even when nocmd.exeexpansion is involved.Useful? React with πΒ / π.