π‘οΈ Sentinel: Fix Windows cmd.exe environment variable injection#782
π‘οΈ Sentinel: Fix Windows cmd.exe environment variable injection#782
Conversation
Introduces `cmd_arg_escape` to safely escape `%` characters in Windows command arguments, preventing unintended environment variable expansion. Updates `CommandModule` to use this new escaping mechanism for `argv` parameters on Windows. Updates `validate_command_args` to reject `%` characters in raw command strings, mitigating injection risks in `cmd` and `executable` parameters. Adds comprehensive regression tests in `tests/security_windows_command_injection.rs`. Co-authored-by: dolagoartur <146357947+dolagoartur@users.noreply.github.com>
|
π Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a π emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
There was a problem hiding this comment.
π‘ Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 9252578fcf
βΉοΈ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with π.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| for c in s.chars() { | ||
| match c { | ||
| '"' => escaped.push_str("\"\""), | ||
| '%' => escaped.push_str("%\"\""), |
There was a problem hiding this comment.
Preserve literal percent signs in cmd argument escaping
The new cmd_arg_escape mapping '%'=>"%\"\"" still leaves a %...% token in the final command (for example %USERNAME% becomes "%""USERNAME%"""), so cmd.exe can still treat it as environment-variable expansion and rewrite the argument instead of passing a literal %...%. In CommandModule::get_command_string this affects every argv element for shell_type="cmd", so legitimate Windows arguments containing % are now corrupted at execution time.
Useful? React with πΒ / π.
| ("!", "history expansion !"), | ||
| ("\\", "shell escaping \\"), | ||
| ("$", "variable expansion $"), | ||
| ("%", "variable expansion %"), |
There was a problem hiding this comment.
Scope percent-sign blocking to Windows cmd contexts
Adding % to dangerous_patterns makes validate_command_args reject all raw commands containing %, even on non-Windows shells where % is commonly valid (for example date +%F or printf '%s\n'). Because CommandModule::validate_params runs this validation before shell-type handling, this introduces a cross-platform behavior regression from a Windows-specific security fix.
Useful? React with πΒ / π.
π¨ Severity: MEDIUM
π‘ Vulnerability: Windows
cmd.exeenvironment variable expansion in command arguments.π― Impact: An attacker controlling a variable used in a
commandmodule argument could inject environment variables (e.g.,%SECRET%) which would be expanded bycmd.exe, potentially leaking sensitive information.π§ Fix:
cmd_arg_escapeinsrc/utils/mod.rswhich escapes%as%"", breaking the variable token and preventing expansion incmd.exe.CommandModule(src/modules/command.rs) to usecmd_arg_escapeforargvelements when executing on Windows/cmd.validate_command_args(src/modules/mod.rs) to treat%as a dangerous character, rejecting it in raw command strings to enforce safer usage patterns.β Verification: Added
tests/security_windows_command_injection.rsverifying that%is rejected by validation and properly escaped in arguments. Confirmed existing security tests pass.PR created automatically by Jules for task 6690147054926803037 started by @dolagoartur