Skip to content

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

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

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

Conversation

@bobdivx
Copy link
Copy Markdown
Owner

@bobdivx bobdivx commented May 27, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: The docker-logs.ts API route suffered from a command injection vulnerability because it concatenated user-provided input (containerId and tail) directly into a shell string executed via execSync.
🎯 Impact: An attacker could execute arbitrary system commands on the host by passing crafted payloads (e.g., ; rm -rf /) in the URL parameters.
🔧 Fix: Refactored the endpoint to use execFileAsync with an arguments array, explicitly preventing shell interpretation. Also added validation to block flag injection (inputs starting with -) and sanitized the error message to avoid leaking sensitive internal paths.
✅ Verification: Ran pnpm test and pnpm run check successfully, and manually confirmed using local test scripts that parameter inputs are now passed securely to the docker executable without shell expansion.


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

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
Copy link
Copy Markdown

vercel Bot commented May 27, 2026

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

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

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 refactors the Docker logs API endpoint to improve security by replacing synchronous execSync with asynchronous execFile to prevent command injection, adding basic flag injection checks, and sanitizing error messages. The reviewer recommends strengthening the input validation for containerId and tail using strict regular expressions instead of a simple prefix check to prevent potential bypasses.

Comment on lines +34 to 39
if (containerId.startsWith("-") || tail.startsWith("-")) {
return new Response(JSON.stringify({ error: "Invalid parameters" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

security-medium medium

While checking if the parameters start with - helps prevent basic flag injection, it is much safer and more robust to validate both containerId and tail using strict regular expressions.

  • tail should only be a positive integer or the string "all".
  • containerId should only contain alphanumeric characters and safe separators (like _, ., /, :, -), matching the pattern used elsewhere in the codebase (e.g., shellSafeName in forge-docker-ops.ts).

This prevents any unexpected argument parsing behavior or bypasses.

Suggested change
if (containerId.startsWith("-") || tail.startsWith("-")) {
return new Response(JSON.stringify({ error: "Invalid parameters" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}
if (!/^[A-Za-z0-9_./:-]+$/.test(containerId) || !/^(all|\d+)$/.test(tail)) {
return new Response(JSON.stringify({ error: "Invalid parameters" }), {
status: 400,
headers: { "Content-Type": "application/json" },
});
}

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