Skip to content

🛡️ Sentinel: [CRITICAL] Fix command injection in multiple API routes#81

Open
bobdivx wants to merge 1 commit into
devfrom
sentinel-command-injection-fix-9804105707731073344
Open

🛡️ Sentinel: [CRITICAL] Fix command injection in multiple API routes#81
bobdivx wants to merge 1 commit into
devfrom
sentinel-command-injection-fix-9804105707731073344

Conversation

@bobdivx
Copy link
Copy Markdown
Owner

@bobdivx bobdivx commented May 31, 2026

🚨 Severity: CRITICAL
💡 Vulnerability: Command injection in docker-logs.ts, docker-health.ts, and github-clone.ts due to unsafe usage of execSync and exec with string interpolation.
🎯 Impact: Attackers could inject arbitrary commands into the host shell, leading to Remote Code Execution (RCE) and system compromise.
🔧 Fix: Refactored execSync and exec to execFileAsync with proper argument arrays. Used -- for git commands to prevent argument injection, and added strict input validation regexes for identifiers. Prevented token leaks in error messages.
✅ Verification: Ensure pnpm run check and pnpm test pass. Manually test API endpoints to ensure normal behavior works and malicious inputs (e.g. id=; echo oops) are safely handled.


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

🚨 Severity: CRITICAL
💡 Vulnerability: Command injection in `docker-logs.ts`, `docker-health.ts`, and `github-clone.ts` due to unsafe usage of `execSync` and `exec` with string interpolation.
🎯 Impact: Attackers could inject arbitrary commands into the host shell, leading to Remote Code Execution (RCE) and system compromise.
🔧 Fix: Refactored `execSync` and `exec` to `execFileAsync` with proper argument arrays. Used `--` for git commands to prevent argument injection, and added strict input validation regexes for identifiers. Prevented token leaks in error messages.
✅ Verification: Ensure `pnpm run check` and `pnpm test` pass. Manually test API endpoints to ensure normal behavior works and malicious inputs (e.g. `id=; echo oops`) are safely handled.

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 31, 2026

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

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

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 mitigates command injection vulnerabilities across several API routes (docker-health.ts, docker-logs.ts, and github-clone.ts) by replacing shell execution with execFile and utilizing explicit argument arrays. It also introduces input validation and sanitizes error messages to prevent credential leaks. The review feedback highlights opportunities to improve these changes: restoring support for the tail=all option in Docker logs, utilizing the robust URL API for parsing and credential injection in the GitHub clone route, and reusing the existing isSafeRepoDirName helper function for repository name validation.

Comment on lines +35 to +36
const tailNum = parseInt(tail, 10);
const validTail = isNaN(tailNum) ? '100' : String(tailNum);
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

The current validation of tail using parseInt breaks the tail=all functionality, which is a valid and common option in Docker logs. Additionally, it does not handle negative numbers gracefully. We can simplify and secure this by validating that tail is either exactly 'all' or a non-negative integer using a regular expression.

Suggested change
const tailNum = parseInt(tail, 10);
const validTail = isNaN(tailNum) ? '100' : String(tailNum);
const validTail = (tail === 'all' || /^\d+$/.test(tail)) ? tail : '100';

Comment on lines +39 to 42
if (!repoUrl.startsWith('https://github.com/')) {
return new Response(JSON.stringify({ error: 'URL Github invalide' }), { status: 400 });
}
const authUrl = repoUrl.replace('https://', `https://oauth2:${githubToken}@`);
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-high high

Using simple string replacement (replace('https://', ...)) and startsWith for URL validation and credential injection can be fragile and prone to parsing discrepancies. Utilizing the built-in URL API is much more robust and secure, ensuring that the protocol is strictly https: and the hostname is strictly github.com, while safely injecting the credentials without manual string manipulation.

    let parsedUrl: URL;
    try {
      parsedUrl = new URL(repoUrl);
      if (parsedUrl.protocol !== 'https:' || parsedUrl.hostname !== 'github.com') {
        return new Response(JSON.stringify({ error: 'URL Github invalide' }), { status: 400 });
      }
    } catch {
      return new Response(JSON.stringify({ error: 'URL Github invalide' }), { status: 400 });
    }
    parsedUrl.username = 'oauth2';
    parsedUrl.password = githubToken;
    const authUrl = parsedUrl.toString();

Comment on lines +20 to +22
if (!/^[a-zA-Z0-9_.-]+$/.test(repoName) || repoName.includes('..')) {
return new Response(JSON.stringify({ error: 'Nom de dépôt invalide' }), { status: 400 });
}
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

Instead of writing a custom regex to validate the repository name, you can reuse the existing isSafeRepoDirName helper function from src/lib/forge-repos.ts to ensure consistency and maintainability across the codebase. Note that you will also need to add isSafeRepoDirName to the imports from ../../lib/forge-repos.

Suggested change
if (!/^[a-zA-Z0-9_.-]+$/.test(repoName) || repoName.includes('..')) {
return new Response(JSON.stringify({ error: 'Nom de dépôt invalide' }), { status: 400 });
}
if (!isSafeRepoDirName(repoName) || repoName === '.' || repoName === '..') {
return new Response(JSON.stringify({ error: 'Nom de dépôt invalide' }), { status: 400 });
}

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