Skip to content
Permalink
Browse files Browse the repository at this point in the history
fix: unsafe tar extract for gppkg (#15076)
  • Loading branch information
yihong0618 committed Feb 28, 2023
1 parent 450c90a commit 1ec4aff
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion gpMgmt/bin/gppylib/operations/package.py
Expand Up @@ -814,7 +814,25 @@ def execute(self):

# untar the package into tmp folder
with closing(tarfile.open(self.gppkg.abspath)) as tarinfo:
tarinfo.extractall(TEMP_EXTRACTION_PATH)
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):

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)

safe_extract(tarinfo, path=TEMP_EXTRACTION_PATH)

# move all the deps into same folder as the main rpm
path = os.path.join(TEMP_EXTRACTION_PATH, DEPS_DIR)
Expand Down

0 comments on commit 1ec4aff

Please sign in to comment.