You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
To avoid part of the problem, gitpython should also avoid interpreting positional arguments as option arguments.
First, I was thinking in adding -- after the option args
Am I the only one confused by trying to fix a problem in the underlying git executable by trying to prevent all misuse in the layer above?
Trying to do that, to my mind, will not deter an attacker who wants to find a bypass, and is much more likely to break downstream legitimate code, or use-cases for the now deemed unsafe features. There is clearly a tradeoff that seems impossible to get right.
git by now has a history of making backwards incompatible changes by forbidding certain protocols or checking for ownership of repositories on shared file systems. Thus my preference here is to let it fix itself.
Those who pass user-input to GitPython or the git binary for that matter are obliged to validate it, and I would be all for such code to be shared in GitPython as well. Validating or sanitizing a URL seems useful, for example. If it's most definitely not breaking current legitimate uses, this could be the default like attempted in #1516 which also allows to opt-out from the potentially breaking feature.
Without shell in the middle a url like this should be just a single string passed to git as URL and it clearly detects something is up.
✦ ❯ git clone "https://clean.already.com/repo --hahaha='exploit town'",
Cloning into 'repo --hahaha='exploit town','...
fatal: unable to access 'https://clean.already.com/repo --hahaha='exploit town',/': URL using bad/illegal format or missing URL
For a moment I thought maybe git doesn't validate enough and passes on abusive URLs to sub-programs through a shell, but that fortunately doesn't seem to be the case.
Those who pass user-input to GitPython or the git binary for that matter are obliged to validate it, and I would be all for such code to be shared in GitPython as well
Don't you agree that methods like clone that are expecting a path/url
I agree, and now I understand what the prior comment is about as well. And it seems not too unlikely that url and path could be used to construct a command-line which uses --upload-pack='attack vector'. Once URL is a little more validated, that should get harder as well. Using --upload-pack is only possible with the ssh scheme and I'd expect only personal-use grade servers to expose more than just git-upload-pack and git-receive-pack in their PATH.
I think once it can be demonstrated that one can indeed execute programs on the server by manipulating the URL or maybe even the URL + destination path, that would be an issue specific to GitPython and worth its own issue.
I think once it can be demonstrated that one can indeed execute programs on the server by manipulating the URL or maybe even the URL + destination path, that would be an issue specific to GitPython and worth its own issue.
That's already possible, and with normal repos, not only ssh repos. The command is executed on the machine that executes gitpython.
That I find really bad, and even though GitPython doesn't do word splitting, such an argument is neatly parsed by git leading to the execution of a program. As it stands, that wouldn't be caught by #1516 either. Maybe we should have a separate issue for that - please feel free to create one if you agree @stsewd .
The library for git is on the way, it's called gitoxide and I will find a way to transition GitPython to using gitoxide's python bindings one day, when these exists. I definitely can't maintain GitPython for another decade if it stays like this 😅.
I assume @blade2005 meant that there is no native git library that git itself would be using, hence git provides an API via the command-line exclusively. libgit2 is a separate effort which, by now, does not provide feature and performance parity with git itself anymore.
@nrpt-m that PR fixes a similar vulnerability which doesn't require passing any extra options to multi_options to be able to exploit it, #1521 will fix the vulnerability when users allow passing any options to multi_options.
A special thanks goes to @stsewd who was a driving force behind implementing the fixes, and to the fine folks who discovered it.
I hope this makes the upcoming year 2023 a little more secure for everyone tada.
Can a release be made in Github? I imagine a nonzero number of people are watching for releases in this repository who aren't subscribed to this issue to be aware of the security impact of this release.
Activity
Forbid unsafe protocol URLs in Repo.clone_from()
Forbid unsafe protocol URLs in Repo.clone_from()
stsewd commentedon Dec 15, 2022
To avoid part of the problem, gitpython should also avoid interpreting positional arguments as option arguments.
First, I was thinking in adding
--after the option argsGitPython/git/cmd.py
Line 1244 in 17ff263
but there are commands like git checkout that make special use of
--, git mentions the--end-of-optionsoption https://git-scm.com/docs/gitcli/ as an alias for--for cases like that, but that option isn't available forgit checkout🙃Other options could be:
----manually to each one, for exampleGitPython/git/repo/base.py
Lines 1170 to 1180 in 17ff263
that would be
git.clone(multi, '--', ...)Byron commentedon Dec 16, 2022
Am I the only one confused by trying to fix a problem in the underlying
gitexecutable by trying to prevent all misuse in the layer above?Trying to do that, to my mind, will not deter an attacker who wants to find a bypass, and is much more likely to break downstream legitimate code, or use-cases for the now deemed unsafe features. There is clearly a tradeoff that seems impossible to get right.
gitby now has a history of making backwards incompatible changes by forbidding certain protocols or checking for ownership of repositories on shared file systems. Thus my preference here is to let it fix itself.Those who pass user-input to
GitPythonor thegitbinary for that matter are obliged to validate it, and I would be all for such code to be shared inGitPythonas well. Validating or sanitizing a URL seems useful, for example. If it's most definitely not breaking current legitimate uses, this could be the default like attempted in #1516 which also allows to opt-out from the potentially breaking feature.Anthony-Mckale commentedon Dec 16, 2022
we're using this in eze
https://github.com/RiverSafeUK/eze-cli
Byron commentedon Dec 16, 2022
Thanks for sharing!
Have you validated that URL injection works? After all the shell seems to be disabled by default and isn't enabled when calling clone either.
Without shell in the middle a url like this should be just a single string passed to
gitas URL and it clearly detects something is up.For a moment I thought maybe
gitdoesn't validate enough and passes on abusive URLs to sub-programs through a shell, but that fortunately doesn't seem to be the case.stsewd commentedon Dec 16, 2022
Don't you agree that methods like clone that are expecting a path/url
GitPython/git/repo/base.py
Line 1219 in 17ff263
--fooand that's interpreted as an option, that is unexpected/wrong.Byron commentedon Dec 16, 2022
I agree, and now I understand what the prior comment is about as well. And it seems not too unlikely that
urlandpathcould be used to construct a command-line which uses--upload-pack='attack vector'. Once URL is a little more validated, that should get harder as well. Using--upload-packis only possible with the ssh scheme and I'd expect only personal-use grade servers to expose more than justgit-upload-packandgit-receive-packin theirPATH.I think once it can be demonstrated that one can indeed execute programs on the server by manipulating the URL or maybe even the URL + destination path, that would be an issue specific to
GitPythonand worth its own issue.stsewd commentedon Dec 17, 2022
That's already possible, and with normal repos, not only ssh repos. The command is executed on the machine that executes gitpython.
Byron commentedon Dec 19, 2022
That I find really bad, and even though
GitPythondoesn't do word splitting, such an argument is neatly parsed bygitleading to the execution of a program. As it stands, that wouldn't be caught by #1516 either. Maybe we should have a separate issue for that - please feel free to create one if you agree @stsewd .stsewd commentedon Dec 19, 2022
@Byron #1517
Forbid unsafe protocol URLs in Repo.clone{,_from}()
Forbid unsafe protocol URLs in Repo.clone{,_from}()
Temporarily disable Bandit, which depends on GitPython
Forbid unsafe protocol URLs in Repo.clone{,_from}()
Byron commentedon Dec 24, 2022
The library for
gitis on the way, it's calledgitoxideand I will find a way to transitionGitPythonto usinggitoxide's python bindings one day, when these exists. I definitely can't maintainGitPythonfor another decade if it stays like this 😅.mcepl commentedon Dec 24, 2022
Well, it does (https://libgit2.org/), doesn’t it?
Byron commentedon Dec 24, 2022
I assume @blade2005 meant that there is no native
gitlibrary thatgititself would be using, hencegitprovides an API via the command-line exclusively.libgit2is a separate effort which, by now, does not provide feature and performance parity withgititself anymore.nrpt-m commentedon Dec 28, 2022
@Byron Could you please confirm if this PR #1518 is fixing CVE-2022-24439 issue as it has been added to 3.1.30 ?
stsewd commentedon Dec 28, 2022
@nrpt-m that PR fixes a similar vulnerability which doesn't require passing any extra options to
multi_optionsto be able to exploit it, #1521 will fix the vulnerability when users allow passing any options tomulti_options.Byron commentedon Dec 29, 2022
@nrpt-m I second that.
Byron commentedon Dec 29, 2022
A new release was created to incorporate many security related fixes.
A special thanks goes to @stsewd who was a driving force behind implementing the fixes, and to the fine folks who discovered it.
I hope this makes the upcoming year 2023 a little more secure for everyone 🎉.
ajakk commentedon Dec 30, 2022
Can a release be made in Github? I imagine a nonzero number of people are watching for releases in this repository who aren't subscribed to this issue to be aware of the security impact of this release.
Byron commentedon Dec 31, 2022
Thanks for the hint. That should be done now.
Update git submodules
Bump GitPython to 3.1.30
py-gitpython: updated to 3.1.30
Mark unsafe-options "allowed" tests xfail on Windows
Mark unsafe-options "allowed" tests xfail on Windows
Mark unsafe-options "allowed" tests xfail on Windows
Mark unsafe-options "allowed" tests xfail on Windows
Mark unsafe-options "allowed" tests xfail on Windows
Mark unsafe-options "allowed" tests xfail on Windows
py-gitpython: updated to 3.1.30
py-gitpython: updated to 3.1.30
py-gitpython: updated to 3.1.30