🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs API#120
🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs API#120bobdivx wants to merge 1 commit into
Conversation
🚨 Severity: CRITICAL 💡 Vulnerability: Command injection in `src/pages/api/docker-logs.ts` via the `containerId` and `tail` parameters, which were unsanitized and directly concatenated into an `execSync` shell execution. 🎯 Impact: An attacker could execute arbitrary shell commands on the host by passing crafted payloads (e.g., `; rm -rf /`) or by injecting flags (e.g., `--help`). 🔧 Fix: Refactored to use `execFileAsync` which avoids shell evaluation by passing arguments explicitly as an array. Added defense-in-depth with strict regex validation for both `containerId` (rejecting special characters and starting hyphens) and `tail`. Also sanitized error leakage in catch blocks. ✅ Verification: Ran `pnpm run check` and `pnpm test` to ensure no regressions. Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com>
|
👋 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. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Code Review
This pull request addresses a critical command injection vulnerability in the docker-logs API route by replacing execSync with execFileAsync, implementing strict regex validation for the containerId and tail parameters, and sanitizing error responses. Additionally, a sentinel file is added to document the vulnerability and its prevention. The review feedback highlights an issue with how the command's output streams are handled: using (stdout || stderr) ignores stderr when stdout is populated, and empty outputs can result in an array containing a single empty string. A suggestion is provided to combine both streams and handle empty logs correctly.
Important
The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.
| const { stdout, stderr } = await execFileAsync('docker', ['logs', '--tail', tail, '--', containerId]); | ||
| logs = (stdout || stderr).trim().split('\n'); |
There was a problem hiding this comment.
Using (stdout || stderr) means that if stdout is non-empty, stderr is completely ignored. Since Docker containers can write to both streams, any logs written to stderr (such as error messages or warnings) will be lost if the container also outputs to stdout. Additionally, if both streams are empty, "".trim().split('\n') will produce [""] instead of an empty array.
We should combine both streams and handle empty logs correctly.
const { stdout, stderr } = await execFileAsync('docker', ['logs', '--tail', tail, '--', containerId]);
const combined = [stdout, stderr].filter(Boolean).join('\n').trim();
logs = combined ? combined.split('\n') : [];
🚨 Severity: CRITICAL
💡 Vulnerability: Command injection in
src/pages/api/docker-logs.tsvia thecontainerIdandtailparameters, which were unsanitized and directly concatenated into anexecSyncshell execution.🎯 Impact: An attacker could execute arbitrary shell commands on the host by passing crafted payloads (e.g.,
; rm -rf /) or by injecting flags (e.g.,--help).🔧 Fix: Refactored to use
execFileAsyncwhich avoids shell evaluation by passing arguments explicitly as an array. Added defense-in-depth with strict regex validation for bothcontainerId(rejecting special characters and starting hyphens) andtail. Also sanitized error leakage in catch blocks.✅ Verification: Ran
pnpm run checkandpnpm testto ensure no regressions.PR created automatically by Jules for task 17299975664885029344 started by @bobdivx