Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Draft: safe mode to disable executing any external programs except git#2029

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Draft
eighthave wants to merge1 commit intogitpython-developers:main
base:main
Choose a base branch
Loading
fromeighthave:safe-mode

Conversation

eighthave
Copy link

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

Copy link
Member

@ByronByron left a comment

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.

'-c', 'http.emptyAuth=true',
'-c', 'protocol.allow=never',
'-c', 'protocol.https.allow=always',
'-c', 'url.https://.insteadOf=ssh://',
Copy link
Member

Choose a reason for hiding this comment

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

There is also configuration related to which filesystem monitor to launch, triggered bygit status.

Copy link
Author

Choose a reason for hiding this comment

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

Nice catch, I think that should be covered bycore.fsmonitor=false. I also looked atreceive.procReceiveRefs,uploadpack.packObjectsHook, andremote.<name>.vcs but couldn't see how to disable them here.

Copy link
Member

Choose a reason for hiding this comment

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

I see, sections that are dependent on actual values are problematic.

env['GIT_TERMINAL_PROMPT'] = 'false'
env['GIT_ASKPASS'] = '/bin/true'
env['SSH_ASKPASS'] = '/bin/true'
env['GIT_SSH'] = '/bin/true'
Copy link
Member

Choose a reason for hiding this comment

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

I think there is alsoGIT_SSH_PROGRAM, and there are probably more.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, thanks,GIT_SSH_COMMAND. I just went throughhttps://git-scm.com/book/en/v2/Git-Internals-Environment-Variables and picked out all the relevant ones.

Byron reacted with thumbs up emoji
@@ -204,6 +208,11 @@ def __init__(
Please note that this was the default behaviour in older versions of
GitPython, which is considered a bug though.

:param safe:
Copy link
Member

Choose a reason for hiding this comment

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

I think without exhaustive tests and actually challenging the code we wouldn't want to make the flag seem like a perfect defence.
Somehow I feel thatas safe as possible should rather be a disclaimer about this being a best-effort basis and that the defence is probably not complete, while stating what it focusses on.

eighthave reacted with thumbs up emoji
Copy link
Author

@eighthaveeighthaveMay 27, 2025
edited
Loading

Choose a reason for hiding this comment

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

Agreed. This is what I have so far:

Lock down the configuration to make it as safe as possible when working with publicly accessible, untrusted repositories. This disables all known options that can run an external program and limits networking to the HTTP protocol via https:// URLs. This might not cover Git config options that were added since this was implemented, or options that might have unknown exploit vectors. It is a best effort defense rather than an exhaustive protection measure.

Copy link
Member

Choose a reason for hiding this comment

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

That sounds good! Maybe it makes sense to explicitly mention configuration keys with subsections, as these are particularly hard to pickup.

On the bright side, thinking about it, this would only be a problem if someone else controls the environment or the configuration. Maybe the latter is common for repositories on shared drives?

@eighthave
Copy link
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 howgit is executed, it seems like it would have to connect to the network? Or is there a test that already replaces the protocol helper, e.g.git-remote-https, to avoid network access?

@Byron
Copy link
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 specificand spotty that they barely have any value.

@gcmarx
Copy link
Contributor

if we can only rungit, that could mean we pick#2027 over#2026. I don't think it makes sense to have an allowlist of other executables GitPython could run.@EliahKagan, your thoughts?

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@ByronByronByron left review comments

Assignees
No one assigned
Labels
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@eighthave@Byron@gcmarx

[8]ページ先頭

©2009-2025 Movatter.jp