From: "brian m. carlson" <sandals@crustytoothpaste.net>
To: Michael Lohmann <git@lohmann.sh>
Cc: git@vger.kernel.org
Subject: Re: [RCF] Secure git against involuntary arb. code execution without feature loss
Date: Wed, 8 Oct 2025 21:35:56 +0000 [thread overview]
Message-ID: <aObZPJ3JK-YVI-g7@fruit.crustytoothpaste.net> (raw)
In-Reply-To: <72F10412-8B0F-4F66-8674-FE194D016DF9@lohmann.sh>
[-- Attachment #1: Type: text/plain, Size: 2951 bytes --]
On 2025-10-08 at 21:02:03, Michael Lohmann wrote:
> Hello everyone,
Hi,
> Hooks, as well as certain config (e.g. `core.pager`) can do automatic
> code execution for you. In general, this is a great feature and should
> be kept without the user noticing any changes.
>
> BUT if you download a random folder which to you unknowingly is a repo
> and either you or e.g. your command line prompt automatically executes a
> simple `git status`, it feels bad if this results in arbitrary code
> execution (ACE), e.g.:
>
> https://www.sonarsource.com/blog/securing-developer-tools-git-integrations/
>
> and
>
> https://github.com/justinsteven/advisories/blob/main/2022_git_buried_bare_repos_and_fsmonitor_various_abuses.md
>
> Apart from one core maintainer, all git user I talked to were surprised
> and shocked by how simple an exploit like this was.
>
> * Proposed solution (keeping all existing features):
> - On first use, git generates a secret "token" (e.g. a random string in
> ~/.gitsecret)
> - On calling `git init` or `git clone`, the secret is copied into the
> new .git directory and serves as proof that this clone was created by
> this user
> - Before executing any user-defined code, check for the local token:
> - If present, proceed as usual.
> - Otherwise abort.
This has all of the downsides of our existing per-Unix user approach and
is also more complicated. You'll notice that when we changed to the
per-Unix user approach, that broke containers, shared repositories, and
even the detection of whether a directory _is_ a repository, and this
would do the same thing. It would be even worse for containers because
if you copied a token into the container from the container user, you'd
end up polluting that directory with lots of useless tokens that never
get cleaned up.
It is also easy to bypass, since if we share multiple repositories as
collaborators, as soon as I can read the secret from one of them, I can
then write it into any other location. It would even be sufficient if
we were users on the same system (such as is common in universities or
some businesses) and I could read the repository. Many websites even
accidentally expose their `.git` directories, which would not only
expose their repository but also allow attacks against all of the
administrator's repositories.
What would be better to see instead is a config option that restricts
which external commands (via config options or hooks) can be executed
from local config. Then it would be possible to say, "Never honour
local config to execute code." With `includeIf`, this can allowlist
certain repositories to do that and leave the rest disabled.
Maybe something like this:
[safe]
config = core.editor
config = core.fsmonitor
hook = pre-receive
If you wanted to implement _that_, I'd be all over it.
--
brian m. carlson (they/them)
Toronto, Ontario, CA
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 262 bytes --]
next prev parent reply other threads:[~2025-10-08 21:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-10-08 21:02 [RCF] Secure git against involuntary arb. code execution without feature loss Michael Lohmann
2025-10-08 21:30 ` Taylor Blau
2025-10-08 21:34 ` rsbecker
2025-10-08 21:49 ` Taylor Blau
2025-10-08 22:09 ` Michael Lohmann
2025-10-08 21:35 ` brian m. carlson [this message]
2025-10-08 22:25 ` Michael Lohmann
2025-10-09 5:24 ` Jeff King
2025-10-09 22:43 ` Michael Lohmann
2025-10-13 9:57 ` Submitted patches for "assume unsafe" Michael Lohmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aObZPJ3JK-YVI-g7@fruit.crustytoothpaste.net \
--to=sandals@crustytoothpaste.net \
--cc=git@lohmann.sh \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).