🛡️ Sentinel: [CRITICAL] Fix PowerShell command injection vulnerability#275
🛡️ Sentinel: [CRITICAL] Fix PowerShell command injection vulnerability#275Dexploarer wants to merge 1 commit intomainfrom
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 delivers a critical security update by patching a PowerShell command injection vulnerability affecting Windows environments. The change significantly enhances the security posture of the application by ensuring that user-provided input, when used in PowerShell commands, is no longer susceptible to malicious command injection, thereby preventing potential arbitrary code execution. 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.
The function throws an error if xdotool is not available on Linux, which is consistent with other platform branches. However, this may result in an unhandled exception if not properly caught upstream. Consider ensuring that all such errors are caught at the API boundary and returned as user-friendly error responses, or check for the presence of a graphical environment before attempting to use xdotool to provide more informative feedback in headless environments.
There was a problem hiding this comment.
Code Review
This pull request effectively addresses a critical PowerShell command injection vulnerability by replacing insecure string escaping with Base64 encoding when passing user input to SendKeys on Windows. The fix is correctly applied in both performType and performKeypress functions. My review includes a suggestion to refactor the duplicated logic into a helper function to improve code maintainability.
| 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; $txt = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($txt)`, | ||
| ], | ||
| 10000, | ||
| ); |
There was a problem hiding this comment.
This block of code for handling Windows SendKeys is nearly identical to the one in performKeypress (lines 1150-1158). The only differences are the input variable and the timeout value.
To improve maintainability and reduce code duplication, consider extracting this logic into a helper function. For example:
function runSendKeysOnWindows(text: string, timeout: number): void {
const base64 = Buffer.from(text).toString("base64");
const command = `Add-Type -AssemblyName System.Windows.Forms; $txt = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}')); [System.Windows.Forms.SendKeys]::SendWait($txt)`;
runCommand("powershell", ["-Command", command], timeout);
}Then you could call it from both performType and performKeypress like this:
// in performType
runSendKeysOnWindows(text, 10000);
// in performKeypress
runSendKeysOnWindows(keys, 5000);| 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, | ||
| ); |
🚨 Severity: CRITICAL
💡 Vulnerability: User input passed to
powershell -CommandviaexecFileSyncwas only protected by simple single-quote escaping (text.replace(/'/g, "''")), allowing attackers to potentially bypass escaping and execute arbitrary PowerShell commands on Windows platforms.🎯 Impact: An attacker could bypass the single-quote escaping logic and inject arbitrary shell commands on a Windows host when simulating typing or key presses in the sandbox.
🔧 Fix: Encoded arbitrary user input as a Base64 string in Node (
Buffer.from(text).toString('base64')) and decoded it natively inside the PowerShell script block using[System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String('${base64}'))to safely isolate the data from command interpretation.✅ Verification: Ran unit tests using
bun test src/api/__tests__/sandbox-routes.test.tsto ensure sandbox route logic remains functional and no regressions were introduced.PR created automatically by Jules for task 12193979712861818234 started by @Dexploarer