Skip to content

🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs#111

Open
bobdivx wants to merge 1 commit into
devfrom
sentinel-fix-docker-logs-injection-13471979432134239327
Open

🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs#111
bobdivx wants to merge 1 commit into
devfrom
sentinel-fix-docker-logs-injection-13471979432134239327

Conversation

@bobdivx

@bobdivx bobdivx commented Jun 12, 2026

Copy link
Copy Markdown
Owner

🚨 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("docker logs...").
🎯 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.


PR created automatically by Jules for task 13471979432134239327 started by @bobdivx

🚨 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>
@google-labs-jules

Copy link
Copy Markdown

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@vercel

vercel Bot commented Jun 12, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
forge Ready Ready Preview, Comment Jun 12, 2026 5:27pm

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +55 to 80
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;
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant