setup.c: create `safe.bareRepository`
commit8d1a7448206e11cdea657c35b04cc49db39be933
authorGlen Choo <chooglen@google.com>
Thu, 14 Jul 2022 21:28:01 +0000 (14 21:28 +0000)
committerJunio C Hamano <gitster@pobox.com>
Thu, 14 Jul 2022 22:08:29 +0000 (14 15:08 -0700)
treeadb883132f48ef4f809f7ed2fd4b633850998ee9
parent6061601d9f1f1c95da5f9304c319218f7cc3ec75
setup.c: create `safe.bareRepository`

There is a known social engineering attack that takes advantage of the
fact that a working tree can include an entire bare repository,
including a config file. A user could run a Git command inside the bare
repository thinking that the config file of the 'outer' repository would
be used, but in reality, the bare repository's config file (which is
attacker-controlled) is used, which may result in arbitrary code
execution. See [1] for a fuller description and deeper discussion.

A simple mitigation is to forbid bare repositories unless specified via
`--git-dir` or `GIT_DIR`. In environments that don't use bare
repositories, this would be minimally disruptive.

Create a config variable, `safe.bareRepository`, that tells Git whether
or not to die() when working with a bare repository. This config is an
enum of:

- "all": allow all bare repositories (this is the default)
- "explicit": only allow bare repositories specified via --git-dir
  or GIT_DIR.

If we want to protect users from such attacks by default, neither value
will suffice - "all" provides no protection, but "explicit" is
impractical for bare repository users. A more usable default would be to
allow only non-embedded bare repositories ([2] contains one such
proposal), but detecting if a repository is embedded is potentially
non-trivial, so this work is not implemented in this series.

[1]: https://lore.kernel.org/git/kl6lsfqpygsj.fsf@chooglen-macbookpro.roam.corp.google.com
[2]: https://lore.kernel.org/git/5b969c5e-e802-c447-ad25-6acc0b784582@github.com

Signed-off-by: Glen Choo <chooglen@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/safe.txt
setup.c
t/t0035-safe-bare-repository.sh [new file with mode: 0755]