CVE-2025-9906·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 .keras model archive that, when loaded via Model.load_model, will trigger arbitrary code to be executed. This is achieved by crafting a special config.json (a file within the .keras archive) that will invoke keras.config.enable_unsafe_deserialization() to disable safe mode. Once safe mode is disable, one can use the Lambda layer feature of keras, which allows arbitrary Python code in the form of pickled code. Both can appear in the same archive. Simply the keras.config.enable_unsafe_deserialization() needs to appear first in the archive and the Lambda with arbitrary code needs to be second.
- Severity
- high
- Software
- Python
- Fixed in
- 3.11.0
- 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.19% — higher than 8% 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-9906 scores 7.3 on CVSS, so a successful attack would be serious — but at 0.19%, 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.0
Fixed in: 3.11.0
How to fix this CVE
Update Python's Keras library to version 3.11.0 or later to patch the arbitrary code execution vulnerability in Model.load_model. Applications using Keras 3.0.0 through 3.11.0 should immediately upgrade, as attackers can bypass safe_mode protections by embedding malicious serialized code within .keras model archives. Verify the upgrade by checking the installed Keras version and testing model loading with untrusted files in an isolated environment.
sudo dnf update python3-kerasDefensia detects this vulnerability
How to check if you are affected
- Check installed Keras version: python3 -c "import keras; print(keras.__version__)"
- Identify services loading .keras model files: grep -r "Model.load_model\|keras.models.load_model" /opt /srv /home --include="*.py" 2>/dev/null
- Search application logs for model loading errors or unexpected deserialization calls: grep -i "load_model\|enable_unsafe_deserialization" /var/log/application.log
- Verify patch installation: python3 -c "import keras; exit(0 if keras.__version__ >= '3.11.0' else 1)" && echo 'Patched' || echo 'Vulnerable'
FAQ
What is CVE-2025-9906?
CVE-2025-9906 is an arbitrary code execution vulnerability in Keras Model.load_model that allows attackers to execute malicious Python code by embedding special configuration and pickled Lambda layer payloads within .keras archive files, even when safe_mode is enabled. The exploit works by triggering keras.config.enable_unsafe_deserialization() through a crafted config.json file.
Is CVE-2025-9906 being actively exploited?
No, CVE-2025-9906 is not currently listed as actively exploited in the CISA KEV catalog, and no public exploits are publicly available.
What versions of Python/Keras are affected by CVE-2025-9906?
Keras versions 3.0.0 through 3.11.0 are vulnerable. The vulnerability is fixed in Keras 3.11.0 and later. Python itself is not the vulnerable component; Keras is the affected library.
How do I check if my server is vulnerable to CVE-2025-9906?
Run: python3 -c "import keras; v = tuple(map(int, keras.__version__.split('.')[:2])); exit(0 if v < (3, 0) or v >= (3, 11) else 1)" — a return code of 1 indicates vulnerability.
Does Defensia detect CVE-2025-9906?
Yes — Defensia's CVE advisory scanner compares installed package versions against the NVD database. If Keras is installed on a monitored server, CVE-2025-9906 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-9906. Free for 1 server.
Get started free