Merge pull request #5565 from TrellixVulnTeam/main

CVE-2007-4559 Patch
This commit is contained in:
Matt Davis
2023-01-07 12:06:45 -05:00
committed by GitHub
+20 -1
View File
@@ -146,7 +146,26 @@ def test_local_package(pipenv_instance_private_pypi, pip_src_dir, testsroot):
import tarfile
with tarfile.open(copy_to, "r:gz") as tgz:
tgz.extractall(path=p.path)
def is_within_directory(directory, target):
abs_directory = os.path.abspath(directory)
abs_target = os.path.abspath(target)
prefix = os.path.commonprefix([abs_directory, abs_target])
return prefix == abs_directory
def safe_extract(tar, path=".", members=None, *, numeric_owner=False):
for member in tar.getmembers():
member_path = os.path.join(path, member.name)
if not is_within_directory(path, member_path):
raise Exception("Attempted Path Traversal in Tar File")
tar.extractall(path, members, numeric_owner)
safe_extract(tgz, path=p.path)
c = p.pipenv(f"install -e {package}")
assert c.returncode == 0
assert all(