🛡️ Sentinel: [CRITICAL] Fix command injection in PowerShell execution#291
🛡️ Sentinel: [CRITICAL] Fix command injection in PowerShell execution#291Dexploarer wants to merge 1 commit intomainfrom
Conversation
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.
|
👋 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. |
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Summary of ChangesHello, 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 Highlights
🧠 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 AssistThe 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
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 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
|
| throw new Error("xdotool required for keyboard input on Linux."); | ||
| } |
There was a problem hiding this comment.
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.
| throw new Error("xdotool required for key input on Linux."); | ||
| } |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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)`, |
There was a problem hiding this comment.
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.
| `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)`, |
There was a problem hiding this comment.
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.
| `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}')))` |
Severity: CRITICAL
Vulnerability: Command injection vulnerability in
performTypeandperformKeypressfor Windows when usingpowershell -Commandwith 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