Skip to content

Commit 19799d0

Browse files
codexByron
authored andcommitted
fix: reject unsafe clone templates
Treat git clone --template as unsafe because caller-controlled templates can install hooks that execute during clone. Add regression coverage for both direct option and keyword forms. References GHSA-6p8h-3wgx-97gf. Validated against Git baseline a23bace9.
1 parent f080282 commit 19799d0

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

git/repo/base.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,8 @@ class Repo:
149149
# Can override configuration variables that execute arbitrary commands:
150150
"--config",
151151
"-c",
152+
# Can install hooks that execute during clone:
153+
"--template",
152154
]
153155
"""Options to :manpage:`git-clone(1)` that allow arbitrary commands to be executed.
154156
@@ -159,6 +161,9 @@ class Repo:
159161
The ``--config``/``-c`` option allows users to override configuration variables like
160162
``protocol.allow`` and ``core.gitProxy`` to execute arbitrary commands:
161163
https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---configltkeygtltvaluegt
164+
165+
The ``--template`` option can install hooks that execute during clone:
166+
https://git-scm.com/docs/git-clone#Documentation/git-clone.txt---templatetemplate-directory
162167
"""
163168

164169
unsafe_git_archive_options = [

test/test_clone.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ def test_clone_unsafe_options(self, rw_repo):
128128
"-c protocol.ext.allow=always",
129129
"-cprotocol.ext.allow=always",
130130
"-vcprotocol.ext.allow=always",
131+
f"--template={tmp_dir}",
131132
]
132133
for unsafe_option in unsafe_options:
133134
with self.assertRaises(UnsafeOptionError):
@@ -142,6 +143,7 @@ def test_clone_unsafe_options(self, rw_repo):
142143
{"config": "protocol.ext.allow=always"},
143144
{"conf": "protocol.ext.allow=always"},
144145
{"c": "protocol.ext.allow=always"},
146+
{"template": tmp_dir},
145147
]
146148
for unsafe_option in unsafe_options:
147149
with self.assertRaises(UnsafeOptionError):

0 commit comments

Comments
 (0)