Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

slack: Protect against zip bombs.

Alex Vandivere68096c907b8
diff --git a/zerver/data_import/slack.py b/zerver/data_import/slack.py
index fe32342e8de..2196493eba1 100644
--- a/zerver/data_import/slack.py
+++ b/zerver/data_import/slack.py
@@ -1378,6 +1378,7 @@ def do_convert_zipfile(
os.makedirs(slack_data_dir, exist_ok=True)
with zipfile.ZipFile(original_path) as zipObj:
+ total_size = 0
for fileinfo in zipObj.infolist():
# Slack's export doesn't set the UTF-8 flag on each
# filename entry, despite encoding them as such, so
@@ -1398,6 +1399,15 @@ def do_convert_zipfile(
if not re.match(r"[^/]+(\.json|/([^/]+\.json)?)$", fileinfo.filename):
raise Exception("This zip file does not look like a Slack archive")
+ # file_size is the uncompressed size of the file
+ total_size += fileinfo.file_size
+
+ # Based on historical Slack exports, anything that is more
+ # than a 10x size magnification is suspect, particularly
+ # if it results in over 1GB.
+ if total_size > 1024 * 1024 * 1024 and total_size > 10 * os.path.getsize(original_path):
+ raise Exception("This zip file is possibly malicious")
+
zipObj.extractall(slack_data_dir)
do_convert_directory(slack_data_dir, output_dir, token, threads, convert_slack_threads)