Skip to content

Commit

Permalink
Block insecure non-multi options in clone/clone_from
Browse files Browse the repository at this point in the history
Follow-up to #1521
  • Loading branch information
Beuc committed Jul 10, 2023
1 parent c09a71e commit 5c59e0d
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 2 additions & 0 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -1203,6 +1203,8 @@ def _clone(

if not allow_unsafe_protocols:
Git.check_unsafe_protocols(str(url))
if not allow_unsafe_options:
Git.check_unsafe_options(options=list(kwargs.keys()), unsafe_options=cls.unsafe_git_clone_options)
if not allow_unsafe_options and multi_options:
Git.check_unsafe_options(options=multi_options, unsafe_options=cls.unsafe_git_clone_options)

Expand Down
24 changes: 23 additions & 1 deletion test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,17 @@ def test_clone_unsafe_options(self, rw_repo):
rw_repo.clone(tmp_dir, multi_options=[unsafe_option])
assert not tmp_file.exists()

unsafe_options = [
{"upload-pack": f"touch {tmp_file}"},
{"u": f"touch {tmp_file}"},
{"config": "protocol.ext.allow=always"},
{"c": "protocol.ext.allow=always"},
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
rw_repo.clone(tmp_dir, **unsafe_option)
assert not tmp_file.exists()

@with_rw_repo("HEAD")
def test_clone_unsafe_options_allowed(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
Expand Down Expand Up @@ -341,6 +352,17 @@ def test_clone_from_unsafe_options(self, rw_repo):
Repo.clone_from(rw_repo.working_dir, tmp_dir, multi_options=[unsafe_option])
assert not tmp_file.exists()

unsafe_options = [
{"upload-pack": f"touch {tmp_file}"},
{"u": f"touch {tmp_file}"},
{"config": "protocol.ext.allow=always"},
{"c": "protocol.ext.allow=always"},
]
for unsafe_option in unsafe_options:
with self.assertRaises(UnsafeOptionError):
Repo.clone_from(rw_repo.working_dir, tmp_dir, **unsafe_option)
assert not tmp_file.exists()

@with_rw_repo("HEAD")
def test_clone_from_unsafe_options_allowed(self, rw_repo):
with tempfile.TemporaryDirectory() as tdir:
Expand Down Expand Up @@ -1410,4 +1432,4 @@ def test_ignored_raises_error_w_symlink(self):
os.symlink(tmp_dir / "target", tmp_dir / "symlink")

with pytest.raises(GitCommandError):
temp_repo.ignored(tmp_dir / "symlink/file.txt")
temp_repo.ignored(tmp_dir / "symlink/file.txt")

0 comments on commit 5c59e0d

Please sign in to comment.