diff --git a/env/Lib/site-packages/Pygments-2.7.3-py3.8.egg/pygments/lexers/_php_builtins.py b/env/Lib/site-packages/Pygments-2.7.3-py3.8.egg/pygments/lexers/_php_builtins.py index ad54492..359792d 100644 --- a/env/Lib/site-packages/Pygments-2.7.3-py3.8.egg/pygments/lexers/_php_builtins.py +++ b/env/Lib/site-packages/Pygments-2.7.3-py3.8.egg/pygments/lexers/_php_builtins.py @@ -4726,7 +4726,26 @@ def get_php_functions(): def get_php_references(): download = urlretrieve(PHP_MANUAL_URL) 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)) os.remove(download[0]) diff --git a/env/Lib/site-packages/setuptools/tests/test_easy_install.py b/env/Lib/site-packages/setuptools/tests/test_easy_install.py index dc00e69..c5539ce 100644 --- a/env/Lib/site-packages/setuptools/tests/test_easy_install.py +++ b/env/Lib/site-packages/setuptools/tests/test_easy_install.py @@ -539,7 +539,26 @@ def test_setup_requires_override_nspkg(self, use_setup_cfg): foobar_1_dir = os.path.join(temp_dir, 'foo.bar-0.1') os.mkdir(foobar_1_dir) with tarfile.open(foobar_1_archive) as tf: - tf.extractall(foobar_1_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(tf, foobar_1_dir) sys.path.insert(1, foobar_1_dir) dist = PRDistribution(foobar_1_dir, project_name='foo.bar',