Skip to content

Commit

Permalink
Add test
Browse files Browse the repository at this point in the history
  • Loading branch information
stsewd committed Dec 22, 2022
1 parent 3c51865 commit 7918fcc
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions test/test_repo.py
Original file line number Diff line number Diff line change
Expand Up @@ -1180,3 +1180,29 @@ def test_do_not_strip_newline_in_stdout(self, rw_dir):
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()

0 comments on commit 7918fcc

Please sign in to comment.