🛡️ Sentinel: [CRITICAL] Fix command injection in powershell#271
🛡️ Sentinel: [CRITICAL] Fix command injection in powershell#271Dexploarer 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. |
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 within the sandbox API. The fix enhances security by implementing a robust Base64 encoding and decoding strategy for user input passed to PowerShell commands, thereby preventing arbitrary command execution and strengthening the system's integrity against malicious input. 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.
Missing graceful error handling for Linux keyboard input:
The Linux branch in performType throws an error if xdotool is not available:
throw new Error("xdotool required for keyboard input on Linux.");This abrupt error may not be caught at the API layer, resulting in an unstructured error response. Consider catching this error at a higher level and returning a structured JSON error to the client, as is done elsewhere in the API.
Recommended solution:
Ensure that all platform-specific errors are caught and returned as structured API responses, e.g.:
try {
performType(text);
sendJson(res, 200, { success: true });
} catch (err) {
sendJson(res, 500, { error: String(err) });
}| throw new Error("xdotool required for key input on Linux."); | ||
| } |
There was a problem hiding this comment.
Missing graceful error handling for Linux key input:
The Linux branch in performKeypress throws an error if xdotool is not available:
throw new Error("xdotool required for key input on Linux.");This abrupt error may not be caught at the API layer, resulting in an unstructured error response. As with keyboard input, consider catching this error at a higher level and returning a structured JSON error to the client.
Recommended solution:
Wrap platform-specific calls in try/catch and return structured error responses to the API caller.
|
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 |
There was a problem hiding this comment.
Code Review
This pull request addresses a critical command injection vulnerability in the performType and performKeypress functions for Windows. The fix correctly replaces the insecure single-quote escaping with Base64 encoding of the user input, which is a robust solution to prevent command injection. My review confirms the fix is effective. I've added one comment regarding code duplication between the two modified functions, which could be addressed to improve maintainability.
| const base64 = Buffer.from(keys).toString("base64"); | ||
| runCommand( | ||
| "powershell", | ||
| [ | ||
| "-Command", | ||
| `Add-Type -AssemblyName System.Windows.Forms; [System.Windows.Forms.SendKeys]::SendWait('${escaped}')`, | ||
| `Add-Type -AssemblyName System.Windows.Forms; $txt = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($txt)`, | ||
| ], | ||
| 5000, | ||
| ); |
There was a problem hiding this comment.
This logic for handling Windows SendKeys is duplicated from the performType function (lines 1088-1096). To improve maintainability and reduce code duplication, consider extracting this logic into a shared helper function. This new function could take the input string and timeout as arguments and encapsulate the Base64 encoding and runCommand call.
🚨 Severity: CRITICAL
💡 Vulnerability: Command injection vulnerability existed in
performTypeandperformKeypresson Windows due to relying on single-quote escaping for user input passed topowershell -Command.🎯 Impact: Arbitrary command execution on the host machine via the sandbox API.
🔧 Fix: Encoded user input as a Base64 string in Node and decoded it natively inside the PowerShell script block.
✅ Verification: Verified via
bun test src/api/__tests__/sandbox-routes.test.tsand successfully documented learning in.jules/sentinel.md.PR created automatically by Jules for task 17117041012147318267 started by @Dexploarer