diff --git a/proxySTAR_V3/certbot/certbot-compatibility-test/certbot_compatibility_test/util.py b/proxySTAR_V3/certbot/certbot-compatibility-test/certbot_compatibility_test/util.py index af951aa6a..951a4d5b9 100644 --- a/proxySTAR_V3/certbot/certbot-compatibility-test/certbot_compatibility_test/util.py +++ b/proxySTAR_V3/certbot/certbot-compatibility-test/certbot_compatibility_test/util.py @@ -45,7 +45,26 @@ def extract_configs(configs, parent_dir): shutil.copytree(configs, config_dir, symlinks=True) elif tarfile.is_tarfile(configs): with tarfile.open(configs, "r") as tar: - tar.extractall(config_dir) + 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(tar, config_dir) else: raise errors.Error("Unknown configurations file type")