CVE-2025-9905·Python vulnerability
The Keras Model.load_model method can be exploited to achieve arbitrary code execution, even with safe_mode=True. One can create a specially crafted .h5/.hdf5 model archive that, when loaded via Model.load_model, will trigger arbitrary code to be executed. This is achieved by crafting a special .h5 archive file that uses the Lambda layer feature of keras which allows arbitrary Python code in the form of pickled code. The vulnerability comes from the fact that the safe_mode=True option is not honored when reading .h5 archives. Note that the .h5/.hdf5 format is a legacy format supported by Keras 3 for backwards compatibility.
- Severity
- high
- Software
- Python
- Fixed in
- 3.11.3
- Published
How likely is exploitation
FIRST's Exploit Prediction Scoring System puts the probability of this CVE being exploited in the next 30 days at 0.21% — higher than 11% of all published CVEs. EPSS is an independent forecast of exploitation, not a severity rating: it says nothing about how much damage a successful attack does, which is what a CVSS score measures.
Read the two together. CVE-2025-9905 scores 7.3 on CVSS, so a successful attack would be serious — but at 0.21%, almost nobody is currently attempting it. That is a different situation from a flaw under mass exploitation, and it is usually the difference between patching on your next maintenance window and patching tonight.
Affected versions
From: 3.0.0
Until: 3.11.3
Fixed in: 3.11.3
How to fix this CVE
Update Keras to version 3.11.3 or later to resolve unsafe deserialization of legacy .h5 model files. Users should avoid loading untrusted .h5/.hdf5 model archives, as the safe_mode parameter does not prevent arbitrary code execution through pickled Lambda layer payloads. Verify your Keras installation and apply the patch immediately if you load model files from external sources.
sudo dnf check-update python3-keras && sudo dnf update python3-kerasDefensia detects this vulnerability
How to check if you are affected
- Run 'pip show keras' or 'python3 -c "import keras; print(keras.__version__)"' to check the installed Keras version
- Review your application code for calls to keras.models.load_model() with .h5 or .hdf5 file paths
- Audit file upload endpoints or model serving pipelines that accept .h5 files from external sources
- After patching, re-run 'python3 -c "import keras; print(keras.__version__)"' to confirm version 3.11.3 or later is installed
FAQ
What is CVE-2025-9905?
A deserialization vulnerability in Keras 3.0.0–3.11.2 where the Model.load_model() function fails to enforce safe_mode restrictions when loading legacy .h5 model archives, allowing attackers to execute arbitrary Python code via crafted pickled Lambda layers.
Is CVE-2025-9905 being actively exploited?
No, CVE-2025-9905 is not listed on the CISA Known Exploited Vulnerabilities catalog and no public exploits have been disclosed.
What versions of Python are affected by CVE-2025-9905?
Keras versions 3.0.0 through 3.11.2 are vulnerable; Python itself is not directly affected. Any system running Keras within this version range that loads .h5 model files is at risk.
How do I check if my server is vulnerable to CVE-2025-9905?
Run 'python3 -c "import keras; print(keras.__version__)"' and compare the output to version 3.11.3; if your version is 3.11.2 or earlier, you are vulnerable.
Does Defensia detect CVE-2025-9905?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If Keras is installed on a monitored server, CVE-2025-9905 will appear in your dashboard with remediation steps.
Related Python CVEs
References
Track CVEs across your fleet automatically
Defensia scans your Linux servers and tells you exactly which ones are running vulnerable versions — including CVE-2025-9905. Free for 1 server.
Get started free