Skip to content

Conversation

@yueyueL
Copy link
Contributor

@yueyueL yueyueL commented Jan 4, 2026

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.

Copilot AI review requested due to automatic review settings January 4, 2026 05:14
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 4, 2026

📝 Walkthrough

Walkthrough

Imported _extract_zip from monai.apps.utils into monai/bundle/scripts.py. Replaced the inline zipfile.ZipFile extraction in _download_from_ngc_private with a call to _extract_zip(zip_path, extract_path). Post-extraction logging remains unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Description check ❓ Inconclusive Description covers the fix and security rationale, but lacks checkbox completion for changesets types and testing requirements per the template. Complete the checklist section with appropriate selections for change type and testing status to match the repository template.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed Title accurately summarizes the main security fix—replacing unsafe zip extraction with safe utility to prevent Zip Slip vulnerability.
✨ Finishing touches
  • 📝 Generate docstrings

📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Cache: Disabled due to data retention organization setting

Knowledge base: Disabled due to Reviews -> Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between a334b62 and 4daa3d3.

📒 Files selected for processing (1)
  • monai/bundle/scripts.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • monai/bundle/scripts.py

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a critical Zip Slip vulnerability (CWE-22) in the NGC private bundle download functionality by replacing the unsafe zipfile.extractall() call with MONAI's secure _extract_zip() utility that validates member paths and prevents path traversal attacks.

Key Changes:

  • Replaced direct use of zipfile.extractall() with the safe _extract_zip() utility function
  • Added import for _extract_zip from monai.apps.utils

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Copy link
Member

@ericspod ericspod left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, please look at the DCO resolution process, the other CICD issues are being worked on elsewhere so we'll have to wait on that.

yueyueL and others added 2 commits January 5, 2026 08:53
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).

Signed-off-by: Yue (Knox) Liu <[email protected]>
@yueyueL yueyueL force-pushed the dev branch 2 times, most recently from f59032b to a334b62 Compare January 5, 2026 09:28
Signed-off-by: Yue (Knox) Liu <[email protected]>
@KumoLiu
Copy link
Contributor

KumoLiu commented Jan 5, 2026

/build

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@yueyueL
Copy link
Contributor Author

yueyueL commented Jan 5, 2026

@KumoLiu The blossom-ci shows success (https://github.com/Project-MONAI/MONAI/actions/runs/20713670102) but hasn't updated on the PR. Could you help resolve this?

@KumoLiu
Copy link
Contributor

KumoLiu commented Jan 5, 2026

/build

@KumoLiu
Copy link
Contributor

KumoLiu commented Jan 5, 2026

@KumoLiu The blossom-ci shows success (https://github.com/Project-MONAI/MONAI/actions/runs/20713670102) but hasn't updated on the PR. Could you help resolve this?

retriggered, looks like network issue.

@KumoLiu KumoLiu merged commit 4014c84 into Project-MONAI:dev Jan 5, 2026
33 checks passed
Borda pushed a commit to Borda/MONAI that referenced this pull request Jan 6, 2026
…NAI#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 <[email protected]>
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: YunLiu <[email protected]>
Signed-off-by: jirka <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants