Skip to content

🔒 security fix for PowerShell command injection#117

Open
badMade wants to merge 3 commits into
mainfrom
fix-powershell-injection-12627724688630408301
Open

🔒 security fix for PowerShell command injection#117
badMade wants to merge 3 commits into
mainfrom
fix-powershell-injection-12627724688630408301

Conversation

@badMade

@badMade badMade commented May 2, 2026

Copy link
Copy Markdown
Owner

🎯 What: Fixed a potential command injection vulnerability in PowerShell execution.
⚠️ Risk: Direct injection of user input into a shell execution via command arguments is a well-known vulnerability that could allow arbitrary command execution.
🛡️ Solution: Replaced the -Command flag with -EncodedCommand. The command string is now UTF-16LE and Base64 encoded before being passed to PowerShell, which is the recommended secure way to pass complex commands and avoid injection or quoting issues.


PR created automatically by Jules for task 12627724688630408301 started by @badMade

Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

Copilot AI review requested due to automatic review settings May 2, 2026 12:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the Rust tools crate's PowerShell execution path to pass commands via PowerShell's -EncodedCommand flag instead of -Command, aiming to change how script text is delivered to the shell.

Changes:

  • Added the base64 dependency to the tools crate.
  • Converted PowerShell command strings to UTF-16LE bytes and Base64 before execution.
  • Replaced -Command with -EncodedCommand for both foreground and background PowerShell invocations.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
rust/crates/tools/src/lib.rs Encodes PowerShell command text and switches process invocation to -EncodedCommand.
rust/crates/tools/Cargo.toml Adds the base64 crate needed for command encoding.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5178 to +5179
.arg("-EncodedCommand")
.arg(encoded_command)
Comment on lines +5207 to +5208
.arg("-EncodedCommand")
.arg(encoded_command);

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces Base64 encoding for shell commands to improve reliability when executing complex strings. It adds the base64 dependency and updates the execute_shell_command function to convert commands to UTF-16 LE before encoding them and passing them via the -EncodedCommand flag. A suggestion was made to pass a reference to the byte vector during encoding to follow idiomatic Rust practices and avoid potential ownership issues.

.encode_utf16()
.flat_map(|u| u.to_le_bytes())
.collect();
let encoded_command = base64::engine::general_purpose::STANDARD.encode(utf16_bytes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The encoded_command is used in two different code paths (background and foreground execution). Since base64::Engine::encode returns a String, passing it by value to .arg() in the background path (line 5179) would move it, making it unavailable for the foreground path (line 5208). Although the background path returns early, it is safer and more idiomatic to pass a reference to .arg() to avoid potential ownership issues if the code is refactored in the future.

Suggested change
let encoded_command = base64::engine::general_purpose::STANDARD.encode(utf16_bytes);
let encoded_command = base64::engine::general_purpose::STANDARD.encode(&utf16_bytes);

badMade and others added 2 commits May 2, 2026 13:37
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Copilot AI review requested due to automatic review settings May 2, 2026 13:51

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +5207 to +5208
.arg("-EncodedCommand")
.arg(encoded_command);
Comment on lines +8206 to +8209
assert_eq!(
output["stdout"],
"pwsh:VwByAGkAdABlAC0ATwB1AHQAcAB1AHQAIABoAGUAbABsAG8A"
);
@badMade

badMade commented May 2, 2026

Copy link
Copy Markdown
Owner Author

@claude code review
@codex code review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8da56aabb2

ℹ️ 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".

Comment on lines +5168 to +5172
let utf16_bytes: Vec<u8> = command
.encode_utf16()
.flat_map(|u| u.to_le_bytes())
.collect();
let encoded_command = base64::engine::general_purpose::STANDARD.encode(utf16_bytes);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Avoid expanding PowerShell payload past Windows argv limit

Switching from -Command to -EncodedCommand base64-expands every script (UTF-16LE + base64), which reduces the maximum runnable command size on Windows before process creation fails with command-line length errors. A command that previously fit as plain text can now exceed the CreateProcess argument limit once encoded, so large generated scripts will fail to execute even though they worked before this change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@codex, make changes based on:

P2 Badge Avoid expanding PowerShell payload past Windows argv limit

Switching from -Command to -EncodedCommand base64-expands every script (UTF-16LE + base64), which reduces the maximum runnable command size on Windows before process creation fails with command-line length errors. A command that previously fit as plain text can now exceed the CreateProcess argument limit once encoded, so large generated scripts will fail to execute even though they worked before this change.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You have reached your Codex usage limits. You can see your limits in the Codex usage dashboard.

@badMade badMade marked this pull request as ready for review May 2, 2026 18:48
@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@badMade

badMade commented May 3, 2026

Copy link
Copy Markdown
Owner Author

@gemini-code-assist, what are the steps and line numbers to make this fix?

@gemini-code-assist

Copy link
Copy Markdown

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants