Skip to content

🛡️ Sentinel: [CRITICAL] Fix command injection in PowerShell execution#291

Draft
Dexploarer wants to merge 1 commit intomainfrom
sentinel/fix-powershell-command-injection-12766772756934151057
Draft

🛡️ Sentinel: [CRITICAL] Fix command injection in PowerShell execution#291
Dexploarer wants to merge 1 commit intomainfrom
sentinel/fix-powershell-command-injection-12766772756934151057

Conversation

@Dexploarer
Copy link
Owner

Severity: CRITICAL
Vulnerability: Command injection vulnerability in performType and performKeypress for Windows when using powershell -Command with simple string replacement.
Impact: Arbitrary code execution on the host machine as unsanitized user inputs could bypass simplistic single quote escaping.
Fix: Native base64 encoding from Node into the Powershell script block to avoid quoting problems altogether.
Verification: Validated that the tests all passed including e2e execution. Reviewed the changes carefully via code review to ensure this works.


PR created automatically by Jules for task 12766772756934151057 started by @Dexploarer

Encoded user input as Base64 when passing to PowerShell via \`runCommand\` in \`performType\` and \`performKeypress\` to prevent command injection vulnerabilities that bypass basic single-quote escaping.
@google-labs-jules
Copy link

👋 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.

@github-actions github-actions bot added the docs label Mar 21, 2026
@coderabbitai
Copy link

coderabbitai bot commented Mar 21, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d9293748-0c83-48cc-9260-95e2d1aededa

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch sentinel/fix-powershell-command-injection-12766772756934151057

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@gemini-code-assist
Copy link

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical command injection vulnerability affecting Windows environments, specifically within the performType and performKeypress functions. The fix involves a fundamental change in how user input is handled when interacting with PowerShell, moving from insecure string escaping to a more robust Base64 encoding mechanism. This significantly enhances the security posture by preventing arbitrary code execution and protecting against potential malicious inputs.

Highlights

  • Critical Command Injection Vulnerability Addressed: Fixed a critical command injection vulnerability in performType and performKeypress functions on Windows, which previously allowed arbitrary code execution due to unsanitized user input in PowerShell commands.
  • Enhanced Input Sanitization: Replaced simplistic single-quote escaping with native Base64 encoding for user inputs passed to PowerShell, ensuring robust protection against injection attacks.
  • Security Documentation Added: A new markdown file was added to document the vulnerability, the lessons learned, and the recommended prevention strategy for similar issues.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Comment on lines 1086 to 1087
throw new Error("xdotool required for keyboard input on Linux.");
}

Choose a reason for hiding this comment

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

Dependency Handling:

If xdotool is not available on Linux, the function throws an error: throw new Error("xdotool required for keyboard input on Linux.");. While this is consistent with other OS branches, it would be more robust to provide actionable guidance in the error message, such as installation instructions, or to check for the dependency earlier (e.g., during capability detection or at startup). This would allow the API to return a more informative error or disable the endpoint, improving maintainability and user experience.

Recommended Solution:

  • Enhance the error message to include installation instructions, e.g., "xdotool required for keyboard input on Linux. Please install it using your package manager (e.g., 'sudo apt install xdotool')."
  • Optionally, check for the dependency at startup and disable the endpoint if missing.

Comment on lines 1147 to 1148
throw new Error("xdotool required for key input on Linux.");
}

Choose a reason for hiding this comment

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

Dependency Handling:

If xdotool is not available on Linux, the function throws an error: throw new Error("xdotool required for key input on Linux.");. As with the previous case, this could be improved by providing actionable guidance or checking for the dependency earlier in the application lifecycle.

Recommended Solution:

  • Update the error message to include installation instructions, e.g., "xdotool required for key input on Linux. Please install it using your package manager (e.g., 'sudo apt install xdotool')."
  • Consider checking for the dependency at startup and disabling the endpoint if missing.

Copy link

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

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 effectively addresses a critical command injection vulnerability in the PowerShell execution for performType and performKeypress on Windows. The switch from string escaping to base64 encoding is a robust and secure solution. I've suggested a minor simplification to the PowerShell commands to improve conciseness, but the core fix is excellent.

[
"-Command",
`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait('${escaped}')`,
`Add-Type -AssemblyName System.Windows.Forms; $text = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($text)`,

Choose a reason for hiding this comment

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

medium

The PowerShell command can be simplified by passing the decoded string directly to SendWait. This removes the need for the intermediate $text variable, making the command more concise.

Suggested change
`Add-Type -AssemblyName System.Windows.Forms; $text = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($text)`,
`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')))`

[
"-Command",
`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait('${escaped}')`,
`Add-Type -AssemblyName System.Windows.Forms; $keys = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($keys)`,

Choose a reason for hiding this comment

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

medium

Similar to the performType function, this PowerShell command can be made more concise. You can remove the intermediate $keys variable and pass the decoded string directly to the SendWait method.

Suggested change
`Add-Type -AssemblyName System.Windows.Forms; $keys = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($keys)`,
`Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait([System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')))`

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant