🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs#111
🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs#111bobdivx wants to merge 1 commit into
Conversation
🚨 Severity: CRITICAL 💡 Vulnerability: Command injection vulnerability in `src/pages/api/docker-logs.ts` caused by unsanitized URL parameters (`tail` and `containerId`) being passed directly to `execSync`. 🎯 Impact: Attackers could append arbitrary shell commands to the `containerId` or `tail` parameters to execute arbitrary code on the host system. 🔧 Fix: Added strict regex validation for `containerId` and `tail`. Replaced `execSync` with `execFileAsync` utilizing an argument array to prevent shell interpretation. Also sanitized error output to prevent internal information leakage. ✅ Verification: Tested via `pnpm test` and `pnpm run check` 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 command injection vulnerability in the Docker logs API endpoint by switching from execSync to execFileAsync and adding strict input validation for containerId and tail. It also documents this vulnerability in .jules/sentinel.md. The reviewer noted that the inner try-catch block around execFileAsync is unnecessary and misleading; if the command fails and throws an error, it should propagate to the outer catch block to return a 500 error rather than attempting to parse err.stderr as valid logs.
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.
| let logs: string[] = []; | ||
| try { | ||
| const output = execSync(command, { stdio: ['pipe', 'pipe', 'pipe'] }).toString(); | ||
| logs = output.trim().split('\n'); | ||
| const { stdout, stderr } = await execFileAsync("docker", [ | ||
| "logs", | ||
| "--tail", | ||
| tail, | ||
| containerId, | ||
| ]); | ||
| // Docker logs can go to either stdout or stderr depending on the containerized app | ||
| const combinedOutput = stdout + (stderr ? "\n" + stderr : ""); | ||
| logs = combinedOutput | ||
| .trim() | ||
| .split("\n") | ||
| .filter((line) => line.length > 0); | ||
| } catch (err: any) { | ||
| // Certains logs sortent sur stderr, checkons stderr si stdout est vide ou si erreur | ||
| if (err.stderr) { | ||
| logs = err.stderr.toString().trim().split('\n'); | ||
| } else { | ||
| throw err; | ||
| } | ||
| // Handle command failure, but check if we got output in stderr anyway | ||
| if (err.stderr) { | ||
| logs = err.stderr | ||
| .toString() | ||
| .trim() | ||
| .split("\n") | ||
| .filter((line: string) => line.length > 0); | ||
| } else { | ||
| throw err; | ||
| } | ||
| } |
There was a problem hiding this comment.
When a containerized application writes to stderr, the docker logs command still exits with code 0 (success). Therefore, execFileAsync will not throw an error, and combinedOutput will correctly capture both stdout and stderr under normal operation.
If execFileAsync actually throws an error (entering the catch block), it means the docker logs command itself failed (e.g., the container does not exist, or the Docker daemon is down). In these failure cases, treating err.stderr as valid container logs and returning a 200 OK response is incorrect and misleading to the client.
We should remove the inner try-catch block entirely and let any actual command failures propagate to the outer catch block, which correctly returns a 500 error response.
const { stdout, stderr } = await execFileAsync("docker", [
"logs",
"--tail",
tail,
containerId,
]);
// Docker logs can go to either stdout or stderr depending on the containerized app
const combinedOutput = stdout + (stderr ? "\n" + stderr : "");
const logs = combinedOutput
.trim()
.split("\n")
.filter((line) => line.length > 0);
🚨 Severity: CRITICAL
💡 Vulnerability: Command injection vulnerability in
src/pages/api/docker-logs.tscaused by unsanitized URL parameters (tailandcontainerId) being passed directly toexecSync("docker logs...").🎯 Impact: Attackers could append arbitrary shell commands to the
containerIdortailparameters to execute arbitrary code on the host system.🔧 Fix: Added strict regex validation for
containerIdandtail. ReplacedexecSyncwithexecFileAsyncutilizing an argument array to prevent shell interpretation. Also sanitized error output to prevent internal information leakage.✅ Verification: Tested via
pnpm testandpnpm run checkto ensure no regressions.PR created automatically by Jules for task 13471979432134239327 started by @bobdivx