-
Notifications
You must be signed in to change notification settings - Fork 0
π‘οΈ Sentinel: [CRITICAL] Fix command injection in git utils #39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
β¦command injection. - Replaced `execAsync` with `execFileAsync` in `src/utils/git.ts`. - Updated `checkGitRepo`, `checkGitInstalled`, `searchCommits`, `getCommitInfo`, and `getWorkingState` to pass arguments as arrays. - Updated `src/utils/__tests__/git.spec.ts` to verify `execFile` usage. - Added `src/utils/__tests__/git_security.spec.ts` to ensure safe argument passing. - Created `.jules/sentinel.md` for security learnings. Co-authored-by: kratos06 <7855778+kratos06@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. |
π WalkthroughWalkthroughThis pull request addresses a command injection vulnerability in Git command execution by refactoring Changes
Estimated code review effortπ― 3 (Moderate) | β±οΈ ~30 minutes Poem
π₯ Pre-merge checks | β 1 | β 2β Failed checks (2 warnings)
β Passed checks (1 passed)
βοΈ Tip: You can configure your own custom pre-merge checks in the settings. β¨ Finishing touches
π§ͺ Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
π€ Fix all issues with AI agents
In @.jules/sentinel.md:
- Line 1: Update the heading date in .jules/sentinel.md from "2024-05-22 -
Command Injection in Git Utils" to the correct PR creation date "2026-02-06 -
Command Injection in Git Utils" so the security note reflects the accurate
timestamp.
π§Ή Nitpick comments (2)
src/utils/git.ts (1)
312-323: Consider guarding against argument injection on thehashparameter.While
execFileprevents shell injection,hashis passed directly as a positional argument togit showwithout validation or a--separator. If a caller ever passes a value starting with--(e.g.,--output=/tmp/evil), git could interpret it as a flag rather than a revision.Adding
--beforehashin eachgit showinvocation signals end-of-options to git:Proposed fix
const { stdout: info } = await execFileAsync( "git", - ["show", "--format=%H%n%h%n%s%n%an%n%ad%n%b", "--no-patch", hash], + ["show", "--format=%H%n%h%n%s%n%an%n%ad%n%b", "--no-patch", "--", hash], { cwd }, ) -const { stdout: stats } = await execFileAsync("git", ["show", "--stat", "--format=", hash], { cwd }) +const { stdout: stats } = await execFileAsync("git", ["show", "--stat", "--format=", "--", hash], { cwd }) -const { stdout: diff } = await execFileAsync("git", ["show", "--format=", hash], { cwd }) +const { stdout: diff } = await execFileAsync("git", ["show", "--format=", "--", hash], { cwd })src/utils/__tests__/git_security.spec.ts (1)
27-43: Thepromisifymock reimplements callback-to-promise plumbing β fragile but functional.This mock manually wires the callback convention of
execFileinto a promise. It works because the production code doespromisify(execFile), so the mock intercepts that. If the production code ever changes to useexecFilefromnode:child_process/promisesor a different promisification approach, this mock will silently stop working.This is acceptable for now, but worth noting for future maintenance.
| @@ -0,0 +1,4 @@ | |||
| ## 2024-05-22 - Command Injection in Git Utils | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incorrect date in the security note.
The heading says "2024-05-22" but this PR was created on 2026-02-06. This appears to be an error β consider updating to the correct date.
π€ Prompt for AI Agents
In @.jules/sentinel.md at line 1, Update the heading date in .jules/sentinel.md
from "2024-05-22 - Command Injection in Git Utils" to the correct PR creation
date "2026-02-06 - Command Injection in Git Utils" so the security note reflects
the accurate timestamp.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
1 issue found across 4 files
Prompt for AI agents (all issues)
Check if these issues are valid β if so, understand the root cause of each and fix them.
<file name=".jules/sentinel.md">
<violation number="1" location=".jules/sentinel.md:1">
P3: The date in the security note heading is incorrect. The note says '2024-05-22' but this fix was created on 2026-02-06. Update the date to reflect when this vulnerability was actually discovered and fixed.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.
| @@ -0,0 +1,4 @@ | |||
| ## 2024-05-22 - Command Injection in Git Utils | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P3: The date in the security note heading is incorrect. The note says '2024-05-22' but this fix was created on 2026-02-06. Update the date to reflect when this vulnerability was actually discovered and fixed.
Prompt for AI agents
Check if this issue is valid β if so, understand the root cause and fix it. At .jules/sentinel.md, line 1:
<comment>The date in the security note heading is incorrect. The note says '2024-05-22' but this fix was created on 2026-02-06. Update the date to reflect when this vulnerability was actually discovered and fixed.</comment>
<file context>
@@ -0,0 +1,4 @@
+## 2024-05-22 - Command Injection in Git Utils
+**Vulnerability:** Found a critical Command Injection vulnerability in `src/utils/git.ts`. The `searchCommits` function used `child_process.exec` with user-supplied input interpolated directly into the command string (`git log ... --grep="${query}"`). This allowed arbitrary command execution via shell metacharacters.
+**Learning:** `child_process.exec` spawns a shell (/bin/sh or cmd.exe) which interprets the command string. Always assume inputs destined for `exec` are hostile. `execFile` or `spawn` should be preferred as they execute the binary directly and treat arguments as literal strings, bypassing the shell.
</file context>
π¨ Severity: CRITICAL
π‘ Vulnerability: Command Injection in git search
π― Impact: Remote Code Execution via malicious search query
π§ Fix: Replaced child_process.exec with execFile and array arguments
β Verification: Ran unit tests including new security regression test
PR created automatically by Jules for task 4273248060135101775 started by @kratos06
Summary by cubic
Fixes a critical command injection in git utils by replacing child_process.exec with execFile and array arguments. Prevents RCE from malicious search queries and adds a regression test.
Written for commit eaf07c8. Summary will update on new commits.
Summary by CodeRabbit
Bug Fixes
Tests