safe mode to disable executing any external programs except git by eighthave · Pull Request #2029 · gitpython-developers/GitPython
Repository navigation
safe mode to disable executing any external programs except git - #2029
Closed
eighthave wants to merge 1 commit into gitpython-developers:main from eighthave:safe-mode
Closed
safe mode to disable executing any external programs except git #2029 eighthave wants to merge 1 commit into gitpython-developers:main from eighthave:safe-mode
Conversation
eighthave commented May 26, 2025 · edited Loading
Copy link Copy Markdown
As described in #2020 , here is the core implementation of "safe mode". The core idea is to set up operations so that external programs are not executed by git. This has been a major source of vulnerabilities.
This means that network connections are limited to HTTPS. As much as possible, this will rewrite remote URLs to HTTPS. This is necessary so that submodules work even when they do not use HTTPS URLs, as long as they are public, HTTPS-accessible repos.
This is a draft to confirm the approach. Then I will follow up and polish everything for merging.
closes #2020
eighthave mentioned this pull request May 26, 2025 I would like to contribute a "safe mode" for working with untrusted repos #2020 Open Byron marked this pull request as draft May 27, 2025 02:21 Byron reviewed May 27, 2025View reviewed changes
Byron left a comment
Copy link Copy Markdown
Member
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
Thanks a lot for the preview - I see now how this can work and like that it seems to be minimally invasive overall.
I assume that the testing will primarily be done by hand for ease of use but hope that some sort of 'practical' test-case could be contributed as well.
eighthave commented May 27, 2025
Copy link Copy Markdown
Author
|
I would like to write tests, I looked around through the test suite, but it still escapes me how to structure these tests. Since these options affect how |
Byron commented May 27, 2025
Copy link Copy Markdown
Member
|
It really isn't easy to test it at all, and probably impossible to test it exhaustively. So I am fine admitting defeat on this one, particularly because the tests I could imagine would be so specific and spotty that they barely have any value. |
gcmarx commented May 27, 2025
Copy link Copy Markdown
Contributor
|
if we can only run |
EliahKagan commented May 28, 2025 · edited Loading
Copy link Copy Markdown
Member
I haven't reviewed this draft PR in detail, and I also don't know what it will be like and how it will document the "safe mode" feature once it's done. But my first impression is that the changes being proposed here should not directly impose any requirements on whether
However, that may not be the whole story. Although I don't think "safe mode" should prohibit the use of subprocesses in Furthermore, regarding the use of |
View reviewed changes
EliahKagan left a comment
Copy link Copy Markdown
Member
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
I noticed a couple of things related to unusual but plausible command arguments.
509d0c5 to
2ab2ea9
Compare
May 28, 2025 16:28
eighthave commented May 28, 2025
Copy link Copy Markdown
Author
|
FYI this is my very simple test suite: #!/usr/bin/python3
import os
import git
import tempfile
for url in [
'git@gitlab.com:fdroid/ci-test-app.git',
'ssh://gitlab.com/fdroid/ci-test-app.git',
'git://gitlab.com/fdroid/ci-test-app.git',
]:
print('====================', url)
d = tempfile.mkdtemp(prefix='foo_py_')
repo = git.Repo.clone_from(url, d, safe=True)
# clone from fake URL should prompt for password
d = tempfile.mkdtemp(prefix='foo_py_')
for url in [
'https://github.com/asdfasdfasdf/adsfasdfasdf.git',
'https://gitlab.com/asdfasdfasdf/adsfasdfasdf.git',
'https://codeberg.org/asdfasdfasdf/adsfasdfasdf.git',
]:
try:
repo = git.Repo.clone_from(url, d, safe=True)
except git.exc.GitCommandError as e:
print('repo', e)
url = 'https://gitlab.com/fdroid/ci-test-app.git'
d = tempfile.mkdtemp(prefix='foo_py_')
print(d)
repo = git.Repo.init(d, safe=True)
origin = repo.create_remote("origin", url)
origin.fetch()
d = tempfile.mkdtemp(prefix='foo_py_')
print(d)
repo = git.Repo.clone_from(url, d, safe=True)
print(type(repo))
print('SUCCESS')
|
9dcf381 to
07a3889
Compare
June 2, 2025 08:40 eighthave marked this pull request as ready for review June 2, 2025 09:01 eighthave requested a review from EliahKagan June 2, 2025 09:01 eighthave changed the title Draft: safe mode to disable executing any external programs except git safe mode to disable executing any external programs except git Jun 2, 2025
Byron commented Jun 3, 2025
Copy link Copy Markdown
Member
|
I think I should leave it to @EliahKagan to review this PR, due to its nature of being very relevant to the security of the project. To me it still is the question if there is a good case for supporting this - I'd think the answer should be "yes" if f-droid benefits, but I fear that it lures people into a false sense of safety. Maybe |
eighthave commented Jun 3, 2025 · edited Loading
Copy link Copy Markdown
Author
|
F-Droid has been using this approach for years, and will switch to this code once it is merged. As for the name, I'm open to suggestions. I used the word "safe" following the example of parser libs I've seen, where it means features are disabled in the interest of security. Like ruamel.yaml uses "safe" mode to mean a YAML parser that does not parse anything but lists, dicts, and scalars (e.g. no objects). From what see, I think this clearly does make it safer to use. |
View reviewed changes
EliahKagan left a comment · edited Loading
Copy link Copy Markdown
Member
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
I'll try to review this in full sometime soon! This mini-review is not that. Instead, this just points out a couple of things related directly to my previous comments. One is fairly minor and pertains to the clarity and technical accuracy of exception messages. The other is more significant: the current attempt to refuse to run the command in a shell does not always work.
eighthave force-pushed the safe-mode branch 2 times, most recently froma60991f to
91fdc6c
Compare
June 9, 2025 14:42 eighthave requested a review from EliahKagan June 9, 2025 14:46 EliahKagan mentioned this pull request Jun 13, 2025 If
diff.external is set, diffing via API fails silently as external tool isn't understood
#1828
Closed
eighthave commented Jun 16, 2025
Copy link Copy Markdown
Author
|
I think this is ready to go. Let me know if there is anything I can provide to help with the review and merge. |
nightly: switch dep from vcs_git to GitPython
b2057a1
This code already depends on GitPython, and hopefully the common.vcs* stuff can eventually go away entirely. GitPython should provide those bits already, and they are maintained by someone else. gitpython-developers/GitPython#2029eighthave force-pushed the safe-mode branch from
91fdc6c to
030cb23
Compare
October 7, 2025 14:09
eighthave commented Oct 7, 2025
Copy link Copy Markdown
Author
|
@EliahKagan anything I can help with? Any other blockers here? I rebased this on the latest main . |
eighthave commented Oct 7, 2025
Copy link Copy Markdown
Author
|
The test failure seems to be unrelated, something with it can't connect to localhost |
View reviewed changes
Byron commented May 6, 2026 · edited Loading
Copy link Copy Markdown
Member
|
@eighthave Sorry for the long wait. The test might be flaky, and fixing the conflicts will hopefully resolve this. |
Byron commented May 6, 2026
Copy link Copy Markdown
Member
|
Also converting to draft as there seem to be more subtle issues with this PR that Eliah can elaborate when there is time. |
safe mode to disable executing any external programs except git
56e3440
eighthave
force-pushed
the
safe-mode
branch
from
030cb23 to
56e3440
Compare
May 6, 2026 07:12
eighthave commented May 6, 2026 via email
Copy link Copy Markdown
Author
| I rebased this on main. Happy to fix issues if I know what they are. FYI, we've been using a version of this code in production for a while now and have seen no problems with it. |
Byron commented Jul 20, 2026
Copy link Copy Markdown
Member
|
While it's desirable what's attempted here, the PR is stale and it's better to start over. |
eighthave commented Jul 20, 2026 via email
Copy link Copy Markdown
Author
| At this point, it seems the GitPython maintainers do not want this, I just wish things were stated clearly. I've responded to all requests and rebased as needed. Without a clear commitment from the GitPython maintainers, I won't pursue this further in GitPython. Instead, we will continue to maintain it in fdroidserver. |
Byron commented Jul 20, 2026
Copy link Copy Markdown
Member
|
My apologies, the GitPython maintainers are a bit overwhelmed and wanted to clear the slate. Can it be useful even without being perfect? Red CI can probably be fixed quickly these days, something @eighthave wants to do, or should I push into it? Also, what's missing from getting this out of draft? A task list/checkbox list would help with this if it's nothing quick. |
EliahKagan commented Jul 20, 2026
Copy link Copy Markdown
Member
|
I'm very sorry about my poor communication here. I have substantial notes about this, but I don't know when I'll be able to get back to it and I don't want to keep saying "soon." There are subtleties that arise when bringing this into GitPython in this form. I am worried that--unintuitive as it may seem--this may actually introduce new or exacerbate existing vulnerabilities in GitPython or other software if added to GitPython like this, or in any patch based on the proposal in #2020 . One of the reasons I failed to respond is that I didn't want to make vague and potentially ominous-sounding statements like what I am doing in this comment. But I want to make clear that I do not recommend moving forward on this in GitPython at this time. This relates to multiple intersecting lines of security research, some of which have themselves been taking longer than expected for unrelated reasons. Out of an abundance of caution, I do not think that it is acceptable for me to say anything more about this right now. If I can get the time, and if I identify and confirm vulnerabilities in GitPython or other projects, then I will report them. |
Byron commented Jul 21, 2026
Copy link Copy Markdown
Member
|
I am also very sorry for all the hassle and... the flip-flopping. It's all based on my lossy memory. To recount, @EliahKagan already brought up concerns about this PR and started working on the security implications with the goal of making it better. It was at this point where we should have asked if we want to invest the time, or just close it. Over time, all that was left with me is the sentiment that this PR should be closed, without much information backing it. The OP's response then shook my resolve and my uncertainty led me to back-paddle, forcing Eliah to come to action. But all of this doesn't change the sentiment, the issues found with this PR, and the time it would take to make it mergable. Thus, it's best to close it, focussing our very limited resources elsewhere. Sorry again for the hassle, and thanks for your understanding, to both of you, @EliahKagan and @eighthave . PS: My recent cleanup is also to avoid long-standing PRs in future, and to be way faster in either fixing issues and merging PRs, or to close them, to prevent a buildup of what later will be noise and that overwhelming feeling that one is lacking behind. |
eighthave commented Jul 21, 2026 via email
Copy link Copy Markdown
Author
| @EliahKagan could you at least send me your notes privately so we can decide how to proceed? Our approach here has been in place in our code base for years and has been audited. If you know of existing issues, we need to fix them. It would be helpful even if it was just raw notes without explanation. ***@***.*** is the email in my commits and matches my longstanding public PGP key: EE66 20C7 136B 0D2C 456C 0A4D E9E2 8DEA 00AA 5556 |