Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

CVE-2007-4559 Patch #601

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion giza/giza/operations/build_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,26 @@ def is_git_dir(path):
def extract_package_at_root(path, conf):
with cd(conf.paths.projectroot):
with tarfile.open(path, "r:gz") as t:
t.extractall()
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(t)


def get_existing_builders(conf):
Expand Down
21 changes: 20 additions & 1 deletion giza/giza/operations/packaging.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,26 @@ def extract_package(conf):
raise FileNotFoundError(m)

with tarfile.open(path, "r:gz") as t:
t.extractall(os.path.join(conf.paths.projectroot, conf.paths.public))
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(t, os.path.join(conf.paths.projectroot,conf.paths.public))


def fetch_package(path, conf):
Expand Down