Skip to content

Commit

Permalink
Merge pull request #54 from TrellixVulnTeam/master
Browse files Browse the repository at this point in the history
  • Loading branch information
bubylou authored Apr 15, 2023
2 parents 65de6be + 8f90abc commit db8c86f
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions scsm/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,26 @@ def remove(self):
def restore(self, backup):
'''Restore specified backup file'''
with tarfile.open(Path(self.backup_dir, backup)) as tar:
tar.extractall(self.app_dir.parent)
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, self.app_dir.parent)

if self.config_is_default:
self.copy_config()
Expand Down Expand Up @@ -458,7 +477,26 @@ def install(self):

if pf.system() != 'Windows':
with tarfile.open(Path(self.directory, f)) as tar:
tar.extractall(self.directory)
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, self.directory)
else:
with ZipFile(Path(self.directory, f)) as zipf:
zipf.extractall(self.directory)
Expand Down

0 comments on commit db8c86f

Please sign in to comment.