🛡️ Sentinel: [CRITICAL] Fix command injection in PowerShell computer input#280
🛡️ Sentinel: [CRITICAL] Fix command injection in PowerShell computer input#280Dexploarer wants to merge 1 commit intodevelopfrom
Conversation
|
👋 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)
📝 Coding Plan
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 that could allow attackers to execute arbitrary PowerShell commands on the host system. The fix involves a fundamental change in how user input is handled when interacting with PowerShell, moving from a vulnerable escaping method to a secure Base64 encoding and decoding process. This significantly enhances the security posture of the application's interaction with the Windows sandbox environment. 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
|
| const base64 = Buffer.from(text).toString("base64"); | ||
| runCommand( | ||
| "powershell", | ||
| [ | ||
| "-Command", | ||
| `Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait('${escaped}')`, | ||
| `Add-Type -AssemblyName System.Windows.Forms; $decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($decoded)`, | ||
| ], | ||
| 10000, | ||
| ); |
There was a problem hiding this comment.
Potential PowerShell Command Injection Risk
While the use of base64 encoding for the text minimizes the risk of injection, the base64 string is interpolated directly into the PowerShell command string. Although base64 encoding should not produce single quotes, it is best practice to ensure that the interpolated string cannot break out of the intended command context. Consider using double quotes around the base64 string in PowerShell, or further escaping, to ensure that even malformed or unexpected input cannot alter the command structure.
Recommended solution:
- Use double quotes around the base64 string in the PowerShell command, or validate/escape the string to ensure it cannot break the command context.
- Example:
`...FromBase64String(\"${base64}\")...` - Alternatively, use PowerShell's
-EncodedCommandparameter to avoid string interpolation entirely.
There was a problem hiding this comment.
Code Review
This pull request correctly fixes a critical command injection vulnerability in the performType and performKeypress functions by using Base64 encoding instead of string escaping. The approach is robust. My review includes a suggestion to refactor the duplicated code in these two functions to improve maintainability. While reviewing, I noticed that similar PowerShell command construction patterns exist elsewhere in the file. It would be beneficial to audit the entire file for similar patterns to ensure all potential command injection vectors are addressed comprehensively.
| const base64 = Buffer.from(text).toString("base64"); | ||
| runCommand( | ||
| "powershell", | ||
| [ | ||
| "-Command", | ||
| `Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait('${escaped}')`, | ||
| `Add-Type -AssemblyName System.Windows.Forms; $decoded = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($decoded)`, | ||
| ], | ||
| 10000, | ||
| ); |
There was a problem hiding this comment.
The logic for executing SendKeys on Windows is nearly identical in performType and performKeypress (see lines 1149-1157). To improve maintainability and follow the DRY (Don't Repeat Yourself) principle, this logic should be extracted into a dedicated helper function. This function could accept the input string and timeout as parameters, and then be called from both performType and performKeypress.
🚨 Severity: CRITICAL
💡 Vulnerability: Command injection vulnerability in
performTypeandperformKeypressvia unsanitized PowerShell commands execution when standard single-quote escaping is bypassed.🎯 Impact: Attackers who control the input string to the computer use API routes could potentially execute arbitrary PowerShell commands on the host sandbox Windows system by breaking out of the single quotes.
🔧 Fix: Substituted standard single-quote escaping mechanism with encoding arbitrary user input as a Base64 string in Node.js, and decoding it natively inside the PowerShell script block using
[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')).✅ Verification: Code formatting and lint checks run cleanly (
@biomejs/biome check). Full test suite (bun test) passed. Journal added for future reference.PR created automatically by Jules for task 10261642245202175922 started by @Dexploarer