Added the Trellix's fix.

This commit is contained in:
Batuhan Berk Başoğlu 2024-01-21 14:19:24 -05:00
parent d8624aa99b
commit 357f9c7ebc

View file

@ -4726,7 +4726,26 @@ if __name__ == '__main__': # pragma: no cover
def get_php_references(): def get_php_references():
download = urlretrieve(PHP_MANUAL_URL) download = urlretrieve(PHP_MANUAL_URL)
with tarfile.open(download[0]) as tar: with tarfile.open(download[0]) as tar:
tar.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(tar)
yield from glob.glob("%s%s" % (PHP_MANUAL_DIR, PHP_REFERENCE_GLOB)) yield from glob.glob("%s%s" % (PHP_MANUAL_DIR, PHP_REFERENCE_GLOB))
os.remove(download[0]) os.remove(download[0])