Skip to content

Commit e69ac42

Browse files
peffdscho
authored andcommitted
docs: document security issues around untrusted .git dirs
For a long time our general philosophy has been that it's unsafe to run arbitrary Git commands if you don't trust the hooks or config in .git, but that running upload-pack should be OK. E.g., see 1456b04 (Remove post-upload-hook, 2009-12-10), or the design of uploadpack.packObjectsHook. But we never really documented this (and even the discussions that led to 1456b04 were not on the public list!). Let's try to make our approach more clear, but also be realistic that even upload-pack carries some risk. Helped-by: Filip Hejsek <[email protected]> Helped-by: Junio C Hamano <[email protected]> Signed-off-by: Jeff King <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 7b70e9e commit e69ac42

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

Documentation/git-upload-pack.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,21 @@ This is implemented by having `upload-pack` internally set the
7171
you trust it), you can explicitly set `GIT_NO_LAZY_FETCH` to
7272
`0`.
7373

74+
SECURITY
75+
--------
76+
77+
Most Git commands should not be run in an untrusted `.git` directory
78+
(see the section `SECURITY` in linkgit:git[1]). `upload-pack` tries to
79+
avoid any dangerous configuration options or hooks from the repository
80+
it's serving, making it safe to clone an untrusted directory and run
81+
commands on the resulting clone.
82+
83+
For an extra level of safety, you may be able to run `upload-pack` as an
84+
alternate user. The details will be platform dependent, but on many
85+
systems you can run:
86+
87+
git clone --no-local --upload-pack='sudo -u nobody git-upload-pack' ...
88+
7489
SEE ALSO
7590
--------
7691
linkgit:gitnamespaces[7]

Documentation/git.txt

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,6 +1032,37 @@ The index is also capable of storing multiple entries (called "stages")
10321032
for a given pathname. These stages are used to hold the various
10331033
unmerged version of a file when a merge is in progress.
10341034

1035+
SECURITY
1036+
--------
1037+
1038+
Some configuration options and hook files may cause Git to run arbitrary
1039+
shell commands. Because configuration and hooks are not copied using
1040+
`git clone`, it is generally safe to clone remote repositories with
1041+
untrusted content, inspect them with `git log`, and so on.
1042+
1043+
However, it is not safe to run Git commands in a `.git` directory (or
1044+
the working tree that surrounds it) when that `.git` directory itself
1045+
comes from an untrusted source. The commands in its config and hooks
1046+
are executed in the usual way.
1047+
1048+
By default, Git will refuse to run when the repository is owned by
1049+
someone other than the user running the command. See the entry for
1050+
`safe.directory` in linkgit:git-config[1]. While this can help protect
1051+
you in a multi-user environment, note that you can also acquire
1052+
untrusted repositories that are owned by you (for example, if you
1053+
extract a zip file or tarball from an untrusted source). In such cases,
1054+
you'd need to "sanitize" the untrusted repository first.
1055+
1056+
If you have an untrusted `.git` directory, you should first clone it
1057+
with `git clone --no-local` to obtain a clean copy. Git does restrict
1058+
the set of options and hooks that will be run by `upload-pack`, which
1059+
handles the server side of a clone or fetch, but beware that the
1060+
surface area for attack against `upload-pack` is large, so this does
1061+
carry some risk. The safest thing is to serve the repository as an
1062+
unprivileged user (either via linkgit:git-daemon[1], ssh, or using
1063+
other tools to change user ids). See the discussion in the `SECURITY`
1064+
section of linkgit:git-upload-pack[1].
1065+
10351066
FURTHER DOCUMENTATION
10361067
---------------------
10371068

0 commit comments

Comments
 (0)