GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Security: Force positional arguments to always be arguments to avoid options injection · Issue #1517 · gitpython-developers/GitPython

Security: Force positional arguments to always be arguments to avoid options injection #1517

New issue
Copy link
New issue
Copy link
Closed
Closed
Security: Force positional arguments to always be arguments to avoid options injection#1517
Copy link
Labels
acknowledgedcriticalhelp wanted

Description

@stsewd
stsewd
opened on Dec 19, 2022
Issue body actions

This is somehow related to #1515, but as a more broad problem. Gitpython exposes some methods to interact with the git program, but gitpython fails to validate/escape the arguments (user-input), resulting in the user being able to pass options to the final git command, this doesn't seem bad, but git exposes some options (--upload-pack and --receive-pack) that can lead to remote code execution.

One example is the clone() method, it receives a path

GitPython/git/repo/base.py

Line 1219 in 17ff263

path: PathLike,

But an option can be passed as well, leading to RCE, a full working example is:

import git
r = git.Repo.init('/tmp/test', bare=True)
r.clone("--upload-pack=touch /tmp/pwn")

A usual solution is to add -- before any user-input arguments, forcing them to always be taken as positional arguments and not options, but there are commands like git checkout that make special use of --, git mentions the --end-of-options option https://git-scm.com/docs/gitcli/ as an alias for -- for cases like that, but that option isn't available for git checkout 🙃

Other options could be:

  • To have a list of commands (like checkout) to not add --
  • Check all command calls and add -- manually to each one, for example

    GitPython/git/repo/base.py

    Lines 1170 to 1180 in 17ff263

    proc = git.clone(
    multi,
    Git.polish_url(str(url)),
    clone_path,
    with_extended_output=True,
    as_process=True,
    v=True,
    universal_newlines=True,
    **add_progress(kwargs, git, progress),
    )
    if progress:

    that would be git.clone(multi, '--', ...)

ref #1515 (comment).

Activity

  1. Byron
    added
    acknowledged
    critical
    help wanted
    on Dec 20, 2022
  2. Byron commented on Dec 20, 2022

    @Byron
    Byron
    on Dec 20, 2022
    Member
    More actions

    Thanks a lot for creating an issue and researching solutions as I think this will help a lot when implementing a mitigation.

    Something I'd like to highlight is that not every git command that is invoked by the GitPython API has arguments that ultimately invoke other programs or unconditionally write files that are out of repository. Thus it should be possible to focus on those that do, like git clone, and maybe others.

  3. stsewd
    added 2 commits that reference this issue on Dec 21, 2022

    Fix command injection

    3488761

    Fix command injection

    fbf9c7e
  4. stsewd
    closed this as completedon Dec 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    acknowledgedcriticalhelp wanted

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.