Skip to content

🔒 Fix Command Injection in Git Operations#77

Open
ishaanxgupta wants to merge 1 commit intomainfrom
sec/fix-git-command-injection-12344443644230307895
Open

🔒 Fix Command Injection in Git Operations#77
ishaanxgupta wants to merge 1 commit intomainfrom
sec/fix-git-command-injection-12344443644230307895

Conversation

@ishaanxgupta
Copy link
Member

🎯 What: The _run_git function in src/scanner/git_ops.py took user-controlled strings (like repository URLs or branch names) and placed them directly into git CLI commands without validation or delimiting. If a user provided an argument like --upload-pack=malicious as a repository URL, Git would interpret it as a command option instead of a positional argument. This commit adds a validation step (_validate_no_options) to prevent string arguments starting with - from reaching the git command, and explicitly appends -- for git clone to separate options from positional arguments correctly.

⚠️ Risk: Left unfixed, an attacker could achieve arbitrary code execution or disclose repository secrets on the system running this pipeline by manipulating branch names or repository URLs passed to the clone_repo or pull_latest functions.

🛡️ Solution:

  1. Implemented a _validate_no_options helper that checks if user-supplied strings begin with - and raises a ValueError if so.
  2. Hardened the git clone command in clone_repo to append -- right before the positional arguments (repo_url and local_path). (Note: -- was specifically avoided in git pull and git checkout as they misinterpret it due to how those commands parse pathspecs/refs).
  3. Added robust unit tests verifying both successful commands and correct rejection of injection payloads.

PR created automatically by Jules for task 12344443644230307895 started by @ishaanxgupta

@google-labs-jules
Copy link

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

@ishaanxgupta ishaanxgupta marked this pull request as ready for review March 9, 2026 07:21
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