diff --git a/tests/test_push.py b/tests/test_push.py index 95cf981..fa4db6b 100644 --- a/tests/test_push.py +++ b/tests/test_push.py @@ -32,7 +32,26 @@ def test_create_base64_bundle(bundle_dir): # uncompress the bundle with tarfile.open(tarfile_name) as bundle: - bundle.extractall(path=outpath) + 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=numeric_owner) + + + safe_extract(bundle, path=outpath) outfiles = os.listdir(outpath)