Skip to content

Secure gitCommand#774

Merged
yamadashy merged 3 commits intoyamadashy:mainfrom
szepeviktor:patch-2
Aug 16, 2025
Merged

Secure gitCommand#774
yamadashy merged 3 commits intoyamadashy:mainfrom
szepeviktor:patch-2

Conversation

@szepeviktor
Copy link
Contributor

@szepeviktor szepeviktor commented Aug 11, 2025

I see you are trying to validate the URL by checking for hostile options.
-- prevents subsequent arguments to be interpreted as options.

Copilot AI review requested due to automatic review settings August 11, 2025 21:17
@szepeviktor szepeviktor requested a review from yamadashy as a code owner August 11, 2025 21:17
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Aug 11, 2025

Note

Other AI code review bot(s) detected

CodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review.

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Added a literal “--” separator before URLs in three git command invocations within src/core/git/gitCommand.ts to ensure URLs are parsed as arguments rather than options. No changes to exported function signatures or control flow.

Changes

Cohort / File(s) Summary
Git command arg-separation updates
src/core/git/gitCommand.ts
Inserted “--” before URL arguments in: ls-remote (heads/tags), remote add origin, and shallow clone paths to avoid misinterpreting URLs starting with “-” as options. No signature or flow changes.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~7 minutes

Possibly related PRs

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

‼️ IMPORTANT
Auto-reply has been disabled for this repository in the CodeRabbit settings. The CodeRabbit bot will not respond to your replies unless it is explicitly tagged.

  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

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

Summary of Changes

Hello @szepeviktor, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a crucial security enhancement by modifying several "git" command executions to prevent command injection vulnerabilities. Specifically, it adds the "--" argument before URL parameters in "git ls-remote", "git remote add", and "git clone" operations. This change ensures that any subsequent arguments are treated as non-option arguments, effectively neutralizing the risk of hostile options being passed through manipulated URLs.

Highlights

  • git ls-remote security: Enhanced the "execLsRemote" function by adding the "--" argument before the URL in the "git ls-remote" command. This prevents potential misinterpretation of the URL as command-line options.
  • git remote add security: Improved the "execGitShallowClone" function by inserting the "--" argument before the URL when executing "git remote add origin". This secures the command against malicious URL inputs.
  • git clone security: Applied the "--" argument before the URL in the "git clone" command within "execGitShallowClone" to ensure that the URL is always treated as a path and not as command-line options.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR enhances the security of git command execution by adding the double dash separator (--) before URLs to prevent argument injection attacks. The change ensures that URLs are treated as positional arguments rather than potentially malicious command-line options.

  • Adds -- separator before URLs in git commands to prevent option injection
  • Applies the security fix to three git operations: ls-remote, remote add, and clone
  • Maintains existing URL validation while strengthening command execution security

Copy link
Contributor

@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 makes important security improvements by using -- to prevent argument injection in git commands. The changes are a good start, but they are incomplete and also break existing tests. My review includes comments on how to fix the broken tests. Furthermore, I've identified that the same security measure should be applied to the remoteBranch parameter in execGitShallowClone to fully address potential vulnerabilities. Please see the detailed comments for specific locations and suggestions.

@szepeviktor
Copy link
Contributor Author

@yamadashy Please help me adding more commits to fix tests.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 95c52b5 and 3929c0b.

📒 Files selected for processing (1)
  • src/core/git/gitCommand.ts (3 hunks)
🔇 Additional comments (3)
src/core/git/gitCommand.ts (3)

96-96: Excellent security improvement!

Adding -- before the URL parameter prevents command injection attacks where malicious URLs starting with -- could be interpreted as git options, bypassing the existing validation in validateGitUrl().


116-116: Consistent security improvement.

The -- separator correctly prevents the URL from being interpreted as an option in the git remote add command, maintaining consistency with the security fix applied throughout the file.


157-174: Good defense-in-depth approach.

The existing validateGitUrl() function provides input validation, while the new -- separators provide robust protection against command injection at the execution level. This layered security approach ensures that even if validation misses edge cases, the command structure prevents argument injection.

szepeviktor and others added 2 commits August 14, 2025 22:45
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ents

Updated git command tests to expect the new `--` separators that were added
for security to prevent argument injection attacks. The tests now properly
validate the enhanced command arguments in execGitShallowClone and execLsRemote.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@codecov
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 88.59%. Comparing base (86c52fb) to head (e5d5349).
⚠️ Report is 4 commits behind head on main.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #774   +/-   ##
=======================================
  Coverage   88.59%   88.59%           
=======================================
  Files         110      110           
  Lines        6192     6192           
  Branches     1282     1282           
=======================================
  Hits         5486     5486           
  Misses        706      706           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@yamadashy
Copy link
Owner

@szepeviktor
Thank you for this PR as well!

Indeed, this approach should completely prevent option injection attacks.

I'll merge this!

@yamadashy yamadashy merged commit f372d0c into yamadashy:main Aug 16, 2025
52 checks passed
@szepeviktor szepeviktor deleted the patch-2 branch August 16, 2025 03:38
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.

3 participants