Skip to content

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

Open
bobdivx wants to merge 1 commit into
devfrom
sentinel/fix-docker-logs-command-injection-17299975664885029344
Open

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

Conversation

@bobdivx

@bobdivx bobdivx commented Jun 15, 2026

Copy link
Copy Markdown
Owner

🚨 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.


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

🚨 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>
@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 15, 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 15, 2026 5:42pm

@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 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.

Comment on lines +36 to +37
const { stdout, stderr } = await execFileAsync('docker', ['logs', '--tail', tail, '--', containerId]);
logs = (stdout || stderr).trim().split('\n');

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

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') : [];

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