🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs endpoint#69
🛡️ Sentinel: [CRITICAL] Fix command injection in docker logs endpoint#69bobdivx wants to merge 1 commit into
Conversation
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 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.
| if (containerId.startsWith("-") || tail.startsWith("-")) { | ||
| return new Response(JSON.stringify({ error: "Invalid parameters" }), { | ||
| status: 400, | ||
| headers: { "Content-Type": "application/json" }, | ||
| }); | ||
| } |
There was a problem hiding this comment.
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.
tailshould only be a positive integer or the string"all".containerIdshould only contain alphanumeric characters and safe separators (like_,.,/,:,-), matching the pattern used elsewhere in the codebase (e.g.,shellSafeNameinforge-docker-ops.ts).
This prevents any unexpected argument parsing behavior or bypasses.
| 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" }, | |
| }); | |
| } |
🚨 Severity: CRITICAL
💡 Vulnerability: The
docker-logs.tsAPI route suffered from a command injection vulnerability because it concatenated user-provided input (containerIdandtail) directly into a shell string executed viaexecSync.🎯 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
execFileAsyncwith 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 testandpnpm run checksuccessfully, 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