diff --git a/setup_tools.py b/setup_tools.py index baf8fe6..c1fbf49 100644 --- a/setup_tools.py +++ b/setup_tools.py @@ -61,6 +61,12 @@ def download_library(command): content = BytesIO(r.read()) content.seek(0) with tarfile.open(fileobj=content) as tf: + # Prevent Tar Slip (Path Traversal) + base_path = os.path.realpath(os.getcwd()) + for member in tf.getmembers(): + member_path = os.path.realpath(os.path.join(base_path, member.name)) + if not member_path.startswith(base_path + os.sep) and member_path != base_path: + raise Exception('Attempted Path Traversal in Tar File') dirname = tf.getnames()[0].partition('/')[0] tf.extractall() shutil.move(dirname, libdir) @@ -149,4 +155,4 @@ def detect_dll(): for fn in os.listdir(os.path.join(here, 'libsecp256k1')): if fn.endswith('.dll'): return True - return False \ No newline at end of file + return False