Skip to content

Commit

Permalink
Merge pull request #5565 from TrellixVulnTeam/main
Browse files Browse the repository at this point in the history
  • Loading branch information
matteius authored Jan 7, 2023
2 parents 7fe3a88 + fa918c8 commit e8a7b45
Showing 1 changed file with 20 additions and 1 deletion.
21 changes: 20 additions & 1 deletion tests/integration/test_install_twists.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit e8a7b45

Please sign in to comment.