Skip to content

🛡️ Sentinel: [CRITICAL] Fix Command Injection in docker logs#24

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

🛡️ Sentinel: [CRITICAL] Fix Command Injection in docker logs#24
bobdivx wants to merge 1 commit into
devfrom
sentinel/fix-command-injection-docker-logs-8291986119183605751

Conversation

@bobdivx
Copy link
Copy Markdown
Owner

@bobdivx bobdivx commented May 10, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: User input (id and tail) was passed directly into a shell command string evaluated by execSync in the docker-logs API endpoint.
🎯 Impact: An attacker could perform arbitrary command execution by passing a malicious payload like id=fake-container; echo 'vulnerable'.
🔧 Fix: Refactored the endpoint to use execFileSync passing arguments as an array, bypassing shell evaluation. Added regex validation to block invalid characters and leading hyphens (preventing flag injection). Sanitized the tail parameter by parsing it strictly as an integer.
✅ Verification: pnpm run check and pnpm test pass. The fix ensures that inputs containing command separators or flags are rejected safely.


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

Migrated from execSync to execFileSync in src/pages/api/docker-logs.ts,
passing arguments as an array instead of concatenating strings. Added
regex input validation to ensure the containerId parameter only contains
valid characters and does not start with a hyphen to prevent flag injection.
Safely parsed the tail parameter as an integer.

Co-authored-by: bobdivx <6737167+bobdivx@users.noreply.github.com>
@vercel
Copy link
Copy Markdown

vercel Bot commented May 10, 2026

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

Project Deployment Actions Updated (UTC)
forge Ready Ready Preview, Comment May 10, 2026 5:53pm

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

Copy link
Copy Markdown

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

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 fixes a command injection vulnerability in the Docker logs API by replacing string-interpolated execSync calls with execFileSync and adding strict input validation for the containerId and tail parameters. Review feedback suggests further optimizing the implementation by using asynchronous execFile to prevent blocking the event loop and improving the log parsing logic to handle different line endings and empty outputs more robustly.

@@ -1,5 +1,5 @@
import type { APIRoute } from 'astro';
import { execSync } from 'child_process';
import { execFileSync } from 'child_process';
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

Using synchronous child process methods like execFileSync in an asynchronous API route blocks the Node.js event loop, which can severely impact the performance and scalability of the server. It is recommended to use the asynchronous execFile version, ideally promisified to maintain clean async/await syntax, as seen in other parts of the codebase (e.g., src/pages/api/docker/containers.ts).

import { execFile } from 'child_process';
import { promisify } from 'util';

const execFileAsync = promisify(execFile);

Comment on lines +42 to +45
const output = execFileSync('docker', ['logs', '--tail', tailParam, containerId], {
stdio: ['pipe', 'pipe', 'pipe'],
encoding: 'utf-8'
});
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

Switching to the asynchronous execFileAsync prevents blocking the event loop while waiting for the Docker command to complete. This is especially important for log retrieval which might take some time depending on the container's output.

        const { stdout: output } = await execFileAsync('docker', ['logs', '--tail', tailParam, containerId], {
          encoding: 'utf-8'
        });

stdio: ['pipe', 'pipe', 'pipe'],
encoding: 'utf-8'
});
logs = output.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.

medium

The current split logic can result in an array containing an empty string if the output is empty or contains only whitespace. Using a regex for line breaks and filtering out empty strings ensures a cleaner result and better compatibility with different operating systems (handling \r\n).

Suggested change
logs = output.trim().split('\n');
logs = output.trim().split(/\r?\n/).filter(Boolean);

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