summaryrefslogtreecommitdiff
path: root/test/test_repo.py
diff options
context:
space:
mode:
authorSebastian Thiel <sebastian.thiel@icloud.com>2022-12-22 17:08:42 +0100
committerSebastian Thiel <sebastian.thiel@icloud.com>2022-12-22 17:08:42 +0100
commit787359d80d80225095567340aa5e7ec01847fa9a (patch)
tree41947c5be7875e746b6e1452add2b92283e926b4 /test/test_repo.py
parent17ff2630af26b37f82ac1158ee3495c4390da699 (diff)
parent2aae532a3993a100d5074cde70abe548cfc45861 (diff)
downloadgitpython-787359d80d80225095567340aa5e7ec01847fa9a.tar.gz
Merge branch 'fix-cmd-injection'
Diffstat (limited to 'test/test_repo.py')
-rw-r--r--test/test_repo.py26
1 files changed, 26 insertions, 0 deletions
diff --git a/test/test_repo.py b/test/test_repo.py
index 703dbb43..6382db7e 100644
--- a/test/test_repo.py
+++ b/test/test_repo.py
@@ -1180,3 +1180,29 @@ class TestRepo(TestBase):
r.git.add(Git.polish_url(fp))
r.git.commit(message="init")
self.assertEqual(r.git.show("HEAD:hello.txt", strip_newline_in_stdout=False), "hello\n")
+
+ @with_rw_repo("HEAD")
+ def test_clone_command_injection(self, rw_repo):
+ tmp_dir = pathlib.Path(tempfile.mkdtemp())
+ unexpected_file = tmp_dir / "pwn"
+ assert not unexpected_file.exists()
+
+ payload = f"--upload-pack=touch {unexpected_file}"
+ rw_repo.clone(payload)
+
+ assert not unexpected_file.exists()
+ # A repo was cloned with the payload as name
+ assert pathlib.Path(payload).exists()
+
+ @with_rw_repo("HEAD")
+ def test_clone_from_command_injection(self, rw_repo):
+ tmp_dir = pathlib.Path(tempfile.mkdtemp())
+ temp_repo = Repo.init(tmp_dir / "repo")
+ unexpected_file = tmp_dir / "pwn"
+
+ assert not unexpected_file.exists()
+ payload = f"--upload-pack=touch {unexpected_file}"
+ with self.assertRaises(GitCommandError):
+ rw_repo.clone_from(payload, temp_repo.common_dir)
+
+ assert not unexpected_file.exists()