From 533095cb7784b2a9695b5cfa9597e409144b09c1 Mon Sep 17 00:00:00 2001 From: TrellixVulnTeam Date: Mon, 3 Oct 2022 02:50:14 +0000 Subject: [PATCH 1/2] Adding tarfile member sanitization to extractall() --- .../npm/node_modules/node-gyp/update-gyp.py | 21 ++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/server/node_modules/npm/node_modules/node-gyp/update-gyp.py b/server/node_modules/npm/node_modules/node-gyp/update-gyp.py index bb84f07..b77b092 100755 --- a/server/node_modules/npm/node_modules/node-gyp/update-gyp.py +++ b/server/node_modules/npm/node_modules/node-gyp/update-gyp.py @@ -33,7 +33,26 @@ print("Unzipping...") with tarfile.open(tar_file, "r:gz") as tar_ref: - tar_ref.extractall(unzip_target) + 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) + + + safe_extract(tar_ref, unzip_target) print("Moving to current checkout (" + CHECKOUT_PATH + ")...") if os.path.exists(CHECKOUT_GYP_PATH): From c57d47671cd44572d2174a70ed401318bac9d7af Mon Sep 17 00:00:00 2001 From: TrellixVulnTeam Date: Tue, 4 Oct 2022 21:33:03 +0000 Subject: [PATCH 2/2] Adding numeric_owner as keyword arguement --- server/node_modules/npm/node_modules/node-gyp/update-gyp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/node_modules/npm/node_modules/node-gyp/update-gyp.py b/server/node_modules/npm/node_modules/node-gyp/update-gyp.py index b77b092..73277d8 100755 --- a/server/node_modules/npm/node_modules/node-gyp/update-gyp.py +++ b/server/node_modules/npm/node_modules/node-gyp/update-gyp.py @@ -49,7 +49,7 @@ def safe_extract(tar, path=".", members=None, *, numeric_owner=False): if not is_within_directory(path, member_path): raise Exception("Attempted Path Traversal in Tar File") - tar.extractall(path, members, numeric_owner) + tar.extractall(path, members, numeric_owner=numeric_owner) safe_extract(tar_ref, unzip_target)