Skip to content

Commit

Permalink
what about this?
Browse files Browse the repository at this point in the history
  • Loading branch information
TingDaoK committed Jan 11, 2024
1 parent 1be485c commit 151a39c
Showing 1 changed file with 2 additions and 21 deletions.
23 changes: 2 additions & 21 deletions builder/core/fetch.py
Original file line number Diff line number Diff line change
Expand Up @@ -235,27 +235,8 @@ def fetch_and_extract(url, archive_path, extract_path):

print('Extracting {} to {}'.format(archive_path, extract_path))
if tarfile.is_tarfile(archive_path):
with open(archive_path, mode='rb') as file:
with tarfile.open(fileobj=file) as tar:
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, extract_path)
with tarfile.open(archive_path) as tar:
tar.extractall(extract_path)

elif zipfile.is_zipfile(archive_path):
with zipfile.ZipFile(archive_path) as zip:
Expand Down

0 comments on commit 151a39c

Please sign in to comment.