Skip to content

Commit

Permalink
Merge pull request #50 from TrellixVulnTeam/master
Browse files Browse the repository at this point in the history
  • Loading branch information
giswqs authored Oct 26, 2022
2 parents 6e87531 + 0ceb86d commit 81cd866
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
21 changes: 20 additions & 1 deletion whitebox/download_wbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,26 @@ def download_wbt(verbose=True):
zip_ref.extractall(pkg_dir)
else: # Decompress Linux tar file
with tarfile.open(zip_name, "r") as tar_ref:
tar_ref.extractall(pkg_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_ref, pkg_dir)
if verbose:
print("WhiteboxTools package directory: {}".format(pkg_dir))

Expand Down
21 changes: 20 additions & 1 deletion whitebox/whitebox_tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,26 @@ def download_wbt(verbose=True):
zip_ref.extractall(pkg_dir)
else: # Decompress Linux tar file
with tarfile.open(zip_name, "r") as tar_ref:
tar_ref.extractall(pkg_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_ref, pkg_dir)
if verbose:
print("WhiteboxTools package directory: {}".format(pkg_dir))

Expand Down

0 comments on commit 81cd866

Please sign in to comment.