Skip to content

Commit 0dd2fb1

Browse files
yueyueLpre-commit-ci[bot]KumoLiu
committed
Fix Zip Slip vulnerability in NGC private bundle download (Project-MONAI#8682)
Replaced the unsafe `zipfile.extractall()` in `_download_from_ngc_private` with MONAI's safe extraction utility. Prevents path traversal via crafted zip member paths (CWE-22). ### Description This changes _download_from_ngc_private() to use the same safe zip extraction path as the other bundle download sources. The previous code used ZipFile.extractall() directly, which could allow Zip Slip path traversal if a malicious archive is downloaded. Now extraction validates member paths and keeps writes within the target directory. --------- Signed-off-by: Yue (Knox) Liu <64764840+yueyueL@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
1 parent 9c6d819 commit 0dd2fb1

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

monai/bundle/scripts.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import re
1818
import urllib
1919
import warnings
20-
import zipfile
2120
from collections.abc import Mapping, Sequence
2221
from functools import partial
2322
from pathlib import Path
@@ -30,7 +29,7 @@
3029
from torch.cuda import is_available
3130

3231
from monai._version import get_versions
33-
from monai.apps.utils import _basename, download_url, extractall, get_logger
32+
from monai.apps.utils import _basename, _extract_zip, download_url, extractall, get_logger
3433
from monai.bundle.config_parser import ConfigParser
3534
from monai.bundle.utils import DEFAULT_INFERENCE, DEFAULT_METADATA, merge_kv
3635
from monai.bundle.workflows import BundleWorkflow, ConfigWorkflow
@@ -288,9 +287,8 @@ def _download_from_ngc_private(
288287
if remove_prefix:
289288
filename = _remove_ngc_prefix(filename, prefix=remove_prefix)
290289
extract_path = download_path / f"{filename}"
291-
with zipfile.ZipFile(zip_path, "r") as z:
292-
z.extractall(extract_path)
293-
logger.info(f"Writing into directory: {extract_path}.")
290+
_extract_zip(zip_path, extract_path)
291+
logger.info(f"Writing into directory: {extract_path}.")
294292

295293

296294
def _get_ngc_token(api_key, retry=0):

0 commit comments

Comments
 (0)