Skip to content

Commit 6cbba39

Browse files
committed
test(test_hg): Alias command injection recreation in URLs
1 parent 96d2ada commit 6cbba39

File tree

1 file changed

+24
-1
lines changed

1 file changed

+24
-1
lines changed

tests/test_hg.py

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import pytest
77

8-
from libvcs.shortcuts import create_repo_from_pip_url
8+
from libvcs.shortcuts import create_repo, create_repo_from_pip_url
99
from libvcs.util import run, which
1010

1111
if not which("hg"):
@@ -72,3 +72,26 @@ def test_repo_mercurial(tmp_path: pathlib.Path, repos_path, hg_remote):
7272
)
7373

7474
assert mercurial_repo.get_revision() == test_repo_revision
75+
76+
77+
def test_vulnerability_2022_03_12_command_injection(
78+
monkeypatch: pytest.MonkeyPatch,
79+
user_path: pathlib.Path,
80+
tmp_path: pathlib.Path,
81+
hg_remote,
82+
):
83+
"""Prevent hg aliases from executed arbitrary commands via URLs.
84+
85+
As of 0.11 this code path is/was only executed via .obtain(), so this only would
86+
effect explicit invocation of .object() or update_repo() of uncloned destination.
87+
"""
88+
random_dir = tmp_path / "random"
89+
random_dir.mkdir()
90+
monkeypatch.chdir(str(random_dir))
91+
mercurial_repo = create_repo(
92+
url="--config=alias.clone=!touch ./HELLO", vcs="hg", repo_dir="./"
93+
)
94+
with pytest.raises(Exception):
95+
mercurial_repo.update_repo()
96+
97+
assert pathlib.Path(random_dir / "HELLO").exists()

0 commit comments

Comments
 (0)